npm install watchpack
97.2
Supply Chain Risk
99.6
Quality
84.7
Maintenance
100
Vulnerability
375 Stars
396 Commits
104 Forks
15 Watching
4 Branches
95 Contributors
Updated on 03 Sept 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Wrapper library for directory and file watching.
watchpack high level API doesn't map directly to watchers. Instead a three level architecture ensures that for each directory only a single watcher exists.
DirectoryWatchers
from a WatcherManager
, which ensures that only a single DirectoryWatcher
per directory is created.Watcher
can be obtained from a DirectoryWatcher
and provides a filtered view on the DirectoryWatcher
.DirectoryWatcher
and Watcher
to decide when to close them.DirectoryWatcher
.var Watchpack = require("watchpack"); var wp = new Watchpack({ // options: aggregateTimeout: 1000, // fire "aggregated" event when after a change for 1000ms no additional change occurred // aggregated defaults to undefined, which doesn't fire an "aggregated" event poll: true, // poll: true - use polling with the default interval // poll: 10000 - use polling with an interval of 10s // poll defaults to undefined, which prefer native watching methods // Note: enable polling when watching on a network path // When WATCHPACK_POLLING environment variable is set it will override this option followSymlinks: true, // true: follows symlinks and watches symlinks and real files // (This makes sense when symlinks has not been resolved yet, comes with a performance hit) // false (default): watches only specified item they may be real files or symlinks // (This makes sense when symlinks has already been resolved) ignored: "**/.git" // ignored: "string" - a glob pattern for files or folders that should not be watched // ignored: ["string", "string"] - multiple glob patterns that should be ignored // ignored: /regexp/ - a regular expression for files or folders that should not be watched // ignored: (entry) => boolean - an arbitrary function which must return truthy to ignore an entry // For all cases expect the arbitrary function the path will have path separator normalized to '/'. // All subdirectories are ignored too }); // Watchpack.prototype.watch({ // files: Iterable<string>, // directories: Iterable<string>, // missing: Iterable<string>, // startTime?: number // }) wp.watch({ files: listOfFiles, directories: listOfDirectories, missing: listOfNotExistingItems, startTime: Date.now() - 10000 }); // starts watching these files and directories // calling this again will override the files and directories // files: can be files or directories, for files: content and existence changes are tracked // for directories: only existence and timestamp changes are tracked // directories: only directories, directory content (and content of children, ...) and // existence changes are tracked. // assumed to exist, when directory is not found without further information a remove event is emitted // missing: can be files or directories, // only existence changes are tracked // expected to not exist, no remove event is emitted when not found initially // files and directories are assumed to exist, when they are not found without further information a remove event is emitted // missing is assumed to not exist and no remove event is emitted wp.on("change", function(filePath, mtime, explanation) { // filePath: the changed file // mtime: last modified time for the changed file // explanation: textual information how this change was detected }); wp.on("remove", function(filePath, explanation) { // filePath: the removed file or directory // explanation: textual information how this change was detected }); wp.on("aggregated", function(changes, removals) { // changes: a Set of all changed files // removals: a Set of all removed files // watchpack gives up ownership on these Sets. }); // Watchpack.prototype.pause() wp.pause(); // stops emitting events, but keeps watchers open // next "watch" call can reuse the watchers // The watcher will keep aggregating events // which can be received with getAggregated() // Watchpack.prototype.close() wp.close(); // stops emitting events and closes all watchers // Watchpack.prototype.getAggregated(): { changes: Set<string>, removals: Set<string> } const { changes, removals } = wp.getAggregated(); // returns the current aggregated info and removes that from the watcher // The next aggregated event won't include that info and will only emitted // when futher changes happen // Can also be used when paused. // Watchpack.prototype.collectTimeInfoEntries(fileInfoEntries: Map<string, Entry>, directoryInfoEntries: Map<string, Entry>) wp.collectTimeInfoEntries(fileInfoEntries, directoryInfoEntries); // collects time info objects for all known files and directories // this include info from files not directly watched // key: absolute path, value: object with { safeTime, timestamp } // safeTime: a point in time at which it is safe to say all changes happened before that // timestamp: only for files, the mtime timestamp of the file // Watchpack.prototype.getTimeInfoEntries() var fileTimes = wp.getTimeInfoEntries(); // returns a Map with all known time info objects for files and directories // similar to collectTimeInfoEntries but returns a single map with all entries // (deprecated) // Watchpack.prototype.getTimes() var fileTimes = wp.getTimes(); // returns an object with all known change times for files // this include timestamps from files not directly watched // key: absolute path, value: timestamp as number
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
11 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 9
Reason
5 existing vulnerabilities detected
Details
Reason
Found 2/12 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-09-02
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 MoreLast day
25.3%
4,891,291
Compared to previous day
Last week
4.5%
26,098,249
Compared to previous week
Last month
0.2%
104,713,918
Compared to previous month
Last year
-1.9%
1,265,385,638
Compared to previous year