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

Commit

Permalink
new: Support dist-url setting. (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj authored Apr 7, 2024
1 parent d512043 commit 2dd33f9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bun_plugin"
version = "0.11.0"
version = "0.11.1"
edition = "2021"
license = "MIT"
publish = false
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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(),
}
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod config;

#[cfg(feature = "wasm")]
mod proto;

Expand Down
21 changes: 13 additions & 8 deletions src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::config::BunPluginConfig;
use extism_pdk::*;
use proto_pdk::*;
use std::collections::HashMap;
Expand Down Expand Up @@ -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";
}
Expand All @@ -86,24 +88,27 @@ pub fn download_prebuilt(
};

let filename = format!("{prefix}.zip");
let mut host = get_tool_config::<BunPluginConfig>()?.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()
}))
Expand Down

0 comments on commit 2dd33f9

Please sign in to comment.