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

Can't watch for file creation inside of non-yet-existing directory #872

Open
pixelastic opened this issue Jul 30, 2019 · 3 comments
Open
Labels

Comments

@pixelastic
Copy link

pixelastic commented Jul 30, 2019

Describe the bug
Watching ./foo/bar.txt when ./foo/ does not yet exists won't trigger any event when ./foo/bar.txt is finally created.
Having ./foo/ existing when calling chokidar.watch or watching ./*/bar.txt works correctly, though.

Versions (please complete the following information):

  • Chokidar version: 3.0.2
  • Node version: v12.6.0
  • OS version: Ubuntu 18.04.2 LTS

To Reproduce

const chokidar = require('chokidar');
const fs = require('fs');

// Make sure no ./foo directory currently exists

chokidar.watch('foo/test*', {}).on('all', () => {
  console.log('This will never be called');
});
chokidar.watch('*/test*', {}).on('all', () => {
  console.log('This will be called');
});

fs.mkdirSync('foo');
fs.writeFileSync('foo/test.txt', 'testing 1');
// Both events should fire, but only the second watcher is triggered

From reading the tests it seems to be expected behavior (the tests explicitly create directories before watching files), but I can't find any documentation on the subject nor any way to bypass it.

Expected behavior
I would expect events to be fired when files are created inside of non-yet-existing directories, no matter how I define my pattern (with a glob, or a static string).

Additional context
I'm currently using a hack to force chokidar to treat my static string as a glob by using (foo|$*)/test* instead of foo/test*. $* will never match anything so both foo and (foo|$*) should match the same things, but it seems to somehow trigger chokidar into the right behavior.

@pixelastic
Copy link
Author

FWIW, I tested on chokidar 3.2.0 and still having the same issue

@exx8
Copy link

exx8 commented Oct 10, 2019

Have you tried my pull request?

@pixelastic

@aleclarson
Copy link

This isn't a problem in filespy, an alternative to chokidar.

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

No branches or pull requests

4 participants