|
| 1 | +// Run "tsc" in watch mode alongside vitest. Vitest runs the compiled output, |
| 2 | +// so on its own it never notices a .ts edit - tsc has to re-emit first, and |
| 3 | +// vitest picks the change up from there. |
| 4 | + |
| 5 | +const { spawn } = require("child_process"); |
| 6 | + |
| 7 | +// shell: true so the node_modules/.bin shims resolve on Windows as well |
| 8 | +const spawnOptions = { stdio: "inherit", shell: true }; |
| 9 | + |
| 10 | +const children = [ |
| 11 | + // --preserveWatchOutput keeps tsc from clearing the screen and wiping the |
| 12 | + // test results out from under you on every recompile |
| 13 | + spawn("tsc", ["--watch", "--preserveWatchOutput"], spawnOptions), |
| 14 | + // --watch explicitly: vitest only infers watch mode when stdout is a TTY, |
| 15 | + // and would otherwise run once and exit, taking tsc down with it |
| 16 | + spawn("vitest", ["--watch"], spawnOptions), |
| 17 | +]; |
| 18 | + |
| 19 | +let shuttingDown = false; |
| 20 | + |
| 21 | +function shutdown() { |
| 22 | + if (shuttingDown) { |
| 23 | + return; |
| 24 | + } |
| 25 | + shuttingDown = true; |
| 26 | + for (const child of children) { |
| 27 | + child.kill("SIGINT"); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +process.on("SIGINT", shutdown); |
| 32 | +process.on("SIGTERM", shutdown); |
| 33 | + |
| 34 | +for (const child of children) { |
| 35 | + // if either side dies, don't leave the other running in the background |
| 36 | + child.on("exit", shutdown); |
| 37 | +} |
0 commit comments