Skip to content

Commit 635ff26

Browse files
committed
watch: try/catch instead of existsSync
1 parent 6e0a587 commit 635ff26

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

lib/internal/main/watch_mode.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ const {
1616
} = require('internal/process/pre_execution');
1717
const {
1818
triggerUncaughtException,
19-
exitCodes: { kNoFailure },
19+
exitCodes: {kNoFailure},
2020
} = internalBinding('errors');
21-
const { getOptionValue } = require('internal/options');
22-
const { FilesWatcher } = require('internal/watch_mode/files_watcher');
23-
const { green, blue, red, white, clear } = require('internal/util/colors');
24-
const { convertToValidSignal } = require('internal/util');
25-
26-
const { spawn } = require('child_process');
27-
const { existsSync } = require('fs');
28-
const { inspect } = require('util');
29-
const { setTimeout, clearTimeout } = require('timers');
30-
const { resolve } = require('path');
31-
const { once } = require('events');
21+
const {getOptionValue} = require('internal/options');
22+
const {FilesWatcher} = require('internal/watch_mode/files_watcher');
23+
const {green, blue, red, white, clear} = require('internal/util/colors');
24+
const {convertToValidSignal} = require('internal/util');
25+
26+
const {spawn} = require('child_process');
27+
const {inspect} = require('util');
28+
const {setTimeout, clearTimeout} = require('timers');
29+
const {resolve} = require('path');
30+
const {once} = require('events');
3231

3332
prepareMainThreadExecution(false, false);
3433
markBootstrapComplete();
@@ -83,7 +82,7 @@ for (let i = 0; i < process.execArgv.length; i++) {
8382

8483
ArrayPrototypePushApply(argsWithoutWatchOptions, kCommand);
8584

86-
const watcher = new FilesWatcher({ debounce: 200, mode: kShouldFilterModules ? 'filter' : 'all' });
85+
const watcher = new FilesWatcher({debounce: 200, mode: kShouldFilterModules ? 'filter' : 'all'});
8786
ArrayPrototypeForEach(kWatchedPaths, (p) => watcher.watchPath(p));
8887

8988
let graceTimer;
@@ -106,9 +105,13 @@ function start() {
106105
}
107106
if (kOptionalEnvFiles.length > 0) {
108107
ArrayPrototypeForEach(kOptionalEnvFiles, (file) => {
109-
const resolvedPath = resolve(file);
110-
if (existsSync(resolvedPath)) {
111-
watcher.filterFile(resolvedPath);
108+
try {
109+
watcher.filterFile(resolve(file));
110+
} catch (error) {
111+
if (error?.code !== 'ENOENT' && error?.code !== 'ENOTDIR') {
112+
throw error;
113+
}
114+
// Failed watching the file, ignore
112115
}
113116
});
114117
}
@@ -134,7 +137,7 @@ async function killAndWait(signal = kKillSignal, force = false) {
134137
}
135138
const onExit = once(child, 'exit');
136139
child.kill(signal);
137-
const { 0: exitCode } = await onExit;
140+
const {0: exitCode} = await onExit;
138141
return exitCode;
139142
}
140143

@@ -167,6 +170,7 @@ async function stop(child) {
167170
}
168171

169172
let restarting = false;
173+
170174
async function restart(child) {
171175
if (restarting) return;
172176
restarting = true;
@@ -205,5 +209,6 @@ function signalHandler(signal) {
205209
process.exit(exitCode ?? kNoFailure);
206210
};
207211
}
212+
208213
process.on('SIGTERM', signalHandler('SIGTERM'));
209214
process.on('SIGINT', signalHandler('SIGINT'));

0 commit comments

Comments
 (0)