From 5183e3a4b12180c63f74dc1cb39385282955d542 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 30 Dec 2023 22:30:15 +0100 Subject: [PATCH] watch: clarify that the fileName parameter can be null MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Yagiz Nizipli Reviewed-By: Benjamin Gruenbaum --- 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);