Skip to content
This repository was archived by the owner on Nov 20, 2020. It is now read-only.

Commit b6bd2c5

Browse files
committed
fix: finally errors result in exit code
1 parent c2d6e74 commit b6bd2c5

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

src/cli/commands/build.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const delve = require('dlv');
77
// @see https://github.com/sindresorhus/import-cwd
88
const importCwd = require('import-cwd');
99

10+
// @see https://github.com/chalk/chalk
11+
const chalk = require('chalk');
12+
1013
// @see https://github.com/shellscape/webpack-log
1114
const log = (new require('webpack-log'))({ name: 'build' });
1215

@@ -34,23 +37,42 @@ const fn = (args = [], flags = {}) => {
3437
return dump.fn(webpackConfig, path.join(process.cwd(), config));
3538
}
3639

37-
try {
38-
webpack(webpackConfig).run((e, stats) => {
39-
if (e) {
40-
process.exitCode = 1;
40+
log.info(chalk`Running in {bold production} mode…`);
4141

42-
return log.error(e);
43-
}
42+
// @see https://webpack.js.org/api/node/
43+
const compiler = webpack(webpackConfig, (error, stats) => {
44+
if (stats.hasErrors() === false && (error === undefined || error === null)) {
45+
log.info(stats.toString(webpackConfig.stats));
46+
log.info('Build complete.');
47+
48+
return;
49+
}
4450

45-
console.log(
46-
stats.toString(webpackConfig.stats)
47-
);
48-
});
49-
} catch (e) {
5051
process.exitCode = 1;
5152

52-
log.error(e);
53-
}
53+
// Fatal webpack errors (wrong configuration, etc)
54+
if (error) {
55+
log.error(error.stack || error);
56+
57+
if (error.details) {
58+
log.error(error.details)
59+
}
60+
61+
return;
62+
}
63+
64+
// Compilation errors (missing modules, syntax errors, etc)
65+
if (stats.hasErrors()) {
66+
log.error(stats.toString(webpackConfig.stats));
67+
}
68+
69+
// Compilation warnings
70+
if (stats.hasWarnings()) {
71+
log.warn(stats.toString(webpackConfig.stats));
72+
}
73+
74+
log.info('Build incomplete.');
75+
});
5476
};
5577

5678
module.exports = {

0 commit comments

Comments
 (0)