@ms-cloudpack/file-watcher
An abstraction on the file watching capabilities used in Cloudpack.
Example usage
- Create a watcher:
const watcher = createWatcher();
- Subscribe to a particular package path using
watch
. (Returns an unwatch
function.)
const unwatch = watcher.watch({ path: 'path/to/package' }, () => console.log(`package changed`));
- To dispose, call the returned
unwatch
, or call watcher.dispose
to unsubscribe from all watchers.
await unwatch();
await watcher.dispose();
createWatcher
options
type
('default' | 'fork'
, optional): By default, this will create a watcher in the same thread. Use type: 'fork'
to create the watcher in a forked process.
watcher.watch
options
path
(string
): The absolute root path to be watched.id
(string
, optional): ID for the watch job (defaults to path
). If you call watch
twice using the same id
, subsequent calls will be ignored.watchedPaths
(string[]
, optional): Relative paths/globs from the root path to watch. Defaults to *.json
and src/**/*
, excluding node_modules
.