Skip to content
Merged
Prev Previous commit
Next Next commit
feat: make options an object
  • Loading branch information
efekrskl committed Feb 19, 2026
commit 3f567d49e8e461b5c872172814903695ae19472d
7 changes: 4 additions & 3 deletions lib/internal/fs/recursive_watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class FSWatcher extends EventEmitter {

assert(typeof options === 'object');

let { persistent, recursive, signal, encoding, ignore, throwIfNoEntry } = options;
const { persistent, recursive, signal, encoding, ignore } = options;
let { throwIfNoEntry } = options;

// TODO(anonrig): Add non-recursive support to non-native-watcher for IBMi & AIX support.
if (recursive != null) {
Expand All @@ -68,7 +69,7 @@ class FSWatcher extends EventEmitter {

if (throwIfNoEntry != null) {
validateBoolean(throwIfNoEntry, 'options.throwIfNoEntry');
} else {
} else {
throwIfNoEntry = true;
}
Comment thread
anonrig marked this conversation as resolved.

Expand Down Expand Up @@ -228,7 +229,7 @@ class FSWatcher extends EventEmitter {
this.#watchFolder(filename);
}
} catch (error) {
if (!this.#options.throwIfNoEntry && error.code === 'ENOENT') {
if (this.#options.throwIfNoEntry !== false && error.code === 'ENOENT') {
Comment thread
efekrskl marked this conversation as resolved.
Outdated
error.filename = filename;
throw error;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/main/watch_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function start() {
ArrayPrototypeForEach(kEnvFiles, (file) => watcher.filterFile(resolve(file)));
}
if (kOptionalEnvFiles.length > 0) {
ArrayPrototypeForEach(kOptionalEnvFiles, (file) => watcher.filterFile(resolve(file), undefined, true));
ArrayPrototypeForEach(kOptionalEnvFiles,
(file) => watcher.filterFile(resolve(file), undefined, { allowMissing: true }));
}
child.once('exit', (code) => {
exited = true;
Expand Down
10 changes: 6 additions & 4 deletions lib/internal/watch_mode/files_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ class FilesWatcher extends EventEmitter {
return [...this.#watchers.keys()];
}

watchPath(path, recursive = true, allowMissing = false) {
watchPath(path, recursive = true, options = kEmptyObject) {
if (this.#isPathWatched(path)) {
return;
}
const { allowMissing = false } = options;

const watcher = watch(path, { recursive, signal: this.#signal, throwIfNoEntry: !allowMissing });
watcher.on('change', (eventType, fileName) => {
// `fileName` can be `null` if it cannot be determined. See
Expand All @@ -126,14 +128,14 @@ class FilesWatcher extends EventEmitter {
}
}

filterFile(file, owner, allowMissing = false) {
filterFile(file, owner, options = kEmptyObject) {
if (!file) return;
if (supportsRecursiveWatching) {
this.watchPath(dirname(file),true, allowMissing);
this.watchPath(dirname(file), true, options);
} else {
// Having multiple FSWatcher's seems to be slower
// than a single recursive FSWatcher
this.watchPath(file, false, allowMissing);
this.watchPath(file, false, options);
}
this.#filteredFiles.add(file);
if (owner) {
Expand Down
Loading