From 660659f1b9877318067eec6fc61627da614bccee Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 28 Dec 2023 22:04:13 +0100 Subject: [PATCH] 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. --- lib/internal/watch_mode/files_watcher.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/watch_mode/files_watcher.js b/lib/internal/watch_mode/files_watcher.js index 51b09c840b65f4..bbc13e67cc9f0d 100644 --- a/lib/internal/watch_mode/files_watcher.js +++ b/lib/internal/watch_mode/files_watcher.js @@ -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);