Build: replace yargs with node:util parseArgs (preserve --no-lint-warnings) - #15473
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9987bebd74
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Barecheck - Code coverage reportTotal: 91.29%Your code coverage diff: 0.00% ▴ ✅ All code changes are covered |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8cc07c79c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (option) { | ||
| argv[option] = false; | ||
| delete argv[arg]; |
There was a problem hiding this comment.
Preserve the last boolean flag's value
When a command supplies both forms of a flag, such as --no-coverage --coverage, parseArgs stores them under separate keys while preserving the first insertion position; this post-processing therefore writes coverage = false regardless of which form appeared last. That breaks the usual last-option-wins behavior and prevents a caller from overriding an earlier wrapper/default flag, so the normalization needs to account for original token order rather than iterating the collapsed values object.
Useful? React with 👍 / 👎.
yargs mapped --no-foo to foo=false for both the camelCase and kebab-case spellings of foo, and let the last occurrence of a flag win. The previous normalization only matched the kebab-case spelling (so --no-sourceMaps silently no-opped) and always applied the negation regardless of a later positive flag. Replay parseArgs option tokens in order instead, which restores both behaviors, and describe the mechanism in the comment. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Negation matching was case- and hyphen-insensitive while positive flags matched exactly, so misspellings like --no-COVERAGE toggled real options that yargs left as unread literal keys. Match each boolean option's two accepted spellings (camelCase and kebab-case) exactly instead, and state in the comment that positive flags are recognized only under their declared names. Add a build-logic spec that spawns node per case, since the parse happens at module load. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
yargs let the last occurrence of a flag win even when it carried an explicit value (--no-fetch --fetch=1 gave fetch=1); the replay skipped valued tokens entirely, so a negation could never be overridden by the =value form. Replay valued occurrences of declared boolean flags too, assigning the value parseArgs recorded. parseArgs' own allowNegative option is deliberately not used: it landed in Node 20.16 while package.json supports >=20.0 (where the unknown key is silently ignored, turning negation off with no error), and it does not cover the kebab-case spellings. Export BOOLEAN_OPTIONS so the spec can sweep every declared boolean in both negation spellings; also pin the valued-override ordering, the mixed-spelling outcome, and flags following a task word. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The kebab-case negation spelling is this code's uniform rule — for ES5, yargs's own camelization mapped --no-es5 to an unread es5 key — and nolint/ES5 are declared names, not camelCase renderings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Accepting --no-source-maps while ignoring --source-maps was an asymmetry with silent failures: the positive kebab spelling left the declared option undefined, so a build asked for source maps shipped without them, and a line like --no-source-maps --source-maps kept contradictory keys where yargs gave the later positive form the win. Fold both polarities of both spellings into one token-replay table: each declared boolean is recognized under its declared name and its kebab-case form, negated or not, last occurrence winning. String options and undeclared flags are still left exactly as parseArgs parsed them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
For repeated valued occurrences of one flag yargs collected an array rather than taking the last value, so unconditional last-wins is this replay's rule, not restored yargs behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This PR introduces changes that may not work on all browsers. According to Babel, the following polyfills may be needed, and they are not automatically included:
The best way to address this is to provide good test coverage, as normal PR checks run unit tests on older browsers. |
Picking up from @derdeka draft #15150
Motivation
yargsdev-dependency in favor of Node.jsutil.parseArgsnow available on Node ≥20.argvsource.--no-lint-warningsbehavior sogulp lint --no-lint-warningscontinues to map toargv.lintWarnings === false.Description
require('yargs').argvusages with a sharedargvproduced byparseArgsingulpHelpers.jsand consumed bygulpfile.js,gulp.precompilation.js, andwebpack.conf.js.parseArgsschema ingulpHelpers.jsand export the parsedargvobject for reuse across build scripts.--no-lint-warningskey intoargv.lintWarnings = falseingulpHelpers.js.test/fake-server/bundle.jsandtest/fake-server/index.jstoutil.parseArgs.yargsfrompackage.jsonand updatepackage-lock.jsonso the repository no longer depends onyargs.Testing
npx eslint test/fake-server/bundle.js test/fake-server/index.js --cache --cache-strategy content— PASS.node --checkagainst modified files (gulpHelpers.js,gulpfile.js,gulp.precompilation.js,webpack.conf.js,test/fake-server/bundle.js,test/fake-server/index.js) — PASS.node -e "const {argv} = require('./gulpHelpers.js'); ..." -- --no-lint-warningsand--nolint --file foo.js --modules a,b --ES5 --polyfills— PASS for preserved--no-lint-warningsbehavior and general flag parsing.yargsusage (rgsearch) and package-lock consistency — PASS (no directyargsimports remain and lockfile updated).gulp lint --no-lint-warnings --nolintfixwas exercised to confirm the--quietpath but the run failed on a pre-existing lint error (unusedConsentHandlerinlibraries/consentManagement/cmUtils.ts), which is unrelated to these changes and reported as a warning in this PR.Codex Task