From c1335e516ecb3089121cc4c0ada7a71463a276f9 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 30 Apr 2024 18:14:21 +0300 Subject: [PATCH 1/6] watch: fix arguments parsing --- lib/internal/main/watch_mode.js | 7 ++++--- test/sequential/test-watch-mode.mjs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index c594f64bfca87d..e96faa3ea64eb7 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -6,7 +6,6 @@ const { ArrayPrototypePush, ArrayPrototypePushApply, ArrayPrototypeSlice, - StringPrototypeIncludes, StringPrototypeStartsWith, } = primordials; @@ -44,8 +43,10 @@ const argsWithoutWatchOptions = []; for (let i = 0; i < process.execArgv.length; i++) { const arg = process.execArgv[i]; if (StringPrototypeStartsWith(arg, '--watch')) { - if (!StringPrototypeIncludes(arg, '=')) { - i++; + i++; + const nextArg = process.execArgv[i]; + if (nextArg && StringPrototypeStartsWith(nextArg, '--')) { + ArrayPrototypePush(argsWithoutWatchOptions, nextArg); } continue; } diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index cc8c56d67ec77e..0c7fc361fb2e56 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -531,4 +531,20 @@ console.log(values.random); `Completed running ${inspect(file)}`, ]); }); + + + it('should run when `--watch --inspect`', async () => { + const file = createTmpFile(); + const args = ['--inspect', file]; + const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, args }); + + assert.match(stderr, /listening on ws:\/\//); + assert.deepStrictEqual(stdout, [ + 'running', + `Completed running ${inspect(file)}`, + `Restarting ${inspect(file)}`, + 'running', + `Completed running ${inspect(file)}`, + ]); + }); }); From 036887ef9729999ade1d7e8afe52e46be8a003c4 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 30 Apr 2024 18:34:50 +0300 Subject: [PATCH 2/6] CR --- lib/internal/main/watch_mode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/main/watch_mode.js b/lib/internal/main/watch_mode.js index e96faa3ea64eb7..4381cf0d381461 100644 --- a/lib/internal/main/watch_mode.js +++ b/lib/internal/main/watch_mode.js @@ -45,7 +45,7 @@ for (let i = 0; i < process.execArgv.length; i++) { if (StringPrototypeStartsWith(arg, '--watch')) { i++; const nextArg = process.execArgv[i]; - if (nextArg && StringPrototypeStartsWith(nextArg, '--')) { + if (nextArg && StringPrototypeStartsWith(nextArg, '-')) { ArrayPrototypePush(argsWithoutWatchOptions, nextArg); } continue; From 6bc37789decc1a38ea188b3749625be00a627d57 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 30 Apr 2024 19:28:05 +0300 Subject: [PATCH 3/6] fix test --- test/sequential/test-watch-mode.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index 0c7fc361fb2e56..bb041426d4556f 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -535,8 +535,8 @@ console.log(values.random); it('should run when `--watch --inspect`', async () => { const file = createTmpFile(); - const args = ['--inspect', file]; - const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, args }); + const args = ['--watch', '--inspect', file]; + const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: '', args }); assert.match(stderr, /listening on ws:\/\//); assert.deepStrictEqual(stdout, [ From 96df0502bd4ef76a3e4ff383534a7c572dd82756 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Tue, 30 Apr 2024 19:31:25 +0300 Subject: [PATCH 4/6] fix test --- test/sequential/test-watch-mode.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index bb041426d4556f..d778f614a4064d 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -39,7 +39,9 @@ async function runWriteSucceed({ options = {}, shouldFail = false }) { - const child = spawn(execPath, [watchFlag, '--no-warnings', ...args], { encoding: 'utf8', stdio: 'pipe', ...options }); + args.unshift('--no-warnings'); + if (watchFlag !== null) args.unshift(watchFlag); + const child = spawn(execPath, args, { encoding: 'utf8', stdio: 'pipe', ...options }); let completes = 0; let cancelRestarts = () => {}; let stderr = ''; @@ -536,7 +538,7 @@ console.log(values.random); it('should run when `--watch --inspect`', async () => { const file = createTmpFile(); const args = ['--watch', '--inspect', file]; - const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: '', args }); + const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: null, args }); assert.match(stderr, /listening on ws:\/\//); assert.deepStrictEqual(stdout, [ From 786bd914d2dc91ff4bc39bbfdf588027c7be6d17 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Wed, 1 May 2024 13:17:19 +0300 Subject: [PATCH 5/6] CR --- test/sequential/test-watch-mode.mjs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index d778f614a4064d..d4c6d3900db6fd 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -534,7 +534,6 @@ console.log(values.random); ]); }); - it('should run when `--watch --inspect`', async () => { const file = createTmpFile(); const args = ['--watch', '--inspect', file]; @@ -549,4 +548,30 @@ console.log(values.random); `Completed running ${inspect(file)}`, ]); }); + + it('should run when `--watch -r=./foo.js`', async () => { + const projectDir = tmpdir.resolve('project7'); + mkdirSync(projectDir); + + const dir = path.join(projectDir, 'watched-dir'); + mkdirSync(dir); + writeFileSync(path.join(projectDir, 'some.js'), "console.log('hello')"); + + const file = createTmpFile("console.log('running');", '.js', projectDir); + const args = ['--watch', '-r', './some.js', file]; + const { stdout, stderr } = await runWriteSucceed({ + file, watchedFile: file, watchFlag: null, args, options: { cwd: projectDir } + }); + + assert.strictEqual(stderr, ''); + assert.deepStrictEqual(stdout, [ + 'hello', + 'running', + `Completed running ${inspect(file)}`, + `Restarting ${inspect(file)}`, + 'hello', + 'running', + `Completed running ${inspect(file)}`, + ]); + }); }); From 4a23ab6af99ef47255f1d59bd89df873b8cb6704 Mon Sep 17 00:00:00 2001 From: Moshe Atlow Date: Wed, 1 May 2024 14:16:05 +0300 Subject: [PATCH 6/6] CR --- test/sequential/test-watch-mode.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-watch-mode.mjs b/test/sequential/test-watch-mode.mjs index d4c6d3900db6fd..8bf0bdff7899d2 100644 --- a/test/sequential/test-watch-mode.mjs +++ b/test/sequential/test-watch-mode.mjs @@ -549,7 +549,7 @@ console.log(values.random); ]); }); - it('should run when `--watch -r=./foo.js`', async () => { + it('should run when `--watch -r ./foo.js`', async () => { const projectDir = tmpdir.resolve('project7'); mkdirSync(projectDir);