Skip to content

feat(watch): prefer includes over excludes #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mogzol
Copy link

@mogzol mogzol commented Apr 2, 2025

Fixes #210

This change makes any explicitly included files in watch mode never get excluded, even if they otherwise would be. Particularly, this is useful for watching files that are excluded by the default excludes, like ".env" files, which were previously impossible to watch.

In making these changes, chokidar has also been upgraded to v4, which no longer supports glob patterns. Glob functionality is now achieved with the 'glob' library. The windowsPathsNoEscape glob option is enabled in order to keep the behavior the same as it was with chokidar v3, where backslash cannot be used as a glob escape character, and only as a directory separator.

Example

Consider the command:

tsx watch --exclude="./lib" --include="./lib/special.ts" index.ts

Previously, changes to ./lib/special.ts would not trigger a restart, despite the fact that it was explicitly watched, because it's containing folder was excluded. With these changes, a restart will be triggered, but changes to any other files in ./lib will still be ignored.

This is also true for included globs. For example, this command:

tsx watch --exclude="./lib" --include="./lib/dir/**" index.ts

Will restart if any files under ./lib/dir are modified, but will not restart for any other changes in the lib directory.

Fixes privatenumber#210

This change makes any explicitly included files in watch mode never get
excluded, even if they otherwise would be. Particularly, this is useful
for watching files that are excluded by the default excludes, like
".env" files, which were previously impossible to watch.

In making these changes, chokidar has also been upgraded to v4, which no
longer supports glob patterns. Glob functionality is now achieved with
the 'glob' library. The `windowsPathsNoEscape` glob option is enabled in
order to keep the behavior the same as it was with chokidar v3, where
backslash cannot be used as a glob escape character, and only as a
directory separator.
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.

Support for watching hidden files
1 participant