GeezerVison is showing github.com — watch: fix arguments parsing · nodejs/node@f5d9257
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 +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 6 | 6 | ArrayPrototypePush, | 7 | 7 | ArrayPrototypePushApply, | 8 | 8 | ArrayPrototypeSlice, | 9 | | - StringPrototypeIncludes, | 10 | 9 | StringPrototypeStartsWith, | 11 | 10 | } = primordials; | 12 | 11 |
| @@ -44,8 +43,10 @@ const argsWithoutWatchOptions = []; | 44 | 43 | for (let i = 0; i < process.execArgv.length; i++) { | 45 | 44 | const arg = process.execArgv[i]; | 46 | 45 | if (StringPrototypeStartsWith(arg, '--watch')) { | 47 | | - if (!StringPrototypeIncludes(arg, '=')) { | 48 | | - i++; | | 46 | + i++; | | 47 | + const nextArg = process.execArgv[i]; | | 48 | + if (nextArg && StringPrototypeStartsWith(nextArg, '-')) { | | 49 | + ArrayPrototypePush(argsWithoutWatchOptions, nextArg); | 49 | 50 | } | 50 | 51 | continue; | 51 | 52 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/sequential/test-watch-mode.mjs +44-1Lines changed: 44 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,9 @@ async function runWriteSucceed({ | 39 | 39 | options = {}, | 40 | 40 | shouldFail = false | 41 | 41 | }) { | 42 | | - const child = spawn(execPath, [watchFlag, '--no-warnings', ...args], { encoding: 'utf8', stdio: 'pipe', ...options }); | | 42 | + args.unshift('--no-warnings'); | | 43 | + if (watchFlag !== null) args.unshift(watchFlag); | | 44 | + const child = spawn(execPath, args, { encoding: 'utf8', stdio: 'pipe', ...options }); | 43 | 45 | let completes = 0; | 44 | 46 | let cancelRestarts = () => {}; | 45 | 47 | let stderr = ''; | @@ -531,4 +533,45 @@ console.log(values.random); | 531 | 533 | `Completed running ${inspect(file)}`, | 532 | 534 | ]); | 533 | 535 | }); | | 536 | + | | 537 | + it('should run when `--watch --inspect`', async () => { | | 538 | + const file = createTmpFile(); | | 539 | + const args = ['--watch', '--inspect', file]; | | 540 | + const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: null, args }); | | 541 | + | | 542 | + assert.match(stderr, /listening on ws:\/\//); | | 543 | + assert.deepStrictEqual(stdout, [ | | 544 | + 'running', | | 545 | + `Completed running ${inspect(file)}`, | | 546 | + `Restarting ${inspect(file)}`, | | 547 | + 'running', | | 548 | + `Completed running ${inspect(file)}`, | | 549 | + ]); | | 550 | + }); | | 551 | + | | 552 | + it('should run when `--watch -r ./foo.js`', async () => { | | 553 | + const projectDir = tmpdir.resolve('project7'); | | 554 | + mkdirSync(projectDir); | | 555 | + | | 556 | + const dir = path.join(projectDir, 'watched-dir'); | | 557 | + mkdirSync(dir); | | 558 | + writeFileSync(path.join(projectDir, 'some.js'), "console.log('hello')"); | | 559 | + | | 560 | + const file = createTmpFile("console.log('running');", '.js', projectDir); | | 561 | + const args = ['--watch', '-r', './some.js', file]; | | 562 | + const { stdout, stderr } = await runWriteSucceed({ | | 563 | + file, watchedFile: file, watchFlag: null, args, options: { cwd: projectDir } | | 564 | + }); | | 565 | + | | 566 | + assert.strictEqual(stderr, ''); | | 567 | + assert.deepStrictEqual(stdout, [ | | 568 | + 'hello', | | 569 | + 'running', | | 570 | + `Completed running ${inspect(file)}`, | | 571 | + `Restarting ${inspect(file)}`, | | 572 | + 'hello', | | 573 | + 'running', | | 574 | + `Completed running ${inspect(file)}`, | | 575 | + ]); | | 576 | + }); | 534 | 577 | }); |
|