From 2f6c4e091aeebd1d57dbe26a15244d482407fcd5 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 13 Dec 2017 12:06:35 +0200 Subject: [PATCH 1/2] fix(compiler): reject promise with real error When the webpack compiler fails, the error is not used in the rejection, so the promise is always rejected with `undefined`. Fix this by respecting the error. Construct real error object as well. --- lib/compiler.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index 29a082ae..b8f0c972 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -25,13 +25,13 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, } resolveBase(); } - function reject() { + function reject(error) { if (isResolved) return; isResolved = true; if (childProcess) { childProcess.removeListener("message", resolveOnWebpackCompilationComplete); } - rejectBase(); + rejectBase(error); } console.log(`Running webpack for ${config.platform}...`); @@ -93,10 +93,9 @@ exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, if (code === 0) { resolve(); } else { - reject({ - code, - message: `child process exited with code ${code}`, - }); + const error = new Error(`Executing webpack failed with exit code ${code}.`); + error.code = code; + reject(error); } }); }); From c248b7283d5f01e708113933b98be560855ad0fd Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Wed, 13 Dec 2017 16:09:07 +0200 Subject: [PATCH 2/2] Force rebuild of application when webpack is used In case we want to use webpack, force the build by setting nativeChanged property of changesInfo to true. This is TEMP solution until we have a better one. --- lib/before-prepareJS.js | 2 +- lib/compiler.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/before-prepareJS.js b/lib/before-prepareJS.js index fbbac4d3..d7b69a61 100644 --- a/lib/before-prepareJS.js +++ b/lib/before-prepareJS.js @@ -10,6 +10,6 @@ module.exports = function ($mobileHelper, $projectData, hookArgs) { bundle: appFilesUpdaterOptions.bundle, watch: false // TODO: Read from CLI options... }; - const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData); + const result = config.bundle && runWebpackCompiler.bind(runWebpackCompiler, config, $mobileHelper, $projectData, hookArgs); return result; } diff --git a/lib/compiler.js b/lib/compiler.js index b8f0c972..f30173d8 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -13,9 +13,13 @@ exports.getWebpackProcess = function getWebpackProcess() { return webpackProcess; } -exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, originalArgs, originalMethod) { +exports.runWebpackCompiler = function runWebpackCompiler(config, $mobileHelper, $projectData, hookArgs, originalArgs, originalMethod) { if (config.bundle) { return new Promise(function (resolveBase, rejectBase) { + if (hookArgs && hookArgs.config && hookArgs.config.changesInfo) { + hookArgs.config.changesInfo.nativeChanged = true; + } + let isResolved = false; function resolve() { if (isResolved) return;