paulmillr / chokidar

Minimal and efficient cross-platform file watching library

Home Page:https://paulmillr.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Watching multiple non-existing files in the same directory results in all files other than the first one being ignored

vilicvane opened this issue · comments

Versions (please complete the following information):

  • Chokidar version 3.5.3

To Reproduce:

const FS = require("fs");
const Chokidar = require("chokidar");

const watcher = Chokidar.watch(["file-1", "file-2"]);

watcher.on("add", (path) => console.log(path));

// BTW, on("ready") doesn't work either.
setTimeout(() => {
  FS.writeFileSync("file-2", ""); // file-1 would work.
}, 1000);

Expected behavior

All previously non-existing files should receive "add" event on creation.

Additional context

I traced down to the NodeFsHandler#_handleRead() method and the way it throttles is the cause:

_handleRead(directory, initialAdd, wh, target, dir, depth, throttler) {
// Normalize the directory name on Windows
directory = sysPath.join(directory, EMPTY_STR);
if (!wh.hasGlob) {
throttler = this.fsw._throttle('readdir', directory, 1000);
if (!throttler) return;
}

Has there been a workaround for this yet?