import { spawn } from 'node:child_process'; import { createRequire } from 'node:module'; const require = createRequire(import.meta.url); // Stop both processes together, including when Turbo or Playwright stops this task. const children = [ spawn( process.execPath, [require.resolve('typescript/bin/tsc'), '--watch', '--preserveWatchOutput'], { stdio: 'inherit' }, ), spawn(process.execPath, ['--watch', 'dist/main.js'], { stdio: 'inherit' }), ]; let stopping = false; function stop(code = 0) { if (stopping) return; stopping = true; for (const child of children) child.kill('SIGTERM'); process.exitCode = code; } process.on('SIGINT', () => stop()); process.on('SIGTERM', () => stop()); for (const child of children) { child.on('error', (error) => { console.error(error.message); stop(1); }); child.on('exit', (code) => { if (!stopping) stop(code ?? 1); }); }