watch: add manual restart and log changed file#62476
Open
KirobotDev wants to merge 2 commits intonodejs:mainfrom
Open
watch: add manual restart and log changed file#62476KirobotDev wants to merge 2 commits intonodejs:mainfrom
KirobotDev wants to merge 2 commits intonodejs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.