diff --git a/lib/internal/watch_mode/files_watcher.js b/lib/internal/watch_mode/files_watcher.js index bbc13e67cc9f0d..02c836e14addf8 100644 --- a/lib/internal/watch_mode/files_watcher.js +++ b/lib/internal/watch_mode/files_watcher.js @@ -6,6 +6,7 @@ const { SafeMap, SafeSet, StringPrototypeStartsWith, + Symbol, } = primordials; const { validateNumber, validateOneOf } = require('internal/validators'); @@ -21,6 +22,7 @@ const { setTimeout } = require('timers'); const supportsRecursiveWatching = process.platform === 'win32' || process.platform === 'darwin'; +const kGlobalDebounce = Symbol('kGlobalDebounce'); class FilesWatcher extends EventEmitter { #watchers = new SafeMap(); #filteredFiles = new SafeSet(); @@ -74,16 +76,17 @@ class FilesWatcher extends EventEmitter { } #onChange(trigger) { - if (this.#debouncing.has(trigger)) { + if (this.#debouncing.has(trigger) || this.#debouncing.has(kGlobalDebounce)) { return; } if (this.#mode === 'filter' && !this.#filteredFiles.has(trigger)) { return; } - this.#debouncing.add(trigger); + this.#debouncing.add(trigger).add(kGlobalDebounce); const owners = this.#depencencyOwners.get(trigger); setTimeout(() => { this.#debouncing.delete(trigger); + this.#debouncing.delete(kGlobalDebounce); this.emit('changed', { owners }); }, this.#debounce).unref(); }