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

Folder rename is not reported when using a pattern #1285

Open
Janpot opened this issue Aug 4, 2023 · 2 comments
Open

Folder rename is not reported when using a pattern #1285

Janpot opened this issue Aug 4, 2023 · 2 comments

Comments

@Janpot
Copy link

Janpot commented Aug 4, 2023

Describe the bug

When a folder is renamed and the original and new folder is part of a path that is covered by a glob that chokidar is watching, no events are fired.

Versions:

  • Chokidar version: 3.5.3
  • Node version: 18.16.0
  • OS version: MacOs 13.5

To Reproduce:

  1. create a file ./hello/foo/file.txt
  2. run
    const path = require('path');
    const chokidar = require('chokidar');
    
    chokidar.watch(path.resolve(__dirname, './hello/*/file.txt')).on('all', (event, filePath) => {
      console.log(event, filePath);
    });
  3. run mv ./hello/foo ./hello/bar
  4. no events are being fired

Expected behavior

an unlink and add event is fired for the rename. (This does happen when using usePolling)

@AlynxZhou
Copy link

I also reproduced this problem with @Janpot 's example but a little bit differently, I could get add event when moving a dir, but no unlink event.

@denysdovhan
Copy link

denysdovhan commented Apr 12, 2024

We experience a very similar problem, but with folder deletion. We use chokidar like this:

chokidar.watch([
  'src/foo/**/file.json',
  'src/bar/**/file.json'
], {
  useFsEvents: false, // <-- THIS SOLVES THE PROBLEM
  ignoreInitial: true,
}).on('all', (eventName, path) => console.log({eventName, path}))

When we delete foo or bar folders, neither unlink nor unlinkDir are emitted. The reason for that seems to be this line:

if (globFilter && !globFilter(path)) return;

When a file patter contains a glob, it gets returned, so update is not reported.

The solution for us is to set useFsEvents: false. It also seems to be used widely by other various libraries.

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

No branches or pull requests

3 participants