From 2dd33f90909086d1a622a9aefe52c706e54e4f1f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Sat, 6 Apr 2024 19:58:55 -0700 Subject: [PATCH] new: Support `dist-url` setting. (#25) --- CHANGELOG.md | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 9 ++++++++- src/config.rs | 14 ++++++++++++++ src/lib.rs | 2 ++ src/proto.rs | 21 +++++++++++++-------- 7 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/config.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 172c6a1..e9e9dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.11.1 + +#### 🚀 Updates + +- Added a `dist-url` config setting, allowing the download host to be customized. + ## 0.11.0 #### 🚀 Updates diff --git a/Cargo.lock b/Cargo.lock index ae2bfc3..e769dc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -229,7 +229,7 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bun_plugin" -version = "0.11.0" +version = "0.11.1" dependencies = [ "extism-pdk", "proto_pdk", diff --git a/Cargo.toml b/Cargo.toml index 4e491bc..ee276e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bun_plugin" -version = "0.11.0" +version = "0.11.1" edition = "2021" license = "MIT" publish = false diff --git a/README.md b/README.md index 650f66d..497a271 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,14 @@ bun = "source:https://github.com/moonrepo/bun-plugin/releases/download/vX.Y.Z/bu ## Configuration -Bun plugin does not support configuration. +Bun plugin can be configured with a `.prototools` file. + +- `dist-url` (string) - The distribution URL to download Bun archives from. Supports `{version}` and `{file}` tokens. + +```toml +[tools.bun] +dist-url = "https://..." +``` ## Hooks diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..ebca197 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,14 @@ +#[derive(Debug, serde::Deserialize, serde::Serialize)] +#[serde(default, deny_unknown_fields, rename_all = "kebab-case")] +pub struct BunPluginConfig { + pub dist_url: String, +} + +impl Default for BunPluginConfig { + fn default() -> Self { + Self { + dist_url: "https://github.com/oven-sh/bun/releases/download/bun-v{version}/{file}" + .into(), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 8ec8133..3dd7a18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +mod config; + #[cfg(feature = "wasm")] mod proto; diff --git a/src/proto.rs b/src/proto.rs index f21833d..d6daa07 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -1,3 +1,4 @@ +use crate::config::BunPluginConfig; use extism_pdk::*; use proto_pdk::*; use std::collections::HashMap; @@ -73,6 +74,7 @@ pub fn download_prebuilt( if env.arch == HostArch::X64 && env.os == HostOS::Linux && command_exists(&env, "grep") { let output = exec_command!("grep", ["avx2", "/proc/cpuinfo"]); + if output.exit_code != 0 { avx2_suffix = "-baseline"; } @@ -86,24 +88,27 @@ pub fn download_prebuilt( }; let filename = format!("{prefix}.zip"); + let mut host = get_tool_config::()?.dist_url; - let tag = if version.is_canary() { - "canary".to_owned() - } else { - format!("bun-v{version}") + // canary - bun-v1.2.3 + if version.is_canary() { + host = host.replace("bun-v{version}", "{version}"); }; Ok(Json(DownloadPrebuiltOutput { archive_prefix: Some(prefix), - download_url: format!("https://github.com/oven-sh/bun/releases/download/{tag}/{filename}"), + download_url: host + .replace("{version}", &version.to_string()) + .replace("{file}", &filename), download_name: Some(filename), // Checksums are not consistently updated checksum_url: if version.is_canary() { None } else { - Some(format!( - "https://github.com/oven-sh/bun/releases/download/{tag}/SHASUMS256.txt" - )) + Some( + host.replace("{version}", &version.to_string()) + .replace("{file}", "SHASUMS256.txt"), + ) }, ..DownloadPrebuiltOutput::default() }))