Skip to content

Commit 1c4d92c

Browse files
committed
watch: fix watch path with equals
1 parent 85705a4 commit 1c4d92c

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/internal/main/watch_mode.js

+5-2
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' });
@@ -50,7 +53,7 @@ let exited;
5053

5154
function start() {
5255
exited = false;
53-
const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : undefined;
56+
const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit';
5457
child = spawn(process.execPath, args, { stdio, env: { ...process.env, WATCH_REPORT_DEPENDENCIES: '1' } });
5558
watcher.watchChildProcessModules(child);
5659
child.once('exit', (code) => {

test/sequential/test-watch-mode.mjs

+22-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,28 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
148148
args: ['--watch-path', fixtures.path('./watch-mode/subdir/'), file],
149149
});
150150

151-
assert.strictEqual(stderr, '');
151+
assert.match(stderr, /Error: Cannot find module/);
152+
assert(stderr.match(/Error: Cannot find module/g).length >= 2);
153+
154+
assertRestartedCorrectly({
155+
stdout,
156+
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
157+
});
158+
});
159+
160+
it('should watch when running an non-existing file - when specified under --watch-path with equals', {
161+
skip: !supportsRecursive
162+
}, async () => {
163+
const file = fixtures.path('watch-mode/subdir/non-existing.js');
164+
const watchedFile = fixtures.path('watch-mode/subdir/file.js');
165+
const { stderr, stdout } = await spawnWithRestarts({
166+
file,
167+
watchedFile,
168+
args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file],
169+
});
170+
171+
assert.match(stderr, /Error: Cannot find module/);
172+
assert(stderr.match(/Error: Cannot find module/g).length >= 2);
152173
assertRestartedCorrectly({
153174
stdout,
154175
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },

0 commit comments

Comments
 (0)