Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Fix windows test.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Mar 1, 2024
1 parent 8a84dfa commit 7ef8c04
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
48 changes: 29 additions & 19 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,21 +384,20 @@ pub fn pre_run(Json(input): Json<RunHook>) -> FnResult<Json<RunHookResult>> {
let env = get_host_environment()?;
let manager = PackageManager::detect()?;

// Where binaries are symlinked... see `locate_executables` above.
let globals_bin_dir = globals_dir.real_path().unwrap();

// Where the packages are installed to. On Windows, globals will be
// installed into the bin directory directly.
let globals_install_dir = if env.os.is_windows() {
globals_bin_dir.to_string_lossy()
}
// On Unix, globals are installed a directory higher, while they're
// binaries are symlinked to ./bin. So we must remove the trailing
// /bin for everything to resolve correctly.
else {
globals_bin_dir.parent().unwrap().to_string_lossy()
}
.to_string();
// Includes trailing /bin folder
let globals_bin_dir = globals_dir
.real_path()
.unwrap()
.to_string_lossy()
.to_string();
// Parent directory, doesn't include /bin folder
let globals_root_dir = globals_dir
.real_path()
.unwrap()
.parent()
.unwrap()
.to_string_lossy()
.to_string();

match manager {
// npm install|add|etc -g <dep>
Expand Down Expand Up @@ -435,7 +434,16 @@ pub fn pre_run(Json(input): Json<RunHook>) -> FnResult<Json<RunHookResult>> {
result
.env
.get_or_insert(HashMap::default())
.insert("PREFIX".into(), globals_install_dir);
// Unix will create a /bin directory when installing into the root,
// while Windows installs directly into the /bin directory.
.insert(
"PREFIX".into(),
if env.os == HostOS::Windows {
globals_bin_dir
} else {
globals_root_dir
},
);
}
}

Expand All @@ -455,9 +463,9 @@ pub fn pre_run(Json(input): Json<RunHook>) -> FnResult<Json<RunHookResult>> {
// environment variables from what I've seen...
let new_args = result.args.get_or_insert(vec![]);
new_args.push("--global-dir".into());
new_args.push(globals_install_dir);
new_args.push(globals_root_dir);
new_args.push("--global-bin-dir".into());
new_args.push(globals_bin_dir.to_string_lossy().to_string());
new_args.push(globals_bin_dir);
}
}

Expand All @@ -472,7 +480,9 @@ pub fn pre_run(Json(input): Json<RunHook>) -> FnResult<Json<RunHookResult>> {
result
.env
.get_or_insert(HashMap::default())
.insert("PREFIX".into(), globals_install_dir);
// Both Unix and Windows will create a /bin directory,
// when installing into the root.
.insert("PREFIX".into(), globals_root_dir);
}
}
};
Expand Down
6 changes: 1 addition & 5 deletions crates/node-depman/tests/hooks_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ mod pre_run {
result.env,
Some(HashMap::from_iter([(
"PREFIX".into(),
if cfg!(windows) {
"/.proto/tools/node/globals/bin".into()
} else {
"/.proto/tools/node/globals".into()
}
"/.proto/tools/node/globals".into()
)]))
);
}
Expand Down

0 comments on commit 7ef8c04

Please sign in to comment.