Skip to content

Commit

Permalink
Fix bundling asyncImports in dist builds, fixes #456
Browse files Browse the repository at this point in the history
  • Loading branch information
charlag committed Jul 12, 2018
1 parent be18929 commit d9bbabc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
5 changes: 2 additions & 3 deletions dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const bundles = {}

function getAsyncImports(file) {
let appSrc = fs.readFileSync(path.resolve(__dirname, file), 'utf-8')
const regExp = /_asyncImport\("(.*)"\)/g
const regExp = /_asyncImport\(["|'](.*)["|']\)/g
let match = regExp.exec(appSrc)
let asyncImports = []
while (match != null) {
Expand All @@ -50,11 +50,10 @@ clean()
builder.trace('src/api/worker/WorkerImpl.js + src/api/entities/*/* + src/system-resolve.js'),
builder.trace('src/app.js + src/system-resolve.js'),
builder.trace('src/gui/theme.js - libs/stream.js'),
builder.trace(getAsyncImports('src/app.js').join(" + ") + " + src/login/LoginViewController.js + src/gui/base/icons/Icons.js + src/search/SearchBar.js"),
builder.trace(getAsyncImports('src/app.js').concat(getAsyncImports('src/native/NativeWrapper.js')).join(" + ") + " + src/login/LoginViewController.js + src/gui/base/icons/Icons.js + src/search/SearchBar.js"),
]).then(trees => {
let workerTree = trees[0]
let bootTree = trees[1]
printTraceReport(bootTree)
let themeTree = trees[2]
let mainTree = trees[3]

Expand Down
25 changes: 13 additions & 12 deletions src/native/NativeWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class NativeWrapper {
}:any))
this._nativeQueue.setCommands({
updatePushIdentifier: (msg: Request) => {
return importModule('src/native/PushServiceApp.js').then(module => {
return _asyncImport('src/native/PushServiceApp.js').then(module => {
module.pushServiceApp.updatePushIdentifier(msg.args[0])
})
},
createMailEditor: (msg: Request) => {
return Promise.all([
importModule('src/mail/MailModel.js'),
importModule('src/mail/MailEditor.js'),
importModule('src/mail/MailUtils.js'),
importModule('src/api/main/LoginController.js')
_asyncImport('src/mail/MailModel.js'),
_asyncImport('src/mail/MailEditor.js'),
_asyncImport('src/mail/MailUtils.js'),
_asyncImport('src/api/main/LoginController.js')
]).spread((mailModelModule, mailEditorModule, mailUtilsModule, {logins}) => {
return logins.waitForUserLogin().then(() => Promise.all(msg.args[0]
.map(uri => Promise.join(getName(uri), getMimeType(uri), getSize(uri), (name, mimeType, size) => {
Expand All @@ -62,19 +62,20 @@ class NativeWrapper {
})
},
handleBackPress: (): Promise<boolean> => {
return importModule('src/native/DeviceButtonHandler.js').then(module => {
return module.handleBackPress()
}
)
return _asyncImport('src/native/DeviceButtonHandler.js')
.then(module => {
return module.handleBackPress()
}
)
},
showAlertDialog: (msg: Request): Promise<void> => {
return importModule('src/gui/base/Dialog.js').then(module => {
return _asyncImport('src/gui/base/Dialog.js').then(module => {
return module.Dialog.error(msg.args[0])
}
)
},
openMailbox: (msg: Request): Promise<void> => {
return importModule('src/native/OpenMailboxHandler.js').then(module => {
return _asyncImport('src/native/OpenMailboxHandler.js').then(module => {
return module.openMailbox(msg.args[0], msg.args[1])
}
)
Expand Down Expand Up @@ -138,7 +139,7 @@ function _createConnectionErrorHandler(rejectFunction) {
}


const importModule = (path): Promise<any> =>
const _asyncImport = (path): Promise<any> =>
asyncImport(typeof module != "undefined" ? module.id : __moduleName, `${env.rootPathPrefix}${path}`)

export const nativeApp = new NativeWrapper()

0 comments on commit d9bbabc

Please sign in to comment.