Skip to content

Commit ad7b4bf

Browse files
committed
refactor(command): drop case-insensitive PATH lookup in resolve_program
Per PR review on #1498: every Rust call site of `run_command` / `run_command_with_fspy` already builds envs with uppercase `"PATH"` (via `HashMap::from([("PATH".to_string(), format_path_env(...))])` in vite_install command handlers and vite_pm_cli). The `Path`-keyed scenario the case-insensitive lookup defended against doesn't reach this code path, so the lookup and its Windows-only regression test are dead weight. Use `envs.get("PATH")` directly.
1 parent 3b55575 commit ad7b4bf

1 file changed

Lines changed: 1 addition & 53 deletions

File tree

crates/vite_command/src/lib.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ fn resolve_program(
5353
envs: &HashMap<String, String>,
5454
cwd: &AbsolutePath,
5555
) -> Result<(AbsolutePathBuf, Vec<OsString>), Error> {
56-
// Look up PATH case-insensitively: on Windows the canonical key is `Path`
57-
// and the TS layer's `prependToPathToEnvs` preserves whatever casing the
58-
// process started with. Hard-coding `"PATH"` would miss a `Path`-keyed
59-
// override and silently fall back to the process PATH (where the
60-
// prepended package-manager bin dir is absent).
61-
let path_env = envs
62-
.iter()
63-
.find(|(k, _)| k.eq_ignore_ascii_case("path"))
64-
.map(|(_, v)| OsStr::new(v.as_str()));
56+
let path_env = envs.get("PATH").map(|p| OsStr::new(p.as_str()));
6557
let bin_path = resolve_bin(bin_name, path_env, cwd)?;
6658
Ok(match ps1_shim::rewrite_cmd_to_powershell(&bin_path) {
6759
Some(rewritten) => rewritten,
@@ -378,50 +370,6 @@ mod tests {
378370
}
379371
}
380372

381-
#[cfg(windows)]
382-
mod resolve_program_tests {
383-
use super::*;
384-
385-
// Regression for voidzero-dev/vite-plus#1489 follow-up: on Windows the
386-
// PATH environment variable is conventionally keyed `Path` (and the
387-
// TS layer's `prependToPathToEnvs` preserves that casing when adding
388-
// the downloaded package-manager bin dir). `resolve_program` must
389-
// look up PATH case-insensitively or it falls back to the process
390-
// environment and can't find the prepended shim.
391-
#[test]
392-
fn resolve_program_finds_binary_via_lowercase_path_key() {
393-
let temp_dir = create_temp_dir();
394-
let temp_dir_path =
395-
AbsolutePathBuf::new(temp_dir.path().canonicalize().unwrap().to_path_buf())
396-
.unwrap();
397-
398-
// Unique name so it can't accidentally resolve via the process PATH.
399-
let bin_name = "vp_test_resolve_program_path_casing";
400-
let bin_path = temp_dir.path().join(format!("{bin_name}.exe"));
401-
std::fs::write(&bin_path, b"").unwrap();
402-
403-
// `Path`, not `PATH` — the real-world Windows casing.
404-
let envs = HashMap::from([(
405-
"Path".to_string(),
406-
temp_dir_path.as_path().to_string_lossy().into_owned(),
407-
)]);
408-
409-
let result = resolve_program(bin_name, &envs, &temp_dir_path);
410-
assert!(
411-
result.is_ok(),
412-
"resolve_program must find the binary via the `Path` env key on Windows; got: {:?}",
413-
result.err()
414-
);
415-
let (program, prefix_args) = result.unwrap();
416-
assert!(prefix_args.is_empty(), "no .ps1 sibling, no PowerShell prefix expected");
417-
assert_eq!(
418-
program.as_path().file_stem().and_then(|s| s.to_str()),
419-
Some(bin_name),
420-
"resolved program should be the .exe in the tempdir"
421-
);
422-
}
423-
}
424-
425373
mod run_command_with_fspy_tests {
426374
use super::*;
427375

0 commit comments

Comments
 (0)