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

Commit c20bfa8

Browse files
committed
Signal fail worker process exit
1 parent afeb3d3 commit c20bfa8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/webpackWorker.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
7676
var watch = !!options.watch,
7777
silent = !!options.json;
7878
if(expectedConfigLength !== 1 && !Array.isArray(config)
79-
|| (Array.isArray(config) && config.length !== expectedConfigLength)) {
79+
|| (Array.isArray(config) && config.length !== expectedConfigLength)) {
8080
if(config.length !== expectedConfigLength) {
8181
var errorMessage = '[WEBPACK] There is a difference between the amount of the'
8282
+ ' provided configs. Maybe you where expecting command line'
@@ -105,11 +105,25 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
105105
});
106106
process.exit(0);
107107
},
108+
exitCallback = function(code) {
109+
if (code === 0) {
110+
return;
111+
}
112+
if(watcher) {
113+
watcher.close(done);
114+
}
115+
done({
116+
message: chalk.red('[WEBPACK]')
117+
+ ' Exit ' + chalk.yellow(getAppName(webpackConfig))
118+
+ ' with code ' + code
119+
});
120+
},
108121
finishedCallback = function(err, stats) {
109122
if(err) {
110123
console.error('%s fatal error occured', chalk.red('[WEBPACK]'));
111124
console.error(err);
112125
process.removeListener('SIGINT', shutdownCallback);
126+
process.removeListener('exit', exitCallback);
113127
return done(err);
114128
}
115129
if(stats.compilation.errors && stats.compilation.errors.length) {
@@ -121,6 +135,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
121135
console.log(message);
122136
} else {
123137
process.removeListener('SIGINT', shutdownCallback);
138+
process.removeListener('exit', exitCallback);
124139
return done({
125140
message: message,
126141
stats: JSON.stringify(stats.toJson(outputOptions), null, 2)
@@ -138,6 +153,7 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
138153
}
139154
if(!watch) {
140155
process.removeListener('SIGINT', shutdownCallback);
156+
process.removeListener('exit', exitCallback);
141157
done(null, options.stats ? JSON.stringify(stats.toJson(outputOptions), null, 2) : '');
142158
} else if (!hasCompletedOneCompile) {
143159
notifyIPCWatchCompileDone(index);
@@ -155,5 +171,6 @@ module.exports = function(configuratorFileName, options, index, expectedConfigLe
155171
}
156172

157173
process.on('SIGINT', shutdownCallback);
174+
process.on('exit', exitCallback);
158175
});
159176
};

0 commit comments

Comments
 (0)