Repository navigation
feat: add --on-watch option to run a command on watched changes - #932
Open
harshilv17 wants to merge 2 commits into
Open
harshilv17 wants to merge 2 commits into
harshilv17 wants to merge 2 commits into
Conversation
Closes fastify#569 Signed-off-by: harshilv17 <harshilvalecha@gmail.com>
|
Tested locally on Node 24. The unit tests in test/watch-unit.test.js cover command execution before restart, debouncing during an active run, non-zero exit logging, and suppression of restarts after stop. One edge case to consider: if emitter.stop() is called while an on-watch command is still executing, stop() terminates the running application children in childs but does not terminate the spawned child process. Holding a reference to the active spawn process and calling .kill() on it inside emitter.stop() would ensure long-running commands (such as a slow build or type check) do not linger after the watcher halts. |
Signed-off-by: harshilv17 <harshilvalecha@gmail.com>
Author
|
@SameRainbows Good catch, thanks. Pushed a fix: |
This branch has not been deployed
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.
Closes #569
Adds an
--on-watchoption (FASTIFY_ON_WATCHenv, oronWatchin a config file) tostart --watch. On every watched change the command runs through the shell with its output piped through, and the app reloads after the command exits:on-watch command exited with code N) and the app still reloads, so a lint error doesn't stop the watcher.--ignore-watch, otherwise each run triggers the next one. The help text and README say so.Without
--on-watchthe watcher behaves as before.I also checked it by hand on a small app: two
touch app.jsran the command twice and reloaded the server twice (same restart count as plain--watch), and--on-watch 'exit 3'logged the exit code and kept serving.Checklist
npm run test && npm run benchmark --if-presentand the Code of conduct