Skip to content

Commit 3f567d4

Browse files
committed
feat: make options an object
1 parent e485116 commit 3f567d4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/internal/fs/recursive_watch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class FSWatcher extends EventEmitter {
5151

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

54-
let { persistent, recursive, signal, encoding, ignore, throwIfNoEntry } = options;
54+
const { persistent, recursive, signal, encoding, ignore } = options;
55+
let { throwIfNoEntry } = options;
5556

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

6970
if (throwIfNoEntry != null) {
7071
validateBoolean(throwIfNoEntry, 'options.throwIfNoEntry');
71-
} else {
72+
} else {
7273
throwIfNoEntry = true;
7374
}
7475

@@ -228,7 +229,7 @@ class FSWatcher extends EventEmitter {
228229
this.#watchFolder(filename);
229230
}
230231
} catch (error) {
231-
if (!this.#options.throwIfNoEntry && error.code === 'ENOENT') {
232+
if (this.#options.throwIfNoEntry !== false && error.code === 'ENOENT') {
232233
error.filename = filename;
233234
throw error;
234235
}

lib/internal/main/watch_mode.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ function start() {
104104
ArrayPrototypeForEach(kEnvFiles, (file) => watcher.filterFile(resolve(file)));
105105
}
106106
if (kOptionalEnvFiles.length > 0) {
107-
ArrayPrototypeForEach(kOptionalEnvFiles, (file) => watcher.filterFile(resolve(file), undefined, true));
107+
ArrayPrototypeForEach(kOptionalEnvFiles,
108+
(file) => watcher.filterFile(resolve(file), undefined, { allowMissing: true }));
108109
}
109110
child.once('exit', (code) => {
110111
exited = true;

lib/internal/watch_mode/files_watcher.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ class FilesWatcher extends EventEmitter {
110110
return [...this.#watchers.keys()];
111111
}
112112

113-
watchPath(path, recursive = true, allowMissing = false) {
113+
watchPath(path, recursive = true, options = kEmptyObject) {
114114
if (this.#isPathWatched(path)) {
115115
return;
116116
}
117+
const { allowMissing = false } = options;
118+
117119
const watcher = watch(path, { recursive, signal: this.#signal, throwIfNoEntry: !allowMissing });
118120
watcher.on('change', (eventType, fileName) => {
119121
// `fileName` can be `null` if it cannot be determined. See
@@ -126,14 +128,14 @@ class FilesWatcher extends EventEmitter {
126128
}
127129
}
128130

129-
filterFile(file, owner, allowMissing = false) {
131+
filterFile(file, owner, options = kEmptyObject) {
130132
if (!file) return;
131133
if (supportsRecursiveWatching) {
132-
this.watchPath(dirname(file),true, allowMissing);
134+
this.watchPath(dirname(file), true, options);
133135
} else {
134136
// Having multiple FSWatcher's seems to be slower
135137
// than a single recursive FSWatcher
136-
this.watchPath(file, false, allowMissing);
138+
this.watchPath(file, false, options);
137139
}
138140
this.#filteredFiles.add(file);
139141
if (owner) {

0 commit comments

Comments
 (0)