Skip to content

Commit

Permalink
fix: Remember to close webpack compiler
Browse files Browse the repository at this point in the history
It looks like this is the right way to go instead of `process.exit`.
  • Loading branch information
bebraw committed Jul 7, 2021
1 parent 4e1bd0d commit 9389325
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 0 additions & 3 deletions app/angular/src/server/build.ts
Expand Up @@ -5,9 +5,6 @@ import options from './options';
async function build() {
try {
await buildStatic(options);

// #15227
process.exit(0);
} catch (error) {
logger.error(error);
}
Expand Down
23 changes: 19 additions & 4 deletions lib/builder-webpack5/src/index.ts
Expand Up @@ -129,14 +129,19 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
const config = await getConfig(options);

return new Promise((succeed, fail) => {
webpackInstance(config).run((error, stats) => {
const compiler = webpackInstance(config);

compiler.run((error, stats) => {
if (error || !stats || stats.hasErrors()) {
logger.error('=> Failed to build the preview');
process.exitCode = 1;

if (error) {
logger.error(error.message);
return fail(error);

compiler.close(() => fail(error));

return;
}

if (stats && (stats.hasErrors() || stats.hasWarnings())) {
Expand All @@ -145,7 +150,9 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
errors.forEach((e) => logger.error(e.message));
warnings.forEach((e) => logger.error(e.message));

return fail(stats);
compiler.close(() => fail(stats));

return;
}
}

Expand All @@ -154,7 +161,15 @@ export const build: WebpackBuilder['build'] = async ({ options, startTime }) =>
stats.toJson({ warnings: true }).warnings.forEach((e) => logger.warn(e.message));
}

return succeed(stats);
// https://webpack.js.org/api/node/#run
// #15227
compiler.close((closeErr) => {
if (closeErr) {
return fail(closeErr);
}

return succeed(stats);
});
});
});
};
Expand Down

0 comments on commit 9389325

Please sign in to comment.