This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
64 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,59 @@ | ||
use proto_pdk_api::ExecCommandInput; | ||
use proto_pdk_api::{ExecCommandInput, HostEnvironment}; | ||
use std::path::Path; | ||
|
||
pub fn install_global(dependency: &str, globals_dir: &Path) -> ExecCommandInput { | ||
pub fn get_global_prefix<T: AsRef<Path>>(env: &HostEnvironment, globals_dir: T) -> String { | ||
let prefix = globals_dir.as_ref().to_string_lossy().to_string(); | ||
|
||
// On Windows, globals will be installed into the prefix as-is, | ||
// so binaries will exist in the root of the prefix. | ||
if env.os.is_windows() { | ||
return prefix; | ||
} | ||
|
||
// On Unix, globals are nested within a /bin directory, and since our | ||
// fixed globals dir ends in /bin, we must remove it and set the prefix | ||
// to the parent directory. This way everything resolves correctly. | ||
prefix.replace("/bin", "") | ||
} | ||
|
||
pub fn install_global(dependency: &str, globals_prefix: String) -> ExecCommandInput { | ||
let mut cmd = ExecCommandInput::inherit( | ||
"npm", | ||
[ | ||
"install", | ||
dependency, | ||
"--global", | ||
"--loglevel", | ||
"warn", | ||
"--no-audit", | ||
"--no-update-notifier", | ||
dependency, | ||
"--prefix", | ||
&globals_prefix, | ||
], | ||
); | ||
|
||
cmd.env_vars | ||
.insert("PROTO_INSTALL_GLOBAL".into(), "true".into()); | ||
|
||
// Remove the /bin component | ||
cmd.env_vars.insert( | ||
"PREFIX".into(), | ||
globals_dir.parent().unwrap().to_string_lossy().to_string(), | ||
); | ||
|
||
cmd | ||
} | ||
|
||
pub fn uninstall_global(dependency: &str, globals_dir: &Path) -> ExecCommandInput { | ||
pub fn uninstall_global(dependency: &str, globals_prefix: String) -> ExecCommandInput { | ||
let mut cmd = ExecCommandInput::inherit( | ||
"npm", | ||
["uninstall", "--global", "--loglevel", "warn", dependency], | ||
[ | ||
"uninstall", | ||
dependency, | ||
"--global", | ||
"--loglevel", | ||
"warn", | ||
"--prefix", | ||
&globals_prefix, | ||
], | ||
); | ||
|
||
cmd.env_vars | ||
.insert("PROTO_INSTALL_GLOBAL".into(), "true".into()); | ||
|
||
// Remove the /bin component | ||
cmd.env_vars.insert( | ||
"PREFIX".into(), | ||
globals_dir.parent().unwrap().to_string_lossy().to_string(), | ||
); | ||
|
||
cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters