Repository navigation
feat: add --on-watch option to run a command on watched changes - #932
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>
|
@SameRainbows Good catch, thanks. Pushed a fix: |
|
The red |
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