refactor(cli): parse JS command arguments with clap - #2523
Draft
fengmk2 wants to merge 17 commits into
Draft
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
fengmk2
force-pushed
the
rfc/napi-clap-cli-args
branch
from
August 21, 2026 13:01
c616858 to
86300af
Compare
Contributor
CLI artifact sizes (
|
| Artifact | Format | Base | PR | Change |
|---|---|---|---|---|
packages/cli/dist |
Directory total | 1.61 MiB | 1.59 MiB | -18.84 KiB (-1.14%) |
packages/core/dist |
Directory total | 3.91 MiB | 3.91 MiB | 0 B (0.00%) |
| Combined package dist | Directory total | 5.52 MiB | 5.50 MiB | -18.84 KiB (-0.33%) |
vp (Linux x64) |
Binary | 10.74 MiB | 10.74 MiB | +8.00 KiB (+0.07%) |
vp (Linux x64) |
gzip -9 | 4.65 MiB | 4.65 MiB | +5.46 KiB (+0.11%) |
| NAPI (Linux x64) | Binary | 32.20 MiB | 32.39 MiB | +188.00 KiB (+0.57%) |
| NAPI (Linux x64) | gzip -9 | 12.69 MiB | 12.76 MiB | +68.63 KiB (+0.53%) |
vp (macOS ARM64) |
Binary | 8.03 MiB | 8.03 MiB | +16 B (+0.00%) |
vp (macOS ARM64) |
gzip -9 | 4.05 MiB | 4.06 MiB | +4.81 KiB (+0.12%) |
| NAPI (macOS ARM64) | Binary | 39.80 MiB | 39.93 MiB | +129.14 KiB (+0.32%) |
| NAPI (macOS ARM64) | gzip -9 | 16.98 MiB | 17.05 MiB | +67.52 KiB (+0.39%) |
vp (Windows x64) |
Binary | 8.63 MiB | 8.64 MiB | +7.50 KiB (+0.08%) |
vp (Windows x64) |
gzip -9 | 3.77 MiB | 3.77 MiB | +4.91 KiB (+0.13%) |
| NAPI (Windows x64) | Binary | 27.03 MiB | 27.20 MiB | +172.50 KiB (+0.62%) |
| NAPI (Windows x64) | gzip -9 | 10.75 MiB | 10.82 MiB | +66.38 KiB (+0.60%) |
| Trampoline (Windows x64) | Binary | 214.00 KiB | 214.00 KiB | 0 B (0.00%) |
| Trampoline (Windows x64) | gzip -9 | 103.20 KiB | 103.20 KiB | 0 B (0.00%) |
| Installer (Windows x64) | Binary | 4.50 MiB | 4.50 MiB | 0 B (0.00%) |
| Installer (Windows x64) | gzip -9 | 2.11 MiB | 2.11 MiB | 0 B (0.00%) |
fengmk2
force-pushed
the
rfc/napi-clap-cli-args
branch
2 times, most recently
from
August 22, 2026 16:38
e9e7cdf to
7753568
Compare
fengmk2
force-pushed
the
rfc/napi-clap-cli-args
branch
from
August 23, 2026 05:28
7753568 to
6ea10b8
Compare
fengmk2
commented
Aug 23, 2026
| packages/cli/binding/src/js_command_args/ | ||
| mod.rs | ||
| parse.rs | ||
| create.rs |
Member
Author
There was a problem hiding this comment.
Should command implementation code be placed in a separate directory for better management?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move argument parsing for the staged, config, hooks, migrate, and create commands from JavaScript to Rust. Each NAPI parser uses clap for strict validation and returns a typed result to JavaScript.
Call graph
JavaScript sends raw arguments to one NAPI parser. JavaScript does not parse the returned values again.
The Rust parsers print command help through the shared vp_cli_help formatter. The global and local CLI paths use the same help format. The create parser keeps all template arguments after the separator in their original order.
This change removes duplicate JavaScript option data and the direct mri dependency. The RFC defines the parser rules, help synchronization, NAPI result types, and command ownership.
Compatibility
Argument parsing is now strict. The CLI rejects unknown options and extra positional arguments. It rejects unsupported negative string options and repeated scalar options.
The staged command rejects invalid concurrency values. It also rejects empty
--cwd,--diff, and--diff-filtervalues before JavaScript runs.The create command rejects
--alland invalid package-manager values. These inputs could pass throughmrior fail later in JavaScript.Performance
The benchmark compares the base commit
45acff9b4with this branch. It ran on macOS ARM64 with Node.js 22.22.0.Each CLI result used 25 to 30 alternating paired runs after four warm-up pairs. A negative change is faster.
The parser-only test used
vp staged --allow-empty --concurrent=2 --diff-filter ACMR --no-stash.vp --versioncontrolvp staged --helpvp config --helpvp hooks --helpvp migrate --helpvp create --helpvp staged --cwdvp hooks unknownvp config --hooks-dirThe clap/NAPI parser is 5.3 times slower in isolation. This adds about 5 µs to a CLI process that takes 130 to 155 ms.
The CLI calls the parser one time. The complete CLI path has no measurable regression. Help is 1% to 4% faster.
vp config --hooks-diris not a parser-only comparison. The base command starts hooks validation. The PR rejects the missing value first.Unknown-option timings are not comparable. The base parser can accept an unknown option and start command work. The PR rejects it during parsing.