Skip to content

Commit c3514aa

Browse files
committed
fix(install): trim global npm list surface
1 parent 09faa61 commit c3514aa

2 files changed

Lines changed: 14 additions & 54 deletions

File tree

  • crates
    • vite_global_cli/src/commands
    • vite_install/src/commands

crates/vite_global_cli/src/commands/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,21 @@ pub(crate) fn managed_npm_bin_for_global_command(
120120
}
121121

122122
let npm_bin = npm_bin_path_from_node_bin_prefix(node_bin_prefix);
123-
vite_command::resolve_bin(
123+
match vite_command::resolve_bin(
124124
npm_bin.as_path().as_os_str().to_string_lossy().as_ref(),
125125
None,
126126
node_bin_prefix,
127-
)
128-
.ok()
127+
) {
128+
Ok(npm_bin) => Some(npm_bin),
129+
Err(error) => {
130+
tracing::debug!(
131+
npm_bin = ?npm_bin,
132+
?error,
133+
"Falling back to npm from PATH for global command"
134+
);
135+
None
136+
}
137+
}
129138
}
130139

131140
/// Build a PackageManager, converting PackageJsonNotFound into a friendly error message.

crates/vite_install/src/commands/list.rs

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use vite_shared::output;
77

88
use crate::package_manager::{
99
PackageManager, PackageManagerType, ResolveCommandResult, format_path_env,
10-
resolve_global_npm_bin_path,
1110
};
1211

1312
/// Options for the list command.
@@ -39,50 +38,20 @@ impl PackageManager {
3938
options: &ListCommandOptions<'_>,
4039
cwd: impl AsRef<AbsolutePath>,
4140
) -> Result<ExitStatus, Error> {
42-
let Some(resolve_command) = self.resolve_list_command_with_global_npm_bin(options, None)
43-
else {
41+
let Some(resolve_command) = self.resolve_list_command(options) else {
4442
// Command not supported, return success
4543
return Ok(ExitStatus::default());
4644
};
4745
run_command(&resolve_command.bin_path, &resolve_command.args, &resolve_command.envs, cwd)
4846
.await
4947
}
5048

51-
/// Run the list command with an explicit npm binary for global lists.
52-
/// Returns ExitStatus with success (0) if the command is not supported.
53-
#[must_use]
54-
pub async fn run_list_command_with_global_npm_bin(
55-
&self,
56-
options: &ListCommandOptions<'_>,
57-
cwd: impl AsRef<AbsolutePath>,
58-
global_npm_bin_path: Option<&AbsolutePath>,
59-
) -> Result<ExitStatus, Error> {
60-
let Some(resolve_command) =
61-
self.resolve_list_command_with_global_npm_bin(options, global_npm_bin_path)
62-
else {
63-
return Ok(ExitStatus::default());
64-
};
65-
run_command(&resolve_command.bin_path, &resolve_command.args, &resolve_command.envs, cwd)
66-
.await
67-
}
68-
6949
/// Resolve the list command.
7050
/// Returns None if the command is not supported by the package manager.
7151
#[must_use]
7252
pub fn resolve_list_command(
7353
&self,
7454
options: &ListCommandOptions,
75-
) -> Option<ResolveCommandResult> {
76-
self.resolve_list_command_with_global_npm_bin(options, None)
77-
}
78-
79-
/// Resolve the list command with an explicit npm binary for global lists.
80-
/// Returns None if the command is not supported by the package manager.
81-
#[must_use]
82-
pub fn resolve_list_command_with_global_npm_bin(
83-
&self,
84-
options: &ListCommandOptions,
85-
global_npm_bin_path: Option<&AbsolutePath>,
8655
) -> Option<ResolveCommandResult> {
8756
// yarn@2+ does not support list command
8857
if self.client == PackageManagerType::Yarn && !self.version.starts_with("1.") {
@@ -96,7 +65,7 @@ impl PackageManager {
9665
// Global packages should use npm cli only (since global installs use npm)
9766
let bin_name: String;
9867
if options.global {
99-
bin_name = resolve_global_npm_bin_path(global_npm_bin_path);
68+
bin_name = "npm".into();
10069
Self::format_npm_list_args(&mut args, options);
10170
args.push("-g".into());
10271

@@ -511,24 +480,6 @@ mod tests {
511480
assert_eq!(result.args, vec!["list", "--depth", "0", "-g"]);
512481
}
513482

514-
#[test]
515-
fn test_global_list_uses_explicit_npm_bin() {
516-
let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0");
517-
let npm_bin = if cfg!(windows) {
518-
AbsolutePathBuf::new("C:\\node\\npm.cmd".into()).unwrap()
519-
} else {
520-
AbsolutePathBuf::new("/node/bin/npm".into()).unwrap()
521-
};
522-
let result = pm
523-
.resolve_list_command_with_global_npm_bin(
524-
&ListCommandOptions { global: true, ..Default::default() },
525-
Some(&npm_bin),
526-
)
527-
.unwrap();
528-
assert_eq!(result.bin_path, npm_bin.as_path().display().to_string());
529-
assert_eq!(result.args, vec!["list", "-g"]);
530-
}
531-
532483
#[test]
533484
fn test_pnpm_list_with_filter() {
534485
let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0");

0 commit comments

Comments
 (0)