Skip to content

Commit 07375e9

Browse files
committed
fix(core): keep nx watch process alive while listening for file changes
The watch command was exiting immediately after registering the file watcher because the registerFileWatcher() function completed and there was nothing keeping the Node.js event loop alive. Unlike the main daemon socket which has a keep-alive timeout, the file watcher socket doesn't generate any timers or pending promises that would prevent the process from exiting. Fix: Add an infinite promise after registering the file watcher. This keeps the event loop alive indefinitely while the file watcher callbacks handle incoming file change events. The process will exit cleanly when: - User presses Ctrl+C (signal handler) - The file watcher connection closes (callback receives 'closed' event)
1 parent 0dfff55 commit 07375e9

File tree

1 file changed

+5
-0
lines changed
  • packages/nx/src/command-line/watch

1 file changed

+5
-0
lines changed

packages/nx/src/command-line/watch/watch.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,9 @@ export async function watch(args: WatchArguments) {
241241
}
242242
);
243243
args.verbose && output.logSingleLine('watch process waiting...');
244+
245+
// Keep the process alive while watching for file changes
246+
// The file watcher callbacks will handle incoming events
247+
// The process will exit when Ctrl+C is pressed or if the connection closes
248+
await new Promise(() => {});
244249
}

0 commit comments

Comments
 (0)