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
const Watchpack = require("watchpack");
const 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", (filePath, mtime, explanation) => {
});
wp.on("remove", (filePath, explanation) => {
});
wp.on("aggregated", (changes, removals) => {
});
wp.pause();
wp.close();
const { changes, removals } = wp.getAggregated();
wp.collectTimeInfoEntries(fileInfoEntries, directoryInfoEntries);
const fileTimes = wp.getTimeInfoEntries();
const fileTimesOld = wp.getTimes();