chokidar icon indicating copy to clipboard operation
chokidar copied to clipboard

The `ignored` function is always called twice

Open skerit opened this issue 4 years ago • 1 comments

Describe the bug

According to the documentation of the ignored option:

If a function with two arguments is provided, it gets called twice per path -
once with a single argument (the path), second time with two arguments
(the path and the fs.Stats object of that path).

I'm supplying a function as the ignored option with a single argument, yet it's being called twice and always with 2 arguments: the first time with a stats object, and the second time without one.

Another weird behaviour when I do give it a function with 2 arguments is that it doesn't seem to call the function for each file, just the first subdirectories it sees after which

Versions:

  • Chokidar version: 3.4.0
  • Node version: 12.18.2
  • OS version: Ubuntu 20.04

To Reproduce:

const chokidar = require('chokidar');
let watcher = chokidar.watch(some_directory, {ignored: function ignoreThisPath(_path) {

	console.log(arguments.length)
	console.log(_path);
	return false;
}});

Expected behavior

It should only be called once

Additional context

I've been using chokidar for years: it automatically restarts (well, exits) my dev server when I change a js file

skerit avatar Jul 14 '20 10:07 skerit

@paulmillr It would be also nice to have more infor on what to do if I only want to respond to the call with stat included as I need that. What do I return when the ignored function is called without the stat? True, false? Why do you need to call this function twice? Actually, it seems to be called three times for me. Perhaps another separate ignore-like properties in options for each?

andrisi avatar Mar 12 '22 14:03 andrisi