Skip to content

Using CLI framework to replace current raw parseArgs #8410

@hyf0

Description

@hyf0

Use cac to replace current cli implementation


--moduleTypes .png=dataurl is silently ignored

Bug

--moduleTypes .png=dataurl is silently ignored — parseArgs (with strict: false) treats it as an unrecognized boolean flag and loses the value to positionals. No error or warning is shown to the user.

Root cause

packages/rolldown/src/cli/arguments/index.ts registers options in kebab-case only (e.g. module-types). parseArgs has no camelCase ↔ kebab-case awareness, so --moduleTypes is treated as an unknown flag.

Broader problem — parseArgs is too minimal

The CLI arguments module (packages/rolldown/src/cli/arguments/) is ~445 lines, of which ~330 lines are custom workarounds for features parseArgs doesn't provide:

Feature parseArgs Custom workaround
camelCase ↔ kebab-case No normalizeArgv + utils.ts (~28 lines)
--no-* boolean negation No Manual prefix stripping + inversion (~20 lines)
Object parsing (key=value,key=value) No Manual split/parse (~21 lines)
Array accumulation Basic multiple Manual push (~10 lines)
Nested option unflattening No setNestedProperty (~18 lines)
Union types No Manual handling (~8 lines)
Validation / error messages Minimal Custom validation (~50 lines)
Default values (conditional) Basic Config-driven defaults (~20 lines)
Prototype pollution guard No Manual check (~3 lines)

Each new edge case (like -- delimiter handling) adds to this maintenance surface. We're effectively building a yargs-parser from scratch on top of parseArgs.

Alternatives to consider

Library Size camelCase --no-* Objects Arrays -- Notes
ordana ~13 kB Yes Yes Custom types Yes Yes Used by Vite (PR vitejs/vite#19436). Built on parseArgs internally. TypeScript-first, auto docs generation. Strategic alignment since rolldown is Vite's future bundler.
yargs-parser ~86 kB Yes Yes Dot notation Yes Yes Battle-tested (3,733 dependents). Most feature-complete standalone parser.
citty ~24 kB Yes Yes Via config Yes Yes UnJS ecosystem (rolldown already uses consola). Zero deps, very active (v0.2.1 released Feb 2026).
commander ~40 kB Yes Yes Limited Variadic Yes Full CLI framework (114K dependents). May be heavier than needed.

Ref

Closes PR #8408 which attempted a narrow fix for the camelCase issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions