Skip to content

watch: add manual restart and log changed file#62476

Open
KirobotDev wants to merge 2 commits intonodejs:mainfrom
KirobotDev:main
Open

watch: add manual restart and log changed file#62476
KirobotDev wants to merge 2 commits intonodejs:mainfrom
KirobotDev:main

Conversation

@KirobotDev
Copy link
Copy Markdown

Summary
This PR enhances the native node --watch mode by adding two key developer experience features:

Manual Restart: Users can now type rs (and press Enter) in the terminal to manually trigger a process restart.
Restart Reason: The console now explicitly logs which file triggered the restart, making it easier to track changes in large projects.
Additionally, the log output has been improved with a session header and consistent colored prefixes ([node:watch]).

Changes
lib/internal/watch_mode/files_watcher.js: Updated #onChange to include the trigger file path in the changed event.
lib/internal/main/watch_mode.js:
Added a stdin listener for the rs command.
Instrumented the restart logic to accept and display the restart reason.
Enhanced visual feedback with colors and a clearer session startup message.
Verification
Manually verified that typing rs triggers a clean restart.
Manually verified that modifying a watched file logs the correct filename as the restart reason.
Ensured that existing watch mode behaviors (like --watch-preserve-output) remain intact.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants