watch: clarify that the fileName parameter can be null

Add a comment to clarify that the `fileName` parameter can be `null` if
the file name cannot be determined.

PR-URL: https://github.com/nodejs/node/pull/51305
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Luigi Pinca
2023-12-30 22:30:15 +01:00
committed by GitHub
parent 338a5be272
commit 8bb30274db

View File

@@ -97,8 +97,11 @@ class FilesWatcher extends EventEmitter {
return;
}
const watcher = watch(path, { recursive, signal: this.#signal });
watcher.on('change', (eventType, fileName) => this
.#onChange(recursive ? resolve(path, fileName ?? '') : path));
watcher.on('change', (eventType, fileName) => {
// `fileName` can be `null` if it cannot be determined. See
// https://github.com/nodejs/node/pull/49891#issuecomment-1744673430.
this.#onChange(recursive ? resolve(path, fileName ?? '') : path);
});
this.#watchers.set(path, { handle: watcher, recursive });
if (recursive) {
this.#removeWatchedChildren(path);