Skip to content

Comments

feat: allow --watch to accept optional directory or list of directories#861

Open
josephreilly22 wants to merge 1 commit intofastify:mainfrom
josephreilly22:watch-optional-directory
Open

feat: allow --watch to accept optional directory or list of directories#861
josephreilly22 wants to merge 1 commit intofastify:mainfrom
josephreilly22:watch-optional-directory

Conversation

@josephreilly22
Copy link

Closes #787

Allow --watch to accept an optional directory or space-separated list of directories. When provided, only those paths are watched; when omitted, behavior is unchanged (watch process.cwd()).

Usage:

  • fastify start app.js --watch or fastify start -w app.js → watch cwd (unchanged)
  • fastify start --watch api api/server.js → watch only api/
  • fastify start --watch "api lib" server.js → watch only api/ and lib/

Changes:

  • args.js: Parse --watch as string, normalize and expose watchPaths
  • start.js: Pass watchPaths to watch module
  • lib/watch/index.js: When watchPaths is provided, watch only those dirs (resolved from cwd); otherwise watch cwd
  • help/start.txt and README.md: Updated docs and example
  • test/args.test.js: Updated expectations for watchPaths, added tests for --watch api and --watch "api lib"
  • test/watch.test.js: Added test for watch with watchPaths

Backward compatibility: Existing --watch (no value) and config/env watch: true unchanged; watchPaths is [] and cwd is watched.

Checklist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only watch specified directory (--watch CLI param)

1 participant