fix(lifecycle): use ProcessLifecycle for coordinated shutdown

Replace per-Watcher SIGINT handlers with a single ProcessLifecycle.install()
in TsWatch.start(). This eliminates competing signal handler races that left
orphaned child processes. Add @push.rocks/smartexit as direct dependency.
This commit is contained in:
2026-03-03 23:43:26 +00:00
parent 91b3e273de
commit e8bd8da3c7
5 changed files with 34 additions and 42 deletions

View File

@@ -46,6 +46,14 @@ export class TsWatch {
public async start() {
logger.log('info', 'Starting tswatch with config-driven mode');
// Install global process lifecycle handlers (SIGINT, SIGTERM, etc.)
// This is the single authority for signal handling — no per-watcher handlers.
plugins.smartexit.ProcessLifecycle.install();
const exitInstance = new plugins.smartexit.SmartExit({ silent: true });
exitInstance.addCleanupFunction(async () => {
await this.stop();
});
// Start server if configured
if (this.config.server?.enabled) {
await this.startServer();