Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d3e0229

Browse filesBrowse files
committed
watch: fix watch path with equals
PR-URL: #47369 Fixes: #47296 Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent a779261 commit d3e0229
Copy full SHA for d3e0229

File tree

Expand file treeCollapse file tree

2 files changed

+44
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/main/watch_mode.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/watch_mode.js
+5-2Lines changed: 5 additions & 2 deletions
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 {
@@ -36,7 +37,9 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output');
3637
const kCommand = ArrayPrototypeSlice(process.argv, 1);
3738
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
3839
const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) =>
39-
arg !== '--watch-path' && arr[i - 1] !== '--watch-path' && arg !== '--watch' && arg !== '--watch-preserve-output');
40+
!StringPrototypeStartsWith(arg, '--watch-path') &&
41+
(!arr[i - 1] || !StringPrototypeStartsWith(arr[i - 1], '--watch-path')) &&
42+
arg !== '--watch' && arg !== '--watch-preserve-output');
4043
ArrayPrototypePushApply(args, kCommand);
4144

4245
const watcher = new FilesWatcher({ throttle: 500, mode: kShouldFilterModules ? 'filter' : 'all' });
@@ -48,7 +51,7 @@ let exited;
4851

4952
function start() {
5053
exited = false;
51-
const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : undefined;
54+
const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit';
5255
child = spawn(process.execPath, args, { stdio, env: { ...process.env, WATCH_REPORT_DEPENDENCIES: '1' } });
5356
watcher.watchChildProcessModules(child);
5457
child.once('exit', (code) => {
Collapse file

‎test/sequential/test-watch-mode.mjs‎

Copy file name to clipboardExpand all lines: test/sequential/test-watch-mode.mjs
+39-1Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,23 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
137137
});
138138
});
139139

140+
it('should watch changes to a file with watch-path', {
141+
skip: !supportsRecursive,
142+
}, async () => {
143+
const file = createTmpFile();
144+
const watchedFile = fixtures.path('watch-mode/subdir/file.js');
145+
const { stderr, stdout } = await spawnWithRestarts({
146+
file,
147+
watchedFile,
148+
args: ['--watch-path', fixtures.path('./watch-mode/subdir'), file],
149+
});
150+
assert.strictEqual(stderr, '');
151+
assertRestartedCorrectly({
152+
stdout,
153+
messages: { inner: 'running', completed: `Completed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
154+
});
155+
});
156+
140157
it('should watch when running an non-existing file - when specified under --watch-path', {
141158
skip: !supportsRecursive
142159
}, async () => {
@@ -148,7 +165,28 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => {
148165
args: ['--watch-path', fixtures.path('./watch-mode/subdir/'), file],
149166
});
150167

151-
assert.strictEqual(stderr, '');
168+
assert.match(stderr, /Error: Cannot find module/);
169+
assert(stderr.match(/Error: Cannot find module/g).length >= 2);
170+
171+
assertRestartedCorrectly({
172+
stdout,
173+
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },
174+
});
175+
});
176+
177+
it('should watch when running an non-existing file - when specified under --watch-path with equals', {
178+
skip: !supportsRecursive
179+
}, async () => {
180+
const file = fixtures.path('watch-mode/subdir/non-existing.js');
181+
const watchedFile = fixtures.path('watch-mode/subdir/file.js');
182+
const { stderr, stdout } = await spawnWithRestarts({
183+
file,
184+
watchedFile,
185+
args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file],
186+
});
187+
188+
assert.match(stderr, /Error: Cannot find module/);
189+
assert(stderr.match(/Error: Cannot find module/g).length >= 2);
152190
assertRestartedCorrectly({
153191
stdout,
154192
messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.