👀 A native C++ Node module for querying and subscribing to filesystem events
Installations
npm install @parcel/watcher-darwin-arm64
Score
98.8
Supply Chain
34.9
Quality
83.6
Maintenance
100
Vulnerability
100
License
Developer
parcel-bundler
Developer Guide
Module System
CommonJS
Min. Node Version
>= 10.0.0
Typescript Support
No
Node Version
18.20.4
NPM Version
10.7.0
Statistics
664 Stars
162 Commits
46 Forks
24 Watching
13 Branches
17 Contributors
Updated on 27 Nov 2024
Languages
C++ (59.44%)
JavaScript (36.37%)
C (1.99%)
Python (1.45%)
Makefile (0.75%)
Total Downloads
Cumulative downloads
Total Downloads
30,694,275
Last day
-12.8%
217,779
Compared to previous day
Last week
0.5%
1,334,530
Compared to previous week
Last month
50.3%
5,534,562
Compared to previous month
Last year
549.3%
26,598,070
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
@parcel/watcher
A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.
Features
- Watch - subscribe to realtime recursive directory change notifications when files or directories are created, updated, or deleted.
- Query - performantly query for historical change events in a directory, even when your program is not running.
- Native - implemented in C++ for performance and low-level integration with the operating system.
- Cross platform - includes backends for macOS, Linux, Windows, FreeBSD, and Watchman.
- Performant - events are throttled in C++ so the JavaScript thread is not overwhelmed during large filesystem changes (e.g.
git checkout
ornpm install
). - Scalable - tens of thousands of files can be watched or queried at once with good performance.
Example
1const watcher = require('@parcel/watcher'); 2const path = require('path'); 3 4// Subscribe to events 5let subscription = await watcher.subscribe(process.cwd(), (err, events) => { 6 console.log(events); 7}); 8 9// later on... 10await subscription.unsubscribe(); 11 12// Get events since some saved snapshot in the past 13let snapshotPath = path.join(process.cwd(), 'snapshot.txt'); 14let events = await watcher.getEventsSince(process.cwd(), snapshotPath); 15 16// Save a snapshot for later 17await watcher.writeSnapshot(process.cwd(), snapshotPath);
Watching
@parcel/watcher
supports subscribing to realtime notifications of changes in a directory. It works recursively, so changes in sub-directories will also be emitted.
Events are throttled and coalesced for performance during large changes like git checkout
or npm install
, and a single notification will be emitted with all of the events at the end.
Only one notification will be emitted per file. For example, if a file was both created and updated since the last event, you'll get only a create
event. If a file is both created and deleted, you will not be notifed of that file. Renames cause two events: a delete
for the old name, and a create
for the new name.
1let subscription = await watcher.subscribe(process.cwd(), (err, events) => { 2 console.log(events); 3});
Events have two properties:
type
- the event type:create
,update
, ordelete
.path
- the absolute path to the file or directory.
To unsubscribe from change notifications, call the unsubscribe
method on the returned subscription object.
1await subscription.unsubscribe();
@parcel/watcher
has the following watcher backends, listed in priority order:
- FSEvents on macOS
- Watchman if installed
- inotify on Linux
- ReadDirectoryChangesW on Windows
- kqueue on FreeBSD, or as an alternative to FSEvents on macOS
You can specify the exact backend you wish to use by passing the backend
option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
Querying
@parcel/watcher
also supports querying for historical changes made in a directory, even when your program is not running. This makes it easy to invalidate a cache and re-build only the files that have changed, for example. It can be significantly faster than traversing the entire filesystem to determine what files changed, depending on the platform.
In order to query for historical changes, you first need a previous snapshot to compare to. This can be saved to a file with the writeSnapshot
function, e.g. just before your program exits.
1await watcher.writeSnapshot(dirPath, snapshotPath);
When your program starts up, you can query for changes that have occurred since that snapshot using the getEventsSince
function.
1let events = await watcher.getEventsSince(dirPath, snapshotPath);
The events returned are exactly the same as the events that would be passed to the subscribe
callback (see above).
@parcel/watcher
has the following watcher backends, listed in priority order:
- FSEvents on macOS
- Watchman if installed
- fts (brute force) on Linux and FreeBSD
- FindFirstFile (brute force) on Windows
The FSEvents (macOS) and Watchman backends are significantly more performant than the brute force backends used by default on Linux and Windows, for example returning results in miliseconds instead of seconds for large directory trees. This is because a background daemon monitoring filesystem changes on those platforms allows us to query cached data rather than traversing the filesystem manually (brute force).
macOS has good performance with FSEvents by default. For the best performance on other platforms, install Watchman and it will be used by @parcel/watcher
automatically.
You can specify the exact backend you wish to use by passing the backend
option. If that backend is not available on the current platform, the default backend will be used instead. See below for the list of backend names that can be passed to the options.
Options
All of the APIs in @parcel/watcher
support the following options, which are passed as an object as the last function argument.
ignore
- an array of paths or glob patterns to ignore. usesis-glob
to distinguish paths from globs. glob patterns are parsed withmicromatch
(see features).- paths can be relative or absolute and can either be files or directories. No events will be emitted about these files or directories or their children.
- glob patterns match on relative paths from the root that is watched. No events will be emitted for matching paths.
backend
- the name of an explicitly chosen backend to use. Allowed options are"fs-events"
,"watchman"
,"inotify"
,"kqueue"
,"windows"
, or"brute-force"
(only for querying). If the specified backend is not available on the current platform, the default backend will be used instead.
WASM
The @parcel/watcher-wasm
package can be used in place of @parcel/watcher
on unsupported platforms. It relies on the Node fs
module, so in non-Node environments such as browsers, an fs
polyfill will be needed.
Note: the WASM implementation is significantly less efficient than the native implementations because it must crawl the file system to watch each directory individually. Use the native @parcel/watcher
package wherever possible.
1import {subscribe} from '@parcel/watcher-wasm'; 2 3// Use the module as documented above. 4subscribe(/* ... */);
Who is using this?
License
MIT
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
11 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
binaries present in source code
Details
- Warn: binary detected: watchman/windows/bin/gflags.dll:1
- Warn: binary detected: watchman/windows/bin/glog.dll:1
- Warn: binary detected: watchman/windows/bin/watchman.exe:1
Reason
7 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:69: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:71: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:81: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:89: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:91: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:105: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:115: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:117: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:124: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:136: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:137: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:143: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:79: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:81: update your workflow using https://app.stepsecurity.io/secureworkflow/parcel-bundler/watcher/test.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/release.yml:77
- Info: 0 out of 16 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @parcel/watcher-darwin-arm64
@parcel/watcher-linux-arm64-musl
A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.
@parcel/watcher-android-arm64
A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.
@parcel/watcher-linux-arm64-glibc
A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.
@parcel/watcher-win32-arm64
A native C++ Node module for querying and subscribing to filesystem events. Used by Parcel 2.