diff --git a/Readme.md b/Readme.md index a44dee5..f45ce18 100644 --- a/Readme.md +++ b/Readme.md @@ -23,7 +23,7 @@ wds --inspect some-test.test.ts - Builds and runs TypeScript really fast (using [`swc`](https://github.com/swc-project/swc) or [`esbuild`](https://github.com/evanw/esbuild)) - Incrementally rebuilds only what has changed in the `--watch` mode, and restarts the process when files change -- Supervises the node.js process with `--supervise` to keep incremental context around on process crash, and can restart on demand in the `--commands` mode +- Execute commands on demand with the `--commands` mode - Plays nice with node.js command line flags like `--inspect` or `--prof` - Produces sourcemaps which Just Work™️ by default for debugging with many editors (VSCode, IntelliJ, etc) - Monorepo aware, allowing for different configuration per package and only compiling what is actually required from the monorepo context diff --git a/src/Options.ts b/src/Options.ts index d1b0dd5..75be193 100644 --- a/src/Options.ts +++ b/src/Options.ts @@ -7,7 +7,6 @@ export interface RunOptions { argv: string[]; terminalCommands: boolean; reloadOnChanges: boolean; - supervise: boolean; useEsbuild: boolean; } diff --git a/src/Supervisor.ts b/src/Supervisor.ts index ae08256..cdb7af7 100644 --- a/src/Supervisor.ts +++ b/src/Supervisor.ts @@ -46,7 +46,7 @@ export class Supervisor extends EventEmitter { this.process.on("message", (value) => this.emit("message", value)); this.process.on("exit", (code, signal) => { - if (signal !== "SIGKILL" && this.options.supervise) { + if (signal !== "SIGKILL") { log.warn(`process exited with ${code}`); } }); diff --git a/src/bench/bench.ts b/src/bench/bench.ts index 7f58abb..84bb3b4 100644 --- a/src/bench/bench.ts +++ b/src/bench/bench.ts @@ -36,11 +36,10 @@ function monitorLogs(childProcess: ChildProcess): Promise { }); } -function spawnOnce(args: { supervise?: boolean; filename: string; esbuild: boolean }): ChildProcess { +function spawnOnce(args: { watch?: boolean; filename: string; esbuild: boolean }): ChildProcess { const extraArgs = []; - if (args.supervise) { - extraArgs.push("--supervise"); + if (args.watch) { extraArgs.push("--watch"); } @@ -158,7 +157,7 @@ export async function benchReload(args: BenchArgs): Promise { process.stdout.write(`Starting reload benchmark (pid=${process.pid})\n`); - const childProcess = spawnOnce({ supervise: true, filename: filepath, esbuild: args.esbuild }); + const childProcess = spawnOnce({ watch: true, filename: filepath, esbuild: args.esbuild }); const _ignoreInitialBoot = await monitorLogs(childProcess); for (let i = 0; i < args.runs; i++) { diff --git a/src/index.ts b/src/index.ts index 270c591..be52c00 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,12 +33,6 @@ export const cli = async () => { description: "Trigger restarts by watching for changes to required files", default: true, }) - .option("supervise", { - alias: "s", - type: "boolean", - description: "Supervise and restart the process when it exits indefinitely", - default: false, - }) .option("esbuild", { type: "boolean", description: "Use esbuild instead of sec", @@ -49,7 +43,6 @@ export const cli = async () => { argv: args._ as any, terminalCommands: args.commands, reloadOnChanges: args.watch, - supervise: args.supervise, useEsbuild: args.esbuild, }); }; @@ -157,7 +150,7 @@ export const wds = async (options: RunOptions) => { await startIPCServer(serverSocketPath, project); // kickoff the first child process - options.supervise && log.info(`Supervision starting for command: node ${options.argv.join(" ")}`); + options.reloadOnChanges && log.info(`Supervision starting for command: node ${options.argv.join(" ")}`); await project.invalidateBuildSetAndReload(); process.on("SIGINT", () => { @@ -170,9 +163,14 @@ export const wds = async (options: RunOptions) => { }); project.supervisor.process.on("exit", (code) => { - log.debug(`child process exited with code ${code}, ${options.supervise ? "not exiting because supervise mode" : "exiting..."}`); - if (!options.supervise) { - project.shutdown(code ?? 1); + const logShutdown = (explanation: string) => { + log.debug(`child process exited with code ${code}, ${explanation}`); + }; + if (options.reloadOnChanges) { + logShutdown("not exiting because we're on 'watch' mode"); + return; } + logShutdown("shutting down project since it's no longer needed..."); + project.shutdown(code ?? 1); }); }; diff --git a/test/reload/test.sh b/test/reload/test.sh index 6b7590e..c45adf7 100755 --- a/test/reload/test.sh +++ b/test/reload/test.sh @@ -9,12 +9,12 @@ trap "kill -9 0" INT TERM trap 'kill $(jobs -p)' EXIT # run a server in the background -$DIR/../../pkg/wds.bin.js $@ --supervise --commands $DIR/run-scratch.ts & +$DIR/../../pkg/wds.bin.js $@ --commands $DIR/run-scratch.ts & max_retry=5 counter=0 -set +e +set +e until curl -s localhost:8080 | grep "World" do sleep 1 @@ -39,4 +39,4 @@ done echo "Made new request to reloaded server" -exit 0 \ No newline at end of file +exit 0