-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
watch: fix watch args not being properly filtered #57936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -791,4 +791,54 @@ process.on('message', (message) => { | |
`Completed running ${inspect(file)}`, | ||
]); | ||
}); | ||
|
||
it('when multiple `--watch` flags are provided should run as if only one was', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure if it's this PR, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thank you very much and sorry for the trouble, I will keep this in mind and create tests in new files whenever possible 🙇 |
||
const projectDir = tmpdir.resolve('project-multi-flag'); | ||
mkdirSync(projectDir); | ||
|
||
const file = createTmpFile(` | ||
console.log( | ||
process.argv.some(arg => arg === '--watch') | ||
? 'Error: unexpected --watch args present' | ||
: 'no --watch args present' | ||
);`, '.js', projectDir); | ||
const args = ['--watch', '--watch', file]; | ||
const { stdout, stderr } = await runWriteSucceed({ | ||
file, watchedFile: file, watchFlag: null, args, options: { cwd: projectDir } | ||
}); | ||
|
||
assert.strictEqual(stderr, ''); | ||
assert.deepStrictEqual(stdout, [ | ||
'no --watch args present', | ||
`Completed running ${inspect(file)}`, | ||
`Restarting ${inspect(file)}`, | ||
'no --watch args present', | ||
`Completed running ${inspect(file)}`, | ||
]); | ||
}); | ||
|
||
it('`--watch-path` ars without `=` used alongside `--watch` should not make it into the script', async () => { | ||
const projectDir = tmpdir.resolve('project-watch-watch-path-args'); | ||
mkdirSync(projectDir); | ||
|
||
const file = createTmpFile(` | ||
console.log( | ||
process.argv.slice(2).some(arg => arg.endsWith('.js')) | ||
? 'some cli args end with .js' | ||
: 'no cli arg ends with .js' | ||
);`, '.js', projectDir); | ||
const args = ['--watch', `--watch-path`, file, file]; | ||
const { stdout, stderr } = await runWriteSucceed({ | ||
file, watchedFile: file, watchFlag: null, args, options: { cwd: projectDir } | ||
}); | ||
|
||
assert.strictEqual(stderr, ''); | ||
assert.deepStrictEqual(stdout, [ | ||
'no cli arg ends with .js', | ||
`Completed running ${inspect(file)}`, | ||
`Restarting ${inspect(file)}`, | ||
'no cli arg ends with .js', | ||
`Completed running ${inspect(file)}`, | ||
]); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: maybe node should error if multiple
--watch
flags are provided?I did not go with such a solution because that would be a breaking change, just ignoring extra
--watch
flags is a non breaking change and it solves the issue at handIf someone believes that multiple
--watch
flags should cause an error I would propose to first land this change right now as a patch then as a followup I can also add the stricter validation which will be included as a breaking change in the next major 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And/or maybe, the erroring when multiple
--watch
flags are provided is part of the bigger issues of node being quite permissive with its cli flags: #57864 and could be addressed as part of that 🤔