Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/vite_global_cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fn documentation_url_for_command_path(command_path: &[&str]) -> Option<&'static
["config"] | ["staged"] => Some("https://viteplus.dev/guide/commit-hooks"),
[
"install" | "add" | "remove" | "update" | "dedupe" | "outdated" | "list" | "ls" | "why"
| "info" | "view" | "show" | "link" | "unlink" | "pm",
| "info" | "view" | "show" | "link" | "unlink" | "rebuild" | "pm",
..,
] => Some("https://viteplus.dev/guide/install"),
["dev"] => Some("https://viteplus.dev/guide/dev"),
Expand Down Expand Up @@ -477,6 +477,7 @@ pub fn top_level_help_doc() -> HelpDoc {
row("info, view, show", "View package information from the registry"),
row("link, ln", "Link packages for local development"),
row("unlink", "Unlink packages"),
row("rebuild", "Rebuild native modules"),
row("pm", "Forward a command to the package manager"),
],
),
Expand Down
24 changes: 24 additions & 0 deletions crates/vite_global_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::cli::{

/// Normalize CLI arguments:
/// - `vp list ...` / `vp ls ...` → `vp pm list ...`
/// - `vp rebuild ...` → `vp pm rebuild ...`
/// - `vp help [command]` → `vp [command] --help`
/// - `vp node [args...]` → `vp env exec node [args...]`
fn normalize_args(args: Vec<String>) -> Vec<String> {
Expand All @@ -50,6 +51,15 @@ fn normalize_args(args: Vec<String>) -> Vec<String> {
normalized.extend(args[2..].iter().cloned());
normalized
}
// `vp rebuild ...` → `vp pm rebuild ...`
Some("rebuild") => {
let mut normalized = Vec::with_capacity(args.len() + 1);
normalized.push(args[0].clone());
normalized.push("pm".to_string());
normalized.push("rebuild".to_string());
Comment thread
fengmk2 marked this conversation as resolved.
Outdated
normalized.extend(args[2..].iter().cloned());
normalized
}
// `vp help` alone -> show main help
Some("help") if args.len() == 2 => vec![args[0].clone(), "--help".to_string()],
// `vp help [command] [args...]` -> `vp [command] --help [args...]`
Expand Down Expand Up @@ -434,6 +444,20 @@ mod tests {
assert_eq!(normalized, s(&["vp", "env", "exec", "node"]));
}

#[test]
fn normalize_args_rewrites_bare_vp_rebuild() {
let input = s(&["vp", "rebuild"]);
let normalized = normalize_args(input);
assert_eq!(normalized, s(&["vp", "pm", "rebuild"]));
}

#[test]
fn normalize_args_rewrites_vp_rebuild_with_args() {
let input = s(&["vp", "rebuild", "--", "--update-binary"]);
let normalized = normalize_args(input);
assert_eq!(normalized, s(&["vp", "pm", "rebuild", "--", "--update-binary"]));
}

#[test]
fn unknown_argument_detected_without_pass_as_value_hint() {
let error = try_parse_args_from(["vp".to_string(), "--cache".to_string()])
Expand Down
15 changes: 15 additions & 0 deletions docs/guide/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Vite+ provides all the familiar package management commands:
- `vp list` shows installed packages
- `vp why <pkg>` explains why a package is present
- `vp info <pkg>` shows registry metadata for a package
- `vp rebuild` rebuilds native modules (e.g. after switching Node.js versions)
- `vp link` and `vp unlink` manage local package links
- `vp dlx <pkg>` runs a package binary without adding it to the project
- `vp pm <command>` forwards a raw package-manager-specific command when you need behavior outside the normalized `vp` command set
Expand Down Expand Up @@ -115,6 +116,20 @@ Use these when you need to understand the current state of dependencies.
- `vp why react` explains why `react` is installed
- `vp info react` shows registry metadata such as versions and dist-tags

#### Rebuild

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.

- `vp rebuild` rebuilds all native modules
- `vp rebuild -- <args>` passes extra arguments to the underlying package manager

```bash
vp rebuild
vp rebuild -- --update-binary
```

`vp rebuild` is a shorthand for `vp pm rebuild`.

#### Advanced

Use these when you need lower-level package-manager behavior.
Expand Down
Loading