Gathering detailed insights and metrics for watchpack
Gathering detailed insights and metrics for watchpack
Gathering detailed insights and metrics for watchpack
Gathering detailed insights and metrics for watchpack
npm install watchpack
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
6,422,890,193
Last Day
1,667,037
Last Week
32,913,077
Last Month
146,990,419
Last Year
1,422,189,699
MIT License
390 Stars
405 Commits
110 Forks
14 Watchers
7 Branches
101 Contributors
Updated on Aug 27, 2025
Latest Version
2.4.4
Package Id
watchpack@2.4.4
Unpacked Size
56.31 kB
Size
14.20 kB
File Count
9
NPM Version
10.9.2
Node Version
22.13.1
Published on
May 21, 2025
Cumulative downloads
Total Downloads
Last Day
-19.2%
1,667,037
Compared to previous day
Last Week
-1.3%
32,913,077
Compared to previous week
Last Month
5.8%
146,990,419
Compared to previous month
Last Year
12.5%
1,422,189,699
Compared to previous year
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
.1var Watchpack = require("watchpack"); 2 3var wp = new Watchpack({ 4 // options: 5 aggregateTimeout: 1000, 6 // fire "aggregated" event when after a change for 1000ms no additional change occurred 7 // aggregated defaults to undefined, which doesn't fire an "aggregated" event 8 9 poll: true, 10 // poll: true - use polling with the default interval 11 // poll: 10000 - use polling with an interval of 10s 12 // poll defaults to undefined, which prefer native watching methods 13 // Note: enable polling when watching on a network path 14 // When WATCHPACK_POLLING environment variable is set it will override this option 15 16 followSymlinks: true, 17 // true: follows symlinks and watches symlinks and real files 18 // (This makes sense when symlinks has not been resolved yet, comes with a performance hit) 19 // false (default): watches only specified item they may be real files or symlinks 20 // (This makes sense when symlinks has already been resolved) 21 22 ignored: "**/.git" 23 // ignored: "string" - a glob pattern for files or folders that should not be watched 24 // ignored: ["string", "string"] - multiple glob patterns that should be ignored 25 // ignored: /regexp/ - a regular expression for files or folders that should not be watched 26 // ignored: (entry) => boolean - an arbitrary function which must return truthy to ignore an entry 27 // For all cases expect the arbitrary function the path will have path separator normalized to '/'. 28 // All subdirectories are ignored too 29}); 30 31// Watchpack.prototype.watch({ 32// files: Iterable<string>, 33// directories: Iterable<string>, 34// missing: Iterable<string>, 35// startTime?: number 36// }) 37wp.watch({ 38 files: listOfFiles, 39 directories: listOfDirectories, 40 missing: listOfNotExistingItems, 41 startTime: Date.now() - 10000 42}); 43// starts watching these files and directories 44// calling this again will override the files and directories 45// files: can be files or directories, for files: content and existence changes are tracked 46// for directories: only existence and timestamp changes are tracked 47// directories: only directories, directory content (and content of children, ...) and 48// existence changes are tracked. 49// assumed to exist, when directory is not found without further information a remove event is emitted 50// missing: can be files or directories, 51// only existence changes are tracked 52// expected to not exist, no remove event is emitted when not found initially 53// files and directories are assumed to exist, when they are not found without further information a remove event is emitted 54// missing is assumed to not exist and no remove event is emitted 55 56wp.on("change", function(filePath, mtime, explanation) { 57 // filePath: the changed file 58 // mtime: last modified time for the changed file 59 // explanation: textual information how this change was detected 60}); 61 62wp.on("remove", function(filePath, explanation) { 63 // filePath: the removed file or directory 64 // explanation: textual information how this change was detected 65}); 66 67wp.on("aggregated", function(changes, removals) { 68 // changes: a Set of all changed files 69 // removals: a Set of all removed files 70 // watchpack gives up ownership on these Sets. 71}); 72 73// Watchpack.prototype.pause() 74wp.pause(); 75// stops emitting events, but keeps watchers open 76// next "watch" call can reuse the watchers 77// The watcher will keep aggregating events 78// which can be received with getAggregated() 79 80// Watchpack.prototype.close() 81wp.close(); 82// stops emitting events and closes all watchers 83 84// Watchpack.prototype.getAggregated(): { changes: Set<string>, removals: Set<string> } 85const { changes, removals } = wp.getAggregated(); 86// returns the current aggregated info and removes that from the watcher 87// The next aggregated event won't include that info and will only emitted 88// when futher changes happen 89// Can also be used when paused. 90 91// Watchpack.prototype.collectTimeInfoEntries(fileInfoEntries: Map<string, Entry>, directoryInfoEntries: Map<string, Entry>) 92wp.collectTimeInfoEntries(fileInfoEntries, directoryInfoEntries); 93// collects time info objects for all known files and directories 94// this include info from files not directly watched 95// key: absolute path, value: object with { safeTime, timestamp } 96// safeTime: a point in time at which it is safe to say all changes happened before that 97// timestamp: only for files, the mtime timestamp of the file 98 99// Watchpack.prototype.getTimeInfoEntries() 100var fileTimes = wp.getTimeInfoEntries(); 101// returns a Map with all known time info objects for files and directories 102// similar to collectTimeInfoEntries but returns a single map with all entries 103 104// (deprecated) 105// Watchpack.prototype.getTimes() 106var fileTimes = wp.getTimes(); 107// returns an object with all known change times for files 108// this include timestamps from files not directly watched 109// key: absolute path, value: timestamp as number
No vulnerabilities found.