Skip to content

Commit 5dc3a8b

Browse files
authored
feat(env): show full file path in vp env which and vp env doctor source display (#641)
When the version source is a file (.node-version, package.json engines.node, etc.), display the full absolute path instead of just the source type name. This helps users identify which file was used when .node-version is found in a parent directory rather than cwd. Session (VITE_PLUS_NODE_VERSION) and fallback (lts) sources retain their existing annotations.
1 parent 732f8cd commit 5dc3a8b

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,12 @@ async fn check_current_resolution(cwd: &AbsolutePathBuf) {
543543

544544
match resolve_version(cwd).await {
545545
Ok(resolution) => {
546-
print_check(" ", "Source", &resolution.source);
546+
let source_display = resolution
547+
.source_path
548+
.as_ref()
549+
.map(|p| p.as_path().display().to_string())
550+
.unwrap_or(resolution.source);
551+
print_check(" ", "Source", &source_display);
547552
print_check(" ", "Version", &resolution.version.bright_green().to_string());
548553

549554
// Check if Node.js is installed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::process::ExitStatus;
1010

1111
use chrono::Local;
1212
use owo_colors::OwoColorize;
13-
use vite_path::AbsolutePathBuf;
13+
use vite_path::{AbsolutePath, AbsolutePathBuf};
1414
use vite_shared::output;
1515

1616
use super::{
@@ -77,19 +77,25 @@ async fn execute_core_tool(cwd: AbsolutePathBuf, tool: &str) -> Result<ExitStatu
7777
println!("{}", tool_path.as_path().display());
7878

7979
// Print metadata
80-
let source_display = format_source(&resolution.source);
80+
let source_display = format_source(&resolution.source, resolution.source_path.as_deref());
8181
println!(" {:<LABEL_WIDTH$} {}", "Version:".dimmed(), resolution.version.bright_green());
8282
println!(" {:<LABEL_WIDTH$} {}", "Source:".dimmed(), source_display.dimmed());
8383

8484
Ok(ExitStatus::default())
8585
}
8686

8787
/// Format the resolution source for human-friendly display.
88-
fn format_source(source: &str) -> String {
88+
///
89+
/// When a `source_path` is available, shows the full file path instead of just the source type name.
90+
/// For env var and lts sources, annotations like `(session)` and `(fallback)` are preserved.
91+
fn format_source(source: &str, source_path: Option<&AbsolutePath>) -> String {
8992
match source {
9093
s if s == VERSION_ENV_VAR => format!("{s} (session)"),
9194
"lts" => "lts (fallback)".to_string(),
92-
other => other.to_string(),
95+
_ => match source_path {
96+
Some(path) => path.as_path().display().to_string(),
97+
None => source.to_string(),
98+
},
9399
}
94100
}
95101

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ v20.18.0
44
> vp env which node # Core tool - shows resolved Node.js binary path
55
<vite-plus-home>/js_runtime/node/<semver>/bin/node
66
Version:  20.18.0
7-
Source:  .node-version
7+
Source:  <cwd>/.node-version
88

99
> vp env which npm # Core tool - shows resolved npm binary path
1010
<vite-plus-home>/js_runtime/node/<semver>/bin/npm
1111
Version:  20.18.0
12-
Source:  .node-version
12+
Source:  <cwd>/.node-version
1313

1414
> vp env which npx # Core tool - shows resolved npx binary path
1515
<vite-plus-home>/js_runtime/node/<semver>/bin/npx
1616
Version:  20.18.0
17-
Source:  .node-version
17+
Source:  <cwd>/.node-version
1818

1919
> vp install -g cowsay@1.6.0 # Install a global package via vp
2020
Installing cowsay@<semver> globally...

rfcs/env-command.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,12 +1307,12 @@ Shows the path to the tool binary that would be executed. The first line is alwa
13071307
$ vp env which node
13081308
/Users/user/.vite-plus/js_runtime/node/20.18.0/bin/node
13091309
Version: 20.18.0
1310-
Source: .node-version
1310+
Source: /Users/user/projects/my-app/.node-version
13111311
13121312
$ vp env which npm
13131313
/Users/user/.vite-plus/js_runtime/node/20.18.0/bin/npm
13141314
Version: 20.18.0
1315-
Source: .node-version
1315+
Source: /Users/user/projects/my-app/.node-version
13161316
```
13171317
13181318
When using session override:

0 commit comments

Comments
 (0)