watchpack
Wrapper library for directory and file watching.
Concept
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.
- The high level API requests
DirectoryWatchers
from a WatcherManager
, which ensures that only a single DirectoryWatcher
per directory is created. - A user-faced
Watcher
can be obtained from a DirectoryWatcher
and provides a filtered view on the DirectoryWatcher
. - Reference-counting is used on the
DirectoryWatcher
and Watcher
to decide when to close them. - The real watchers are created by the
DirectoryWatcher
. - Files are never watched directly. This should keep the watcher count low.
- Watching can be started in the past. This way watching can start after file reading.
- Symlinks are not followed, instead the symlink is watched.
API
var Watchpack = require("watchpack");
var wp = new Watchpack({
aggregateTimeout: 1000,
poll: true,
followSymlinks: true,
ignored: "**/.git"
});
wp.watch({
files: listOfFiles,
directories: listOfDirectories,
missing: listOfNotExistingItems,
startTime: Date.now() - 10000
});
wp.on("change", function(filePath, mtime, explanation) {
});
wp.on("remove", function(filePath, explanation) {
});
wp.on("aggregated", function(changes, removals) {
});
wp.pause();
wp.close();
const { changes, removals } = wp.getAggregated();
wp.collectTimeInfoEntries(fileInfoEntries, directoryInfoEntries);
var fileTimes = wp.getTimeInfoEntries();
var fileTimes = wp.getTimes();