chokidar icon indicating copy to clipboard operation
chokidar copied to clipboard

initial add event fired after ready, ready fired twice

Open fknx opened this issue 3 years ago • 1 comments

Describe the bug

The initial add event is fired after the ready event in case one of the files watched does not exist, if the files are passed to chokidar explicitly. Additionally, the ready event fires twice.

Versions:

  • Chokidar: 3.5.1
  • Node: 14.17.0
  • OS version: Windows 10, 2004 (Build 19041.985)

To Reproduce:

const chokidar = require('chokidar');

const files = ['file1.txt', 'file2.txt', 'file3.txt'];

const watcher = chokidar.watch(files, { ignoreInitial: false, cwd: '.' });

watcher.on('ready', () => console.log('ready'));
watcher.on('add', path => console.log('add:', path));

If all three files exist, then the output is as expected:

add: file1.txt
add: file2.txt
add: file3.txt
ready

However, if file2.txt does not exist, the add event for file3.txt is fired after the initial ready event, and a second ready event is fired:

add: file1.txt
ready
add: file3.txt
ready

Expected behavior

In the case of the missing file2.txt, I would expect the following output:

add: file1.txt
add: file3.txt
ready

fknx avatar Jun 02 '21 07:06 fknx

This looks similar to #1011, but in that case the ready event did not fire twice, so I'm not sure if the issues are related.

fknx avatar Jun 02 '21 07:06 fknx