paulmillr / chokidar

Minimal and efficient cross-platform file watching library
https://paulmillr.com
MIT License
10.86k stars 575 forks source link

Ignored prop doesn't work as expected #1284

Closed peter-olom closed 1 year ago

peter-olom commented 1 year ago

In attempting to watch specific file types, chokidar effectively stops watching all files.

To Reproduce:

import chokidar from "chokidar";
import path, { extname } from "path";

const WATCH_DIR = path.join(process.env.USERPROFILE ?? '', '/Documents');
console.log('@@@ Watching directory: ', WATCH_DIR); // Outputs the correct directory e.g C:\Users\username\Documents

const watcher = chokidar.watch(WATCH_DIR, {
    //ignore all none documents
    ignored: path => !(['xlsx', 'docx', 'pdf', 'pptx', 'txt'].includes(extname(path).slice(1))),
    ignoreInitial: true,
    ignorePermissionErrors: true,
});

watcher.on('all', (event, path) => {
    console.log('@@@', event, path);
});

Expected behavior When I add or delete any file type in the list, an event is emitted.

Additional context If I remove the negation (!) in the ignored prop, then it ignores all the file types in the list.

peter-olom commented 1 year ago

Never mind this issue, I gave it a fresh look today and realized I could implement a white watchlist using glob patterns.