Skip to content

Commit a7115be

Browse files
authored
Merge branch 'main' into fix/multichoice-hint
2 parents 5365e20 + f98a237 commit a7115be

File tree

4 files changed

+97
-35
lines changed

4 files changed

+97
-35
lines changed

crates/vite_global_cli/src/help.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn documentation_url_for_command_path(command_path: &[&str]) -> Option<&'static
6565
["config"] | ["staged"] => Some("https://viteplus.dev/guide/commit-hooks"),
6666
[
6767
"install" | "add" | "remove" | "update" | "dedupe" | "outdated" | "list" | "ls" | "why"
68-
| "info" | "view" | "show" | "link" | "unlink" | "pm",
68+
| "info" | "view" | "show" | "link" | "unlink" | "rebuild" | "pm",
6969
..,
7070
] => Some("https://viteplus.dev/guide/install"),
7171
["dev"] => Some("https://viteplus.dev/guide/dev"),
@@ -477,6 +477,7 @@ pub fn top_level_help_doc() -> HelpDoc {
477477
row("info, view, show", "View package information from the registry"),
478478
row("link, ln", "Link packages for local development"),
479479
row("unlink", "Unlink packages"),
480+
row("rebuild", "Rebuild native modules"),
480481
row("pm", "Forward a command to the package manager"),
481482
],
482483
),

crates/vite_global_cli/src/main.rs

Lines changed: 79 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,60 @@ use crate::cli::{
3636

3737
/// Normalize CLI arguments:
3838
/// - `vp list ...` / `vp ls ...` → `vp pm list ...`
39+
/// - `vp rebuild ...` → `vp pm rebuild ...`
3940
/// - `vp help [command]` → `vp [command] --help`
4041
/// - `vp node [args...]` → `vp env exec node [args...]`
4142
fn normalize_args(args: Vec<String>) -> Vec<String> {
42-
match args.get(1).map(String::as_str) {
43-
// `vp list ...` → `vp pm list ...`
44-
// `vp ls ...` → `vp pm list ...`
45-
Some("list" | "ls") => {
46-
let mut normalized = Vec::with_capacity(args.len() + 1);
47-
normalized.push(args[0].clone());
48-
normalized.push("pm".to_string());
49-
normalized.push("list".to_string());
50-
normalized.extend(args[2..].iter().cloned());
51-
normalized
52-
}
53-
// `vp help` alone -> show main help
54-
Some("help") if args.len() == 2 => vec![args[0].clone(), "--help".to_string()],
55-
// `vp help [command] [args...]` -> `vp [command] --help [args...]`
56-
Some("help") if args.len() > 2 => {
57-
let mut normalized = Vec::with_capacity(args.len());
58-
normalized.push(args[0].clone());
59-
normalized.push(args[2].clone());
60-
normalized.push("--help".to_string());
61-
normalized.extend(args[3..].iter().cloned());
62-
normalized
63-
}
64-
// `vp node [args...]` → `vp env exec node [args...]`
65-
Some("node") => {
66-
let mut normalized = Vec::with_capacity(args.len() + 2);
67-
normalized.push(args[0].clone());
68-
normalized.push("env".to_string());
69-
normalized.push("exec".to_string());
70-
normalized.push("node".to_string());
71-
normalized.extend(args[2..].iter().cloned());
72-
normalized
73-
}
74-
// No transformation needed
75-
_ => args,
43+
let mut normalized = args;
44+
loop {
45+
let next = match normalized.get(1).map(String::as_str) {
46+
// `vp list ...` → `vp pm list ...`
47+
// `vp ls ...` → `vp pm list ...`
48+
Some("list" | "ls") => {
49+
let mut next = Vec::with_capacity(normalized.len() + 1);
50+
next.push(normalized[0].clone());
51+
next.push("pm".to_string());
52+
next.push("list".to_string());
53+
next.extend(normalized[2..].iter().cloned());
54+
next
55+
}
56+
// `vp rebuild ...` → `vp pm rebuild ...`
57+
Some("rebuild") => {
58+
let mut next = Vec::with_capacity(normalized.len() + 1);
59+
next.push(normalized[0].clone());
60+
next.push("pm".to_string());
61+
next.push("rebuild".to_string());
62+
next.extend(normalized[2..].iter().cloned());
63+
next
64+
}
65+
// `vp help` alone -> show main help
66+
Some("help") if normalized.len() == 2 => {
67+
vec![normalized[0].clone(), "--help".to_string()]
68+
}
69+
// `vp help [command] [args...]` -> `vp [command] --help [args...]`
70+
Some("help") if normalized.len() > 2 => {
71+
let mut next = Vec::with_capacity(normalized.len());
72+
next.push(normalized[0].clone());
73+
next.push(normalized[2].clone());
74+
next.push("--help".to_string());
75+
next.extend(normalized[3..].iter().cloned());
76+
next
77+
}
78+
// `vp node [args...]` → `vp env exec node [args...]`
79+
Some("node") => {
80+
let mut next = Vec::with_capacity(normalized.len() + 2);
81+
next.push(normalized[0].clone());
82+
next.push("env".to_string());
83+
next.push("exec".to_string());
84+
next.push("node".to_string());
85+
next.extend(normalized[2..].iter().cloned());
86+
next
87+
}
88+
// No transformation needed
89+
_ => return normalized,
90+
};
91+
92+
normalized = next;
7693
}
7794
}
7895

@@ -434,6 +451,34 @@ mod tests {
434451
assert_eq!(normalized, s(&["vp", "env", "exec", "node"]));
435452
}
436453

454+
#[test]
455+
fn normalize_args_rewrites_bare_vp_rebuild() {
456+
let input = s(&["vp", "rebuild"]);
457+
let normalized = normalize_args(input);
458+
assert_eq!(normalized, s(&["vp", "pm", "rebuild"]));
459+
}
460+
461+
#[test]
462+
fn normalize_args_rewrites_vp_rebuild_with_args() {
463+
let input = s(&["vp", "rebuild", "--", "--update-binary"]);
464+
let normalized = normalize_args(input);
465+
assert_eq!(normalized, s(&["vp", "pm", "rebuild", "--", "--update-binary"]));
466+
}
467+
468+
#[test]
469+
fn normalize_args_rewrites_vp_help_rebuild() {
470+
let input = s(&["vp", "help", "rebuild"]);
471+
let normalized = normalize_args(input);
472+
assert_eq!(normalized, s(&["vp", "pm", "rebuild", "--help"]));
473+
}
474+
475+
#[test]
476+
fn normalize_args_rewrites_vp_help_node() {
477+
let input = s(&["vp", "help", "node"]);
478+
let normalized = normalize_args(input);
479+
assert_eq!(normalized, s(&["vp", "env", "exec", "node", "--help"]));
480+
}
481+
437482
#[test]
438483
fn unknown_argument_detected_without_pass_as_value_hint() {
439484
let error = try_parse_args_from(["vp".to_string(), "--cache".to_string()])

docs/guide/install.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Vite+ provides all the familiar package management commands:
6060
- `vp list` shows installed packages
6161
- `vp why <pkg>` explains why a package is present
6262
- `vp info <pkg>` shows registry metadata for a package
63+
- `vp rebuild` rebuilds native modules (e.g. after switching Node.js versions)
6364
- `vp link` and `vp unlink` manage local package links
6465
- `vp dlx <pkg>` runs a package binary without adding it to the project
6566
- `vp pm <command>` forwards a raw package-manager-specific command when you need behavior outside the normalized `vp` command set
@@ -115,6 +116,20 @@ Use these when you need to understand the current state of dependencies.
115116
- `vp why react` explains why `react` is installed
116117
- `vp info react` shows registry metadata such as versions and dist-tags
117118

119+
#### Rebuild
120+
121+
Use `vp rebuild` when native modules need to be recompiled, for example after switching Node.js versions or when a C/C++ addon fails to load.
122+
123+
- `vp rebuild` rebuilds all native modules
124+
- `vp rebuild -- <args>` passes extra arguments to the underlying package manager
125+
126+
```bash
127+
vp rebuild
128+
vp rebuild -- --update-binary
129+
```
130+
131+
`vp rebuild` is a shorthand for `vp pm rebuild`.
132+
118133
#### Advanced
119134

120135
Use these when you need lower-level package-manager behavior.

packages/cli/snap-tests-global/cli-helper-message/snap.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Manage Dependencies:
4141
info, view, show View package information from the registry
4242
link, ln Link packages for local development
4343
unlink Unlink packages
44+
rebuild Rebuild native modules
4445
pm Forward a command to the package manager
4546

4647
Maintain:

0 commit comments

Comments
 (0)