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

Commit

Permalink
new: Support proto v0.15. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Aug 21, 2023
1 parent 5085b18 commit 34fe37b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 47 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Changelog

## 0.1.1
## 0.2.0

#### 🚀 Updates

- Added support for `install_global` and `uninstall_global`.
- Updated to support proto v0.15 release.

## 0.1.0

Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bun_plugin"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
license = "MIT"
publish = false
Expand All @@ -10,10 +10,10 @@ crate-type = ['cdylib']

[dependencies]
extism-pdk = "0.3.3"
proto_pdk = { version = "0.4.5" }
proto_pdk = { version = "0.6.1" } # , path = "../../proto/crates/pdk" }
serde = "1.0.183"

[dev-dependencies]
proto_pdk_test_utils = { version = "0.3.9" }
proto_pdk_test_utils = { version = "0.5.0" } # , path = "../../proto/crates/pdk-test-utils" }
starbase_sandbox = "0.1.8"
tokio = "1.31.0"
20 changes: 12 additions & 8 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ pub fn register_tool(Json(_): Json<ToolMetadataInput>) -> FnResult<Json<ToolMeta
pub fn download_prebuilt(
Json(input): Json<DownloadPrebuiltInput>,
) -> FnResult<Json<DownloadPrebuiltOutput>> {
let env = get_proto_environment()?;

check_supported_os_and_arch(
NAME,
&input.env,
&env,
permutations! [
HostOS::Linux => [HostArch::X64, HostArch::Arm64],
HostOS::MacOS => [HostArch::X64, HostArch::Arm64],
],
)?;

let version = input.env.version;
let version = input.context.version;

let arch = match input.env.arch {
let arch = match env.arch {
HostArch::Arm64 => "aarch64",
HostArch::X64 => "x64",
_ => unreachable!(),
};

let prefix = match input.env.os {
let prefix = match env.os {
HostOS::Linux => format!("bun-linux-{arch}"),
HostOS::MacOS => format!("bun-darwin-{arch}"),
_ => unreachable!(),
Expand All @@ -63,9 +65,11 @@ pub fn download_prebuilt(
}

#[plugin_fn]
pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBinsOutput>> {
pub fn locate_bins(Json(_): Json<LocateBinsInput>) -> FnResult<Json<LocateBinsOutput>> {
let env = get_proto_environment()?;

Ok(Json(LocateBinsOutput {
bin_path: Some(format_bin_name(BIN, input.env.os).into()),
bin_path: Some(format_bin_name(BIN, env.os).into()),
fallback_last_globals_dir: true,
globals_lookup_dirs: vec!["$HOME/.bun/bin".into()],
..LocateBinsOutput::default()
Expand Down Expand Up @@ -99,7 +103,7 @@ pub fn create_shims(Json(_): Json<CreateShimsInput>) -> FnResult<Json<CreateShim
pub fn install_global(
Json(input): Json<InstallGlobalInput>,
) -> FnResult<Json<InstallGlobalOutput>> {
let result = exec_command!(BIN, ["add", "--global", &input.dependency]);
let result = exec_command!(inherit, BIN, ["add", "--global", &input.dependency]);

Ok(Json(InstallGlobalOutput::from_exec_command(result)))
}
Expand All @@ -108,7 +112,7 @@ pub fn install_global(
pub fn uninstall_global(
Json(input): Json<UninstallGlobalInput>,
) -> FnResult<Json<UninstallGlobalOutput>> {
let result = exec_command!(BIN, ["remove", "--global", &input.dependency]);
let result = exec_command!(inherit, BIN, ["remove", "--global", &input.dependency]);

Ok(Json(UninstallGlobalOutput::from_exec_command(result)))
}
93 changes: 58 additions & 35 deletions tests/download_test.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
use proto_pdk_test_utils::*;
use starbase_sandbox::create_empty_sandbox;
use std::path::PathBuf;

#[cfg(not(windows))]
generate_download_install_tests!("bun-test", "0.6.0");

#[test]
fn supports_linux_arm64() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::Arm64,
os: HostOS::Linux,
..Default::default()
});

assert_eq!(
plugin.download_prebuilt(DownloadPrebuiltInput {
env: Environment {
arch: HostArch::Arm64,
os: HostOS::Linux,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
}
Expand All @@ -36,13 +39,17 @@ fn supports_linux_arm64() {
#[test]
fn supports_linux_x64() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::X64,
os: HostOS::Linux,
..Default::default()
});

assert_eq!(
plugin.download_prebuilt(DownloadPrebuiltInput {
env: Environment {
arch: HostArch::X64,
os: HostOS::Linux,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
}
Expand All @@ -64,13 +71,17 @@ fn supports_linux_x64() {
#[test]
fn supports_macos_arm64() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::Arm64,
os: HostOS::MacOS,
..Default::default()
});

assert_eq!(
plugin.download_prebuilt(DownloadPrebuiltInput {
env: Environment {
arch: HostArch::Arm64,
os: HostOS::MacOS,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
}
Expand All @@ -92,13 +103,17 @@ fn supports_macos_arm64() {
#[test]
fn supports_macos_x64() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::X64,
os: HostOS::MacOS,
..Default::default()
});

assert_eq!(
plugin.download_prebuilt(DownloadPrebuiltInput {
env: Environment {
arch: HostArch::X64,
os: HostOS::MacOS,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
}
Expand All @@ -121,12 +136,16 @@ fn supports_macos_x64() {
#[should_panic(expected = "Unable to install Bun")]
fn doesnt_support_windows() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::X64,
os: HostOS::Windows,
..Default::default()
});

plugin.download_prebuilt(DownloadPrebuiltInput {
env: Environment {
arch: HostArch::X64,
os: HostOS::Windows,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
},
Expand All @@ -136,19 +155,21 @@ fn doesnt_support_windows() {
#[test]
fn locates_unix_bin() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::Arm64,
os: HostOS::Linux,
..Default::default()
});

assert_eq!(
plugin
.locate_bins(LocateBinsInput {
env: Environment {
arch: HostArch::Arm64,
os: HostOS::Linux,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
},
home_dir: PathBuf::new(),
tool_dir: PathBuf::new()
}
})
.bin_path,
Some("bun".into())
Expand All @@ -158,19 +179,21 @@ fn locates_unix_bin() {
#[test]
fn locates_windows_bin() {
let sandbox = create_empty_sandbox();
let plugin = create_plugin("bun-test", sandbox.path());
let mut plugin = create_plugin("bun-test", sandbox.path());

plugin.set_environment(HostEnvironment {
arch: HostArch::X64,
os: HostOS::Windows,
..Default::default()
});

assert_eq!(
plugin
.locate_bins(LocateBinsInput {
env: Environment {
arch: HostArch::X64,
os: HostOS::Windows,
context: ToolContext {
version: "1.2.0".into(),
..Default::default()
},
home_dir: PathBuf::new(),
tool_dir: PathBuf::new()
}
})
.bin_path,
Some("bun.exe".into())
Expand Down

0 comments on commit 34fe37b

Please sign in to comment.