Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

fix(compiler): reject promise with real error #350

Merged
merged 2 commits into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/before-prepareJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 10 additions & 7 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,13 +29,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}...`);
Expand Down Expand Up @@ -93,10 +97,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);
}
});
});
Expand Down