Skip to content

Commit e18bc64

Browse files
committed
find PATH case-insensitively on Windows
1 parent d982129 commit e18bc64

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

crates/vite_task/src/execute.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,23 @@ impl TaskEnvs {
310310
all_envs.insert("VITE_TASK_EXECUTION_ENV".into(), Arc::<OsStr>::from(OsStr::new("1")));
311311

312312
// Add node_modules/.bin to PATH
313-
let env_path =
314-
all_envs.entry("PATH".into()).or_insert_with(|| Arc::<OsStr>::from(OsStr::new("")));
313+
// On Windows, environment variable names are case-insensitive (e.g., "PATH", "Path", "path" are all the same)
314+
// However, Rust's HashMap keys are case-sensitive, so we need to find the existing PATH variable
315+
// regardless of its casing to avoid creating duplicate PATH entries with different casings.
316+
// For example, if the system has "Path", we should use that instead of creating a new "PATH" entry.
317+
let env_path = {
318+
if cfg!(windows)
319+
&& let Some(existing_path) = all_envs.iter_mut().find_map(|(name, value)| {
320+
if name.eq_ignore_ascii_case("path") { Some(value) } else { None }
321+
})
322+
{
323+
// Found existing PATH variable (with any casing), use it
324+
existing_path
325+
} else {
326+
// On Unix or no existing PATH on Windows, create/get "PATH" entry
327+
all_envs.entry("PATH".into()).or_insert_with(|| Arc::<OsStr>::from(OsStr::new("")))
328+
}
329+
};
315330
let paths = split_paths(env_path);
316331

317332
let node_modules_bin_paths = [

0 commit comments

Comments
 (0)