Skip to content

Commit 910d539

Browse files
committed
watch: fix watch path with equals
1 parent d8e3fca commit 910d539

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/internal/main/watch_mode.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
ArrayPrototypeMap,
77
ArrayPrototypePushApply,
88
ArrayPrototypeSlice,
9+
StringPrototypeStartsWith,
910
} = primordials;
1011

1112
const {
@@ -38,7 +39,9 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output');
3839
const kCommand = ArrayPrototypeSlice(process.argv, 1);
3940
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
4041
const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) =>
41-
arg !== '--watch-path' && arr[i - 1] !== '--watch-path' && arg !== '--watch' && arg !== '--watch-preserve-output');
42+
!StringPrototypeStartsWith(arg, '--watch-path') &&
43+
(!arr[i - 1] || !StringPrototypeStartsWith(arr[i - 1], '--watch-path')) &&
44+
arg !== '--watch' && arg !== '--watch-preserve-output');
4245
ArrayPrototypePushApply(args, kCommand);
4346

4447
const watcher = new FilesWatcher({ throttle: 500, mode: kShouldFilterModules ? 'filter' : 'all' });

test/sequential/test-watch-mode.mjs

+18
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
155155
});
156156
});
157157

158+
it('should watch when running an non-existing file - when specified under --watch-path with equeals', {
159+
skip: !supportsRecursive
160+
}, async () => {
161+
const file = fixtures.path('watch-mode/subdir/non-existing.js');
162+
const watchedFile = fixtures.path('watch-mode/subdir/file.js');
163+
const { stderr, stdout } = await spawnWithRestarts({
164+
file,
165+
watchedFile,
166+
args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file],
167+
});
168+
169+
assert.strictEqual(stderr, '');
170+
assertRestartedCorrectly({
171+
stdout,
172+
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
173+
});
174+
});
175+
158176
it('should watch changes to a file - event loop blocked', async () => {
159177
const file = fixtures.path('watch-mode/event_loop_blocked.js');
160178
const { stderr, stdout } = await spawnWithRestarts({

0 commit comments

Comments
 (0)