MCPcopy Create free account
hub / github.com/nodejs/node / watchPath

Method watchPath

lib/internal/watch_mode/files_watcher.js:116–132  ·  view source on GitHub ↗
(path, recursive = true, options = kEmptyObject)

Source from the content-addressed store, hash-verified

114 }
115
116 watchPath(path, recursive = true, options = kEmptyObject) {
117 if (this.#isPathWatched(path)) {
118 return;
119 }
120 const { allowMissing = false } = options;
121
122 const watcher = watch(path, { recursive, signal: this.#signal, throwIfNoEntry: !allowMissing });
123 watcher.on('change', (eventType, fileName) => {
124 // `fileName` can be `null` if it cannot be determined. See
125 // https://github.com/nodejs/node/pull/49891#issuecomment-1744673430.
126 this.#onChange(recursive ? resolve(path, fileName ?? '') : path, eventType);
127 });
128 this.#watchers.set(path, { handle: watcher, recursive });
129 if (recursive) {
130 this.#removeWatchedChildren(path);
131 }
132 }
133
134 filterFile(file, owner, options = kEmptyObject) {
135 if (!file) return;

Callers 5

watchFilesFunction · 0.95
filterFileMethod · 0.95
watch_mode.jsFile · 0.80

Calls 7

#isPathWatchedMethod · 0.95
#onChangeMethod · 0.95
watchFunction · 0.50
resolveFunction · 0.50
onMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected