You can reproduce the problem with the following test code:
const { fs } = require("memfs");
const path = require("path");
const watchedDirectory = path.join(__dirname, "watched");
fs.mkdirSync(watchedDirectory, { recursive: true });
fs.watch(watchedDirectory, { recursive: true }, (eventType, filename) => { console.log("Received: " + eventType + " " + filename); })
fs.mkdirSync(path.join(watchedDirectory, "new_dir"), { recursive: true });
fs.writeFileSync(path.join(watchedDirectory, "new_dir", "new_file"), "stuff");
You will see the following output:
Received: rename ../watched/new_dir
There is no event raised for new_file.
It looks like this is due to the following setTimeout() call, which sends critical watcher attachments to the back of the timer queue:
If I remove that setTimeout() wrapper, I see the following output:
Received: rename ../watched/new_dir
Received: rename ../watched/new_dir/new_file
Received: change ../watched/new_dir/new_file
Received: change ../watched/new_dir/new_file
This is much better.
Please note that, if you use Node's default fs instead of memfs, you will see the following output, which we could consider canonical:
Received: rename new_dir
Received: rename new_dir\new_file
Received: change new_dir\new_file
Received: change new_dir
There is still a small difference between fs and memfs. In Node's fs, the last change event is for the parent directory. In memfs, the last change event is for the file itself. From the point-of-view of the user, it just looks like a duplicate event. Maybe it's due to #116 ?
If I add any additional writeFileSync() calls, both fs and memfs raise duplicate change events for the file, so, they match perfectly there.
Thanks a lot for your consideration!
You can reproduce the problem with the following test code:
You will see the following output:
There is no event raised for
new_file.It looks like this is due to the following setTimeout() call, which sends critical watcher attachments to the back of the timer queue:
memfs/src/volume.ts
Line 2514 in d78d6b8
If I remove that setTimeout() wrapper, I see the following output:
This is much better.
Please note that, if you use Node's default
fsinstead ofmemfs, you will see the following output, which we could consider canonical:There is still a small difference between
fsandmemfs. In Node'sfs, the last change event is for the parent directory. Inmemfs, the last change event is for the file itself. From the point-of-view of the user, it just looks like a duplicate event. Maybe it's due to #116 ?If I add any additional
writeFileSync()calls, bothfsandmemfsraise duplicate change events for the file, so, they match perfectly there.Thanks a lot for your consideration!