parcel-bundler / watcher

👀 A native C++ Node module for querying and subscribing to filesystem events
MIT License
659 stars 44 forks source link

File queries #42

Open rtsao opened 4 years ago

rtsao commented 4 years ago

Is there any maintainer interest in additional features that would increase parity with watchman?

In particular, it'd be nice to be able to

https://facebook.github.io/watchman/docs/file-query.html has a lot of different types of file queries, but for my use case basic glob or file extension would probably suffice.

Obviously this can be done in userland, but it would be neat if this was on the C++ end.

DeMoorJasper commented 4 years ago

Supporting globs sounds like a great addition to this library, not entirely sure how much work this will be.

The file change querying is already possible let events = await watcher.getEventsSince(dirPath, snapshotPath);?

devongovett commented 4 years ago

I'm curious, what would you use this for?

rtsao commented 4 years ago

I would have a variety of use cases, but mainly standalone code generation tools and standalone non-web programming language compilers.

This library has a lot of appeal compared to other Node.js file watchers. I'm looking at using this as an alternative to using Watchman directly, thereby eliminating a hard requirement for end users (but still allowing for progressive enhancement if they already use it).

So I'd probably want to query the file system for specifically relevant files (probably via glob or file extension) upon cold start (changed since an arbitrary time, regardless of if an existing snapshot exists), then listen for change events if operating in watch-compile mode.

It is definitely understandable if you'd rather not have this be a general-purpose, fully featured watcher. But I think would potentially fill a really nice niche outside of just Parcel specifically.

aleclarson commented 3 years ago

watch only specific kinds of files (i.e. *.css)

You could try filespy, a wrapper for @parcel/watcher.

https://github.com/alloc/filespy

kresnasatya commented 1 year ago
  • query/watch only specific kinds of files (i.e. *.css)

I vote for this idea especially for Backend Integration like PHP, Ruby, etc.

Currently, I create a WordPress theme integrate with ViteJS with purpose to refresh the page on the browser (without user action) with PHP file extension if I do actions like create, edit, move, and delete in PHP file. So far I know, to support this capabilities developers tend to use chokidar wrapped with vite-plugin (e.g. : ElMassimo/vite-plugin-full-reload and arnoson/vite-plugin-live-reload) because chokidar can also watch file, glob, and array beside of dir.

I wish if @parcel/watcher can support these capabilities too.

Maybe we can add more flexibility in first parameter like await watcher.subscribe(‘file, dir, glob, array’, (err, status) => {}) instead of await watcher.subscribe(process.cwd(), (err, status) => {}).