deno
deno copied to clipboard
Add "ignore" to Deno.watchFs
Hey,
been using Deno for a while now. For a cli tool I'm using Deno.watchFs, which works fine.
My use case is the following: I want to watch a whole directory recursively and then have different actions depending on what files have changed. This allows me do dynamically listen for new folder creations etc. in one place.
The problem: Attaching the watcher to the project root directory (with e.g. the .git folder) takes a long time, sometimes seconds. It would be very convenient to have something like "ignore" alongside with the "recursive" option in order to initially exclude some folders or files from being watched, but still watch all the files and folders that are present recursively.
I know that I could restructure the project, maybe put everything that needs "watching" into a separate sub directory, but I think this would be a great and convenient addition to the file watcher.
Also I'm happy to contribute and add this to the watcher, if it's something that will be adopted. So this would be cool:
using watcher = Deno.watchFs(rootDir, { recursive: true, ignore: [".git", "some-other-file"] });
// or
using watcher = Deno.watchFs(rootDir, { recursive: true, ignore: ".git" });
As I understand it we would just need to add a filter to the loop of the files and simply skip it if it's in the ignore list: https://github.com/denoland/deno/blob/e4b52f5a7684cfb6754f2531e51f833a64d97d7b/runtime/ops/fs_events.rs#L125-L130
But maybe I'm wrong and this change needs to happen in the inotify crate. Or maybe there is even a better solution that works with the current setup?