GeezerVison is showing github.com — watch: fix watch path with equals · nodejs/node@75669e9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/watch_mode.js +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | ArrayPrototypeMap, | 7 | 7 | ArrayPrototypePushApply, | 8 | 8 | ArrayPrototypeSlice, | | 9 | + StringPrototypeStartsWith, | 9 | 10 | } = primordials; | 10 | 11 |
| 11 | 12 | const { | @@ -38,7 +39,9 @@ const kPreserveOutput = getOptionValue('--watch-preserve-output'); | 38 | 39 | const kCommand = ArrayPrototypeSlice(process.argv, 1); | 39 | 40 | const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' ')); | 40 | 41 | 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'); | 42 | 45 | ArrayPrototypePushApply(args, kCommand); | 43 | 46 |
| 44 | 47 | const watcher = new FilesWatcher({ throttle: 500, mode: kShouldFilterModules ? 'filter' : 'all' }); | @@ -50,7 +53,7 @@ let exited; | 50 | 53 |
| 51 | 54 | function start() { | 52 | 55 | exited = false; | 53 | | - const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : undefined; | | 56 | + const stdio = kShouldFilterModules ? ['inherit', 'inherit', 'inherit', 'ipc'] : 'inherit'; | 54 | 57 | child = spawn(process.execPath, args, { stdio, env: { ...process.env, WATCH_REPORT_DEPENDENCIES: '1' } }); | 55 | 58 | watcher.watchChildProcessModules(child); | 56 | 59 | child.once('exit', (code) => { | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-watch-mode.mjs +39-1Lines changed: 39 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -137,6 +137,23 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => { | 137 | 137 | }); | 138 | 138 | }); | 139 | 139 |
| | 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 | + | 140 | 157 | it('should watch when running an non-existing file - when specified under --watch-path', { | 141 | 158 | skip: !supportsRecursive | 142 | 159 | }, async () => { | @@ -148,7 +165,28 @@ describe('watch mode', { concurrency: false, timeout: 60_000 }, () => { | 148 | 165 | args: ['--watch-path', fixtures.path('./watch-mode/subdir/'), file], | 149 | 166 | }); | 150 | 167 |
| 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); | 152 | 190 | assertRestartedCorrectly({ | 153 | 191 | stdout, | 154 | 192 | messages: { completed: `Failed running ${inspect(file)}`, restarted: `Restarting ${inspect(file)}` }, | |
|