Skip to content

Commit

Permalink
Merge branch 'dot-env' of https://github.com/info-arnav/webpack-cli i…
Browse files Browse the repository at this point in the history
…nto dot-env

merge: yarn.lock
  • Loading branch information
info-arnav committed Apr 13, 2024
2 parents a51a1fc + 969181e commit 397d73a
Show file tree
Hide file tree
Showing 5 changed files with 2,752 additions and 3,164 deletions.
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 @@ -2550,11 +2552,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
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ exports[`basic serve usage should throw error when same ports in multicompiler:
at stack"
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;

exports[`basic serve usage should work and log warning on the 'watch' option in a configuration: stderr 1`] = `
"[webpack-cli] No need to use the 'serve' command together with '{ watch: true | false }' or '--watch'/'--no-watch' configuration, it does not make sense.
<i> [webpack-dev-server] Project is running at:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ exports[`basic serve usage should throw error when same ports in multicompiler:
at stack"
`;

exports[`basic serve usage should throw error when same ports in multicompiler: stdout 1`] = `""`;

exports[`basic serve usage should work and log warning on the 'watch' option in a configuration: stderr 1`] = `
"[webpack-cli] No need to use the 'serve' command together with '{ watch: true | false }' or '--watch'/'--no-watch' configuration, it does not make sense.
<i> [webpack-dev-server] Project is running at:
Expand Down
5 changes: 3 additions & 2 deletions test/serve/basic/serve-basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,14 @@ describe("basic serve usage", () => {
});

it("should throw error when same ports in multicompiler", async () => {
const { stderr, stdout } = await runWatch(__dirname, [
const { stderr } = await runWatch(__dirname, [
"serve",
"--config",
"same-ports-dev-server.config.js",
]);

expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
// Due to racing logic, first dev server can be started and compiled, but then the second always fails
// expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
});
});

0 comments on commit 397d73a

Please sign in to comment.