Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: gracefully shutting down #4145

Merged
merged 1 commit into from
Apr 10, 2024
Merged
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
34 changes: 30 additions & 4 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ const WEBPACK_DEV_SERVER_PACKAGE = WEBPACK_DEV_SERVER_PACKAGE_IS_CUSTOM
? (process.env.WEBPACK_DEV_SERVER_PACKAGE as string)
: "webpack-dev-server";

const EXIT_SIGNALS = ["SIGINT", "SIGTERM"];

interface Information {
Binaries?: string[];
Browsers?: string[];
Expand Down Expand Up @@ -2532,11 +2534,35 @@ class WebpackCLI implements IWebpackCLI {
: compiler.options.watch,
);

if (isWatch(compiler) && this.needWatchStdin(compiler)) {
process.stdin.on("end", () => {
process.exit(0);
if (isWatch(compiler)) {
let needForceShutdown = false;

EXIT_SIGNALS.forEach((signal) => {
const listener = () => {
if (needForceShutdown) {
process.exit(0);
}

this.logger.info(
"Gracefully shutting down. To force exit, press ^C again. Please wait...",
);

needForceShutdown = true;

compiler.close(() => {
process.exit(0);
});
};

process.on(signal, listener);
});
process.stdin.resume();

if (this.needWatchStdin(compiler)) {
process.stdin.on("end", () => {
process.exit(0);
});
process.stdin.resume();
}
}
}
}
Expand Down
Loading