Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSEvents behaves differently compared to inotify with glob excludes #171

Open
SamVerschueren opened this issue Apr 24, 2024 · 1 comment

Comments

@SamVerschueren
Copy link

Hey 👋

I was looking into the behaviour of parcel watcher and noticed a difference between macOS (FSEvents) and Linux (inotify). I believe Linux is correct in this one, as it behaves identically as the WASM version.

Let's assume the following code

import * as watcher from '@parcel/watcher';

await watcher.subscribe(
    process.cwd(), 
    (err, events) => {
        console.log(events);
    },
    {
        ignore: ['foo'],
    }
);

You can play around with it in this StackBlitz project.

You will not receive events for either foo, or any of it's children like foo/bar if they are created in the current working directory. This behaves identical on both macOS, Linux, and WASM.

However, if we change the ignore from foo to **/foo, things get interesting.

import * as watcher from '@parcel/watcher';

await watcher.subscribe(
    process.cwd(), 
    (err, events) => {
        console.log(events);
    },
    {
        ignore: ['**/foo'],
    }
);

On macOS, Linux, and WASM, you will not receive events for foo. On Linux and WASM, you will also not receive events for children like foo/bar. However, on macOS, you do receive events for children of foo.

This is also the case for the parcel watcher in VSCode where I used a file system watcher to subscribe to events on a directory.

I don't know if this is expected, but I assume the idea behind parcel-watcher is to have something which works identically on all platforms?

@bpasero
Copy link
Contributor

bpasero commented Apr 24, 2024

I think the main difference is that (to my knowledge) on Linux recursive file watching requires to install a watcher per folder, so you need to recursively go down the watch path and install watchers on each node. I think the ignore pattern is applied during that phase, such as **/foo will match on a path bar/foo and then stop events. But on platforms with good file watching support (macOS and Windows), the glob pattern is tested on the full path and that will not match the glob pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants