Skip to content
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

Cannot watch specific files inside ignored path #1225

Closed
SystemParadox opened this issue Jun 16, 2022 · 3 comments
Closed

Cannot watch specific files inside ignored path #1225

SystemParadox opened this issue Jun 16, 2022 · 3 comments
Labels

Comments

@SystemParadox
Copy link

SystemParadox commented Jun 16, 2022

Describe the bug

If you exclude a folder with ignored: ['**/node_modules/**'], it appears to be impossible to get chokidar to watch a specific subdirectory underneath this.

If you use ignored: ['**/node_modules/**', '!**/node_modules/foo/**'] then node_modules/foo remains ignored. It appears chokidar sees the first exclude pattern and doesn't even bother looking inside node_modules after that.

If you undo the negation and try to exclude it with a negative lookahead regex (ugh) then it seems to take the negated glob to include everything and doesn't bother with the regex: ignored: ['**/node_modules/**', '!**/node_modules/**', /node_modules\/(?!foo\/)/].

Versions:

  • Chokidar version: 2.1.8 and 3.5.3
  • Node version: 16.15.1
  • OS version: Linux Mint 20.3

To Reproduce:

Example program (just npm i chokidar and run this):

const chokidar = require('chokidar');
const fs = require('fs');
fs.mkdirSync('node_modules/foo', { recursive: true });
chokidar.watch(process.cwd(), {
    ignored: [
        '**/node_modules/**',
        '!**/node_modules/foo/**',
    ],
}).on('all', (event, path) => {
    console.log(event, path);
});
setTimeout(() => {
    fs.writeFile('node_modules/foo/test.txt', 'hello', () => {});
}, 500);
// Should output 'change node_modules/foo/test.txt'
// Should not output add/change for other modules like 'node_modules/chokidar'

Expected behavior

There should be an easy way to exclude a folder like node_modules but then override this to include specific subdirectories within it, without having to use mad things like negative lookahead regexes or individually exclude every other node_module.

Additional context

ViteJS adds ignored: ['**/node_modules/**'] by default to exclude files in node_modules and provides a server.watch.ignored option that allows appending extra entries to the ignored list. Vite's own documentation has an example that adds '!**/node_modules/your-package-name/**' to watch particular packages, but this does not work because of the above issue.

Most build tools (babel, webpack, vite, etc) get this completely wrong in their own include/exclude rules. Most build tools also use chokidar for watching. I think the chokidar documentation needs a section that clearly explains what build tools should be doing with their default config and user options so that node_modules can be excluded by default but easily and sanely overridden to include specific subfolders.

@SystemParadox
Copy link
Author

@paulmillr why has this been closed? I can't see any docs or fixes anywhere.

@paulmillr
Copy link
Owner

#1336

Repository owner locked and limited conversation to collaborators Jul 2, 2024
@paulmillr
Copy link
Owner

paulmillr commented Jul 2, 2024

To clarify, v4 drops support for globs. So, the issue would be "resolved". You will need to write either regexps, or filtering functions instead of globs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants