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

fix: Fix incorrect Windows globals dir. #22

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.5.3

#### 🐞 Fixes

- Fixed an incorrect globals directory on Windows.

#### ⚙️ Internal

- Updated dependencies.
- Updated globals install to use a `--prefix` arg instead of `PREFIX` env var.

## 0.5.2

#### 🚀 Updates
Expand Down
48 changes: 28 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ members = ["crates/*"]
extism-pdk = "0.3.4"
proto_pdk = { version = "0.10.3" } # , path = "../../proto/crates/pdk" }
proto_pdk_api = { version = "0.10.4" } # , path = "../../proto/crates/pdk-api" }
proto_pdk_test_utils = { version = "0.11.0" } # , path = "../../proto/crates/pdk-test-utils" }
proto_pdk_test_utils = { version = "0.11.1" } # , path = "../../proto/crates/pdk-test-utils" }
regex = { version = "1.10.2", default-features = false, features = [
"std",
"unicode",
] }
serde = "1.0.192"
serde = "1.0.193"
serde_json = "1.0.108"
starbase_sandbox = "0.1.12"
tokio = { version = "1.34.0", features = ["full"] }
Expand Down
48 changes: 30 additions & 18 deletions crates/common/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
use proto_pdk_api::ExecCommandInput;
use std::path::Path;
use proto_pdk_api::{ExecCommandInput, HostEnvironment, VirtualPath};

pub fn install_global(dependency: &str, globals_dir: &Path) -> ExecCommandInput {
pub fn get_global_prefix(env: &HostEnvironment, globals_dir: &VirtualPath) -> String {
let prefix = globals_dir.real_path().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
}
2 changes: 1 addition & 1 deletion crates/node-depman/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node_depman_plugin"
version = "0.5.2"
version = "0.5.3"
edition = "2021"
license = "MIT"
publish = false
Expand Down
15 changes: 11 additions & 4 deletions crates/node-depman/src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::npm_registry::parse_registry_response;
use crate::package_manager::PackageManager;
use extism_pdk::*;
use node_common::{commands, BinField, NodeDistVersion, PackageJson};
use node_common::{
commands::{self, get_global_prefix},
BinField, NodeDistVersion, PackageJson,
};
use proto_pdk::*;
use std::collections::HashMap;
use std::fs;
Expand Down Expand Up @@ -247,7 +250,7 @@ pub fn download_prebuilt(
};

Ok(Json(DownloadPrebuiltOutput {
archive_prefix: Some(get_archive_prefix(&manager, &version)),
archive_prefix: Some(get_archive_prefix(&manager, version)),
download_url: format!(
"https://registry.npmjs.org/{package_name}/-/{package_without_scope}-{version}.tgz",
),
Expand Down Expand Up @@ -321,9 +324,11 @@ pub fn locate_executables(
pub fn install_global(
Json(input): Json<InstallGlobalInput>,
) -> FnResult<Json<InstallGlobalOutput>> {
let env = get_proto_environment()?;

let result = exec_command!(commands::install_global(
&input.dependency,
&input.globals_dir.real_path(),
get_global_prefix(&env, &input.globals_dir),
));

Ok(Json(InstallGlobalOutput::from_exec_command(result)))
Expand All @@ -333,9 +338,11 @@ pub fn install_global(
pub fn uninstall_global(
Json(input): Json<UninstallGlobalInput>,
) -> FnResult<Json<UninstallGlobalOutput>> {
let env = get_proto_environment()?;

let result = exec_command!(commands::uninstall_global(
&input.dependency,
&input.globals_dir.real_path(),
get_global_prefix(&env, &input.globals_dir),
));

Ok(Json(UninstallGlobalOutput::from_exec_command(result)))
Expand Down
11 changes: 5 additions & 6 deletions crates/node-depman/tests/globals_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// These work locally but fail in CI... hard to debug!

// use proto_pdk_test_utils::*;
// use starbase_sandbox::create_empty_sandbox;
use proto_pdk_test_utils::*;

// mod npm {
// use super::*;
mod npm {
use super::*;

// generate_globals_test!("npm-test", "prettier");
// }
generate_globals_test!("npm-test", "prettier");
}

// mod pnpm {
// use super::*;
Expand Down
Loading
Loading