Chokidar 4.0.1 not responding to add change or unlink events in Bun 1.1.27 #1382
Description
Describe the bug
A clear and concise description of what the bug is.
Versions (please complete the following information):
- Chokidar version 4.0.1
- Bun 1.1.27
- OS version: Ubuntu 24.04.1 LTS on Windows 10 x86_64
To Reproduce:
Steps to reproduce the behavior. Include filename and chokidar config.
Ideally prove a problem by isolating and making it reproducible with a very short sample program, which you could paste here:
// apps/server
import { env } from '@project/env';
import { fileWatcher } from '@project/core';
fileWatcher(env.DIR1_PATH, env.DIR2_PATH, env.DIR3_PATH);
const PORT = 3004;
app.listen(PORT, () => {
console.log(`Listening on http://localhost:${PORT}`);
});
The above is from apps/server
and runs via bun --watch run src/index.ts
It uses chokidar wrapper from packages/core
below
// packages/core
import chokidar from 'chokidar';
var fileSystem = [] as any;
var ready: any;
const fileWatcher = (dir1Path, dir2Path, dir3Path) => {
if (new Set([dir1Path, dir2Path, dir3Path]).size != 3) {
throw 'Each directory must be in a different subdirectory and cannot share the same directory path(s)';
}
const watcher = chokidar.watch(
[dir1Path as string, dir2Path as string, dir3Path as string],
{
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true,
},
);
watcher.on('ready', () => {
console.log('Initial scan complete. Ready for changes');
ready = true;
ready && sync();
});
watcher
.on('add', (path) => {
console.log(`File ${path} has been added`);
fileSystem.push(path);
ready && sync();
})
.on('change', (path) => {
console.log(`File ${path} has been changed`);
})
.on('unlink', (path) => {
console.log(`File ${path} has been removed`);
fileSystem = fileSystem.filter((e: any) => e !== path);
ready && sync();
});
const sync = async () => {
fileSystem && (await upsertRow(fileSystem[fileSystem .length - 1]))
...
};
return watcher;
}
However, when I add new files, rename existing files or remove existing files from any of the three directories in the chokidar array, it does not initiate the watch events
I know because there is no console log when there is filesystem activity
It was working before, not sure when it broke. Havent tested in a while
Most valuable could be one or more test cases for test.js to demonstrate the problem.
Expected behavior
when I add new files, rename existing files or remove existing files from any of the three directories in the chokidar array, it should call the add, unlink or change events (watcher.on()
)