fix(cli): add normalization for camelCase long options in CLI arguments#8408
fix(cli): add normalization for camelCase long options in CLI arguments#8408
Conversation
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
✅ Deploy Preview for rolldown-rs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR improves the rolldown CLI argument parser by normalizing camelCase long options (e.g. --moduleTypes) into the canonical kebab-case form (e.g. --module-types) so they’re recognized consistently.
Changes:
- Add an argv preprocessing step to convert camelCase
--longOptionsinto kebab-case beforenode:util.parseArgsruns. - Add an e2e CLI test exercising camelCase object option parsing (
--moduleTypes) and update snapshots accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/rolldown/src/cli/arguments/index.ts | Adds normalizeArgv and routes CLI args through it before parsing. |
| packages/rolldown/tests/cli/cli-e2e.test.ts | Adds an e2e test covering --moduleTypes for object option parsing. |
| packages/rolldown/tests/cli/snapshots/cli-e2e.test.ts.snap | Adds snapshot output for the new e2e test. |
| return argv.map((arg) => { | ||
| // Only process long options (--option or --option=value) | ||
| if (!arg.startsWith('--')) return arg; | ||
| const eqIndex = arg.indexOf('=', 2); | ||
| if (eqIndex === -1) { | ||
| // --optionName → --option-name | ||
| return `--${camelCaseToKebabCase(arg.slice(2))}`; | ||
| } | ||
| // --optionName=value → --option-name=value | ||
| const name = arg.slice(2, eqIndex); | ||
| const value = arg.slice(eqIndex); | ||
| return `--${camelCaseToKebabCase(name)}${value}`; | ||
| }); |
There was a problem hiding this comment.
normalizeArgv rewrites every --* token even after the -- end-of-options marker. That changes the contents of positional arguments that intentionally start with -- (e.g. rolldown -- --fooBar), which should be passed through verbatim. Consider switching to an index-based loop that stops normalizing once -- is encountered (or explicitly skips normalization for args after it).
| return argv.map((arg) => { | |
| // Only process long options (--option or --option=value) | |
| if (!arg.startsWith('--')) return arg; | |
| const eqIndex = arg.indexOf('=', 2); | |
| if (eqIndex === -1) { | |
| // --optionName → --option-name | |
| return `--${camelCaseToKebabCase(arg.slice(2))}`; | |
| } | |
| // --optionName=value → --option-name=value | |
| const name = arg.slice(2, eqIndex); | |
| const value = arg.slice(eqIndex); | |
| return `--${camelCaseToKebabCase(name)}${value}`; | |
| }); | |
| const normalized: string[] = []; | |
| let seenEndOfOptions = false; | |
| for (const arg of argv) { | |
| if (seenEndOfOptions) { | |
| normalized.push(arg); | |
| continue; | |
| } | |
| if (arg === '--') { | |
| seenEndOfOptions = true; | |
| normalized.push(arg); | |
| continue; | |
| } | |
| // Only process long options (--option or --option=value) | |
| if (!arg.startsWith('--')) { | |
| normalized.push(arg); | |
| continue; | |
| } | |
| const eqIndex = arg.indexOf('=', 2); | |
| if (eqIndex === -1) { | |
| // --optionName → --option-name | |
| normalized.push(`--${camelCaseToKebabCase(arg.slice(2))}`); | |
| continue; | |
| } | |
| // --optionName=value → --option-name=value | |
| const name = arg.slice(2, eqIndex); | |
| const value = arg.slice(eqIndex); | |
| normalized.push(`--${camelCaseToKebabCase(name)}${value}`); | |
| } | |
| return normalized; |
363e90e to
c23a082
Compare

No description provided.