From 2d84c7b0c712631a6b16a32b6b75c6fb87847631 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Sun, 2 Apr 2023 09:30:47 +0300 Subject: [PATCH] watch: fix watch path with equals --- lib/internal/main/watch_mode.js | 5 ++++- test/sequential/test-watch-mode.mjs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index 9ef731c06f50b6..c4a130fe44bc14 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -6,6 +6,7 @@ const { ArrayPrototypeMap, ArrayPrototypePushApply, ArrayPrototypeSlice, + StringPrototypeStartsWith, } = primordials; const { @@ -38,7 +39,9 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output'); const kCommand = ArrayPrototypeSlice(process.argv, 1); const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' ')); const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) => - arg !== '--watch-path' && arr[i - 1] !== '--watch-path' && arg !== '--watch' && arg !== '--watch-preserve-output'); + !StringPrototypeStartsWith(arg, '--watch-path') && + (!arr[i - 1] || !StringPrototypeStartsWith(arr[i - 1], '--watch-path')) && + arg !== '--watch' && arg !== '--watch-preserve-output'); ArrayPrototypePushApply(args, kCommand); const watcher = new FilesWatcher({ throttle: 500, mode: kShouldFilterModules ? 'filter' : 'all' }); diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index fbfd887571e6af..fb6418d12a43d0 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -155,6 +155,24 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => { }); }); + it('should watch when running an non-existing file - when specified under --watch-path with equeals', { + skip: !supportsRecursive + }, async () => { + const file = fixtures.path('watch-mode/subdir/non-existing.js'); + const watchedFile = fixtures.path('watch-mode/subdir/file.js'); + const { stderr, stdout } = await spawnWithRestarts({ + file, + watchedFile, + args: [`--watch-path=${fixtures.path('./watch-mode/subdir/')}`, file], + }); + + assert.strictEqual(stderr, ''); + assertRestartedCorrectly({ + stdout, + messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` }, + }); + }); + it('should watch changes to a file - event loop blocked', async () => { const file = fixtures.path('watch-mode/event_loop_blocked.js'); const { stderr, stdout } = await spawnWithRestarts({