mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
watch: fix arguments parsing
PR-URL: https://github.com/nodejs/node/pull/52760 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
This commit is contained in:
1 parent
5161d95c30
commit
739adf90b1
2 files changed
+48
-4
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 = '';
|
||||
@@ -531,4 +533,45 @@ console.log(values.random);
|
||||
`Completed running ${inspect(file)}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('should run when `--watch --inspect`', async () => {
|
||||
const file = createTmpFile();
|
||||
const args = ['--watch', '--inspect', file];
|
||||
const { stdout, stderr } = await runWriteSucceed({ file, watchedFile: file, watchFlag: null, args });
|
||||
|
||||
assert.match(stderr, /listening on ws:\/\//);
|
||||
assert.deepStrictEqual(stdout, [
|
||||
'running',
|
||||
`Completed running ${inspect(file)}`,
|
||||
`Restarting ${inspect(file)}`,
|
||||
'running',
|
||||
`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)}`,
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user