Skip to content

Commit b009326

Browse files
committed
feat(env): migrate vp env packages to vp pm list -g + add vp list/vp ls aliases
Move global package listing from `vp env` to `vp pm list -g` where package management belongs. Add `vp list` and `vp ls` as top-level aliases that rewrite to `vp pm list`. When `-g` is passed, the command intercepts early (before JS runtime init) and delegates to the managed packages listing with optional pattern filtering.
1 parent b216bf1 commit b009326

8 files changed

Lines changed: 45 additions & 28 deletions

File tree

crates/vite_global_cli/src/cli.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -718,13 +718,6 @@ pub enum EnvSubcommands {
718718
command: Vec<String>,
719719
},
720720

721-
/// List installed global packages
722-
Packages {
723-
/// Output as JSON
724-
#[arg(long)]
725-
json: bool,
726-
},
727-
728721
/// Uninstall a Node.js version
729722
#[command(alias = "uni")]
730723
Uninstall {

crates/vite_global_cli/src/commands/env/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod list_remote;
1414
mod off;
1515
mod on;
1616
pub mod package_metadata;
17-
mod packages;
17+
pub mod packages;
1818
mod pin;
1919
mod run;
2020
mod setup;
@@ -56,7 +56,6 @@ pub async fn execute(cwd: AbsolutePathBuf, args: EnvArgs) -> Result<ExitStatus,
5656
crate::cli::EnvSubcommands::Run { node, npm, command } => {
5757
run::execute(node.as_deref(), npm.as_deref(), &command).await
5858
}
59-
crate::cli::EnvSubcommands::Packages { json } => packages::execute(json).await,
6059
crate::cli::EnvSubcommands::Uninstall { version } => {
6160
let provider = vite_js_runtime::NodeProvider::new();
6261
let resolved = config::resolve_version_alias(&version, &provider).await?;
@@ -135,7 +134,6 @@ fn print_help() {
135134
println!(" list-remote [PAT] List available Node.js versions from the registry");
136135
println!(" use [VERSION] Use a Node.js version for this shell session");
137136
println!(" run [--node <VER>] Run a command (--node optional for shim tools)");
138-
println!(" packages List installed global packages");
139137
println!(" install [VERSION] Install a Node.js version (reads project config if omitted)");
140138
println!(" uninstall <VERSION> Uninstall a Node.js version");
141139
println!();
@@ -176,6 +174,7 @@ fn print_help() {
176174
println!(" vp install -g <package> # Install a global package");
177175
println!(" vp uninstall -g <package> # Uninstall a global package");
178176
println!(" vp update -g [package] # Update global package(s)");
177+
println!(" vp list -g [package] # List installed global packages");
179178
}
180179

181180
/// Print shell snippet for setting environment (--print flag)

crates/vite_global_cli/src/commands/env/packages.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ use super::package_metadata::PackageMetadata;
66
use crate::error::Error;
77

88
/// Execute the packages command.
9-
pub async fn execute(json: bool) -> Result<ExitStatus, Error> {
10-
let packages = PackageMetadata::list_all().await?;
9+
pub async fn execute(json: bool, pattern: Option<&str>) -> Result<ExitStatus, Error> {
10+
let all_packages = PackageMetadata::list_all().await?;
11+
12+
let packages: Vec<_> = if let Some(pat) = pattern {
13+
let pat_lower = pat.to_lowercase();
14+
all_packages.into_iter().filter(|p| p.name.to_lowercase().contains(&pat_lower)).collect()
15+
} else {
16+
all_packages
17+
};
1118

1219
if packages.is_empty() {
1320
if json {
1421
println!("[]");
22+
} else if pattern.is_some() {
23+
println!("No global packages matching '{}'.", pattern.unwrap());
24+
println!();
25+
println!("Run 'vp list -g' to see all installed global packages.");
1526
} else {
1627
println!("No global packages installed.");
1728
println!();

crates/vite_global_cli/src/commands/env/which.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub async fn execute(cwd: AbsolutePathBuf, tool: &str) -> Result<ExitStatus, Err
3434
// Unknown tool
3535
eprintln!("vp: Unknown tool '{tool}'");
3636
eprintln!("Not a core tool (node, npm, npx) and not found in any installed global package.");
37-
eprintln!("Run 'vp env packages' to see installed global packages.");
37+
eprintln!("Run 'vp list -g' to see installed global packages.");
3838
Ok(exit_status(1))
3939
}
4040

crates/vite_global_cli/src/commands/pm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ pub async fn execute_pm_subcommand(
4444
cwd: AbsolutePathBuf,
4545
command: PmCommands,
4646
) -> Result<ExitStatus, Error> {
47+
// Intercept `pm list -g` to use vite-plus managed global packages listing
48+
if let PmCommands::List { global: true, json, ref pattern, .. } = command {
49+
return crate::commands::env::packages::execute(json, pattern.as_deref()).await;
50+
}
51+
4752
prepend_js_runtime_to_path_env(&cwd).await?;
4853

4954
let package_manager = PackageManager::builder(&cwd).build_with_default().await?;

crates/vite_global_cli/src/main.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,30 @@ use std::process::ExitCode;
1717

1818
use crate::cli::{parse_args_from, run_command};
1919

20-
/// Normalize help arguments: transform `help [command]` into `[command] --help`
21-
fn normalize_help_args() -> Vec<String> {
22-
let args: Vec<String> = std::env::args().collect();
23-
24-
// Skip the binary name (args[0])
20+
/// Normalize CLI arguments:
21+
/// - `vp list ...` / `vp ls ...` → `vp pm list ...`
22+
/// - `vp help [command]` → `vp [command] --help`
23+
fn normalize_args(args: Vec<String>) -> Vec<String> {
2524
match args.get(1).map(String::as_str) {
25+
// `vp list ...` → `vp pm list ...`
26+
// `vp ls ...` → `vp pm list ...`
27+
Some("list" | "ls") => {
28+
let mut normalized = Vec::with_capacity(args.len() + 1);
29+
normalized.push(args[0].clone());
30+
normalized.push("pm".to_string());
31+
normalized.push("list".to_string());
32+
normalized.extend(args[2..].iter().cloned());
33+
normalized
34+
}
2635
// `vp help` alone -> show main help
2736
Some("help") if args.len() == 2 => vec![args[0].clone(), "--help".to_string()],
2837
// `vp help [command] [args...]` -> `vp [command] --help [args...]`
2938
Some("help") if args.len() > 2 => {
3039
let mut normalized = Vec::with_capacity(args.len());
31-
normalized.push(args[0].clone()); // binary name
32-
normalized.push(args[2].clone()); // command
40+
normalized.push(args[0].clone());
41+
normalized.push(args[2].clone());
3342
normalized.push("--help".to_string());
34-
normalized.extend(args[3..].iter().cloned()); // remaining args
43+
normalized.extend(args[3..].iter().cloned());
3544
normalized
3645
}
3746
// No transformation needed
@@ -64,8 +73,8 @@ async fn main() -> ExitCode {
6473
}
6574
};
6675

67-
// Normalize help arguments: transform `help [command]` into `[command] --help`
68-
let normalized_args = normalize_help_args();
76+
// Normalize arguments (list/ls aliases, help rewriting)
77+
let normalized_args = normalize_args(args);
6978

7079
// Parse CLI arguments (using custom help formatting)
7180
let args = parse_args_from(normalized_args);

packages/global/snap-tests/command-env-which/snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ added 41 packages in <variable>ms
3535
[1]> vp env which unknown-tool # Unknown tool - error message
3636
vp: Unknown tool 'unknown-tool'
3737
Not a core tool (node, npm, npx) and not found in any installed global package.
38-
Run 'vp env packages' to see installed global packages.
38+
Run 'vp list -g' to see installed global packages.

rfcs/env-command.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ vp install -g --node lts typescript
167167
vp install -g --force eslint-v9 # Removes 'eslint' if it provides same binary
168168

169169
# List installed global packages
170-
vp env packages
171-
vp env packages --json
170+
vp list -g
171+
vp list -g --json
172172

173173
# Uninstall a global package
174174
vp remove -g typescript
@@ -1240,7 +1240,7 @@ $ vp env which eslint
12401240
$ vp env which unknown-tool
12411241
vp: Unknown tool 'unknown-tool'
12421242
Not a core tool (node, npm, npx) and not found in any installed global package.
1243-
Run 'vp env packages' to see installed global packages.
1243+
Run 'vp list -g' to see installed global packages.
12441244
```
12451245
12461246
## Pin Command
@@ -2021,7 +2021,7 @@ env-doctor/
20212021
5. Implement `vp install -g` / `vp remove -g` / `vp update -g` for managed global packages
20222022
6. Implement package metadata storage
20232023
7. Implement per-package binary shims
2024-
8. Implement `vp env packages` to list installed global packages
2024+
8. Implement `vp list -g` / `vp pm list -g` to list installed global packages
20252025
9. Implement `vp env install <VERSION>` to install Node.js versions
20262026
10. Implement `vp env uninstall <VERSION>` to uninstall Node.js versions
20272027
11. Implement per-binary config files (`bins/`) for conflict detection

0 commit comments

Comments
 (0)