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

Commit

Permalink
new: Update to latest PDK.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 11, 2023
1 parent d7f4831 commit 6db40b9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ crate-type = ['cdylib']

[dependencies]
extism-pdk = "0.3.3"
proto_pdk = "0.2.0"
proto_pdk = "0.2.1"
serde = "1.0.167"
44 changes: 9 additions & 35 deletions src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use extism_pdk::*;
use proto_pdk::*;
use serde::Deserialize;
use std::collections::HashMap;

static NAME: &str = "Bun";
Expand All @@ -27,7 +26,7 @@ pub fn download_prebuilt(
other => {
return Err(PluginError::UnsupportedArchitecture {
tool: NAME.into(),
arch: format!("{:?}", other),
arch: other.to_string(),
})?;
}
};
Expand All @@ -38,7 +37,7 @@ pub fn download_prebuilt(
other => {
return Err(PluginError::UnsupportedPlatform {
tool: NAME.into(),
platform: format!("{:?}", other),
platform: other.to_string(),
})?;
}
};
Expand All @@ -64,54 +63,29 @@ pub fn locate_bins(Json(input): Json<LocateBinsInput>) -> FnResult<Json<LocateBi
bin_path: Some(if input.env.os == HostOS::Windows {
format!("{}.exe", BIN) // Not supported yet
} else {
format!("{}", BIN)
BIN.to_owned()
}),
fallback_last_globals_dir: true,
globals_lookup_dirs: vec!["$HOME/.bun/bin".into()],
}))
}

#[derive(Deserialize)]
pub struct TagEntry {
name: String,
}

#[plugin_fn]
pub fn load_versions(Json(_): Json<LoadVersionsInput>) -> FnResult<Json<LoadVersionsOutput>> {
let mut output = LoadVersionsOutput::default();
let mut latest = Version::new(0, 0, 0);
let tags = load_git_tags("https://github.com/oven-sh/bun")?;

let response: Vec<TagEntry> = fetch_url("https://api.github.com/repos/oven-sh/bun/tags")?;
let tags = response
let tags = tags
.iter()
.filter_map(|entry| entry.name.strip_prefix("bun-v"))
.filter_map(|t| t.strip_prefix("bun-v").map(|t| t.to_owned()))
.collect::<Vec<_>>();

for tag in tags {
let version = Version::parse(tag)?;

if version > latest {
latest = version.clone();
}

output.versions.push(version);
}

output.aliases.insert("latest".into(), latest);

Ok(Json(output))
Ok(Json(LoadVersionsOutput::from_tags(&tags)?))
}

#[plugin_fn]
pub fn create_shims(Json(_): Json<CreateShimsInput>) -> FnResult<Json<CreateShimsOutput>> {
let mut global_shims = HashMap::new();

global_shims.insert(
"bunx".into(),
ShimConfig {
before_args: Some("x".into()),
..ShimConfig::default()
},
);
global_shims.insert("bunx".into(), ShimConfig::global_with_sub_command("x"));

Ok(Json(CreateShimsOutput {
global_shims,
Expand Down

0 comments on commit 6db40b9

Please sign in to comment.