Skip to content

Commit

Permalink
feat(bun): windows support (#3075)
Browse files Browse the repository at this point in the history
* feat(windows): windows support

* feat(bun): windows support
  • Loading branch information
jdx authored Nov 18, 2024
1 parent c0b60c8 commit 8b5d4b8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ btrace.backends = ["asdf:joschi/asdf-btrace"]
buf.backends = ["ubi:bufbuild/buf", "asdf:truepay/asdf-buf"]
buildpack.backends = ["asdf:johnlayton/asdf-buildpack"]
bun.backends = ["core:bun", "vfox:ahai-code/vfox-bun"]
bun.test = ["bun --version", "{{version}}"]
bundler.backends = ["asdf:jonathanmorley/asdf-bundler"]
cabal.backends = ["asdf:sestrella/asdf-ghcup"]
caddy.backends = ["aqua:caddyserver/caddy", "asdf:salasrod/asdf-caddy"]
Expand Down
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ mod tests {
fn test_dir_subdirs() {
reset();
let subdirs = dir_subdirs(&dirs::HOME).unwrap();
assert!(subdirs.contains(&"cwd".to_string()));
assert!(subdirs.contains("cwd"));
}

#[test]
Expand Down
33 changes: 22 additions & 11 deletions src/plugins/core/bun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::cli::version::{ARCH, OS};
use crate::cmd::CmdLineRunner;
use crate::github::GithubRelease;
use crate::http::{HTTP, HTTP_FETCH};
use crate::http::HTTP;
use crate::install_context::InstallContext;
use crate::toolset::{ToolRequest, ToolVersion};
use crate::ui::progress_report::SingleReport;
use crate::{file, plugins};
use crate::{file, github, plugins};

#[derive(Debug)]
pub struct BunPlugin {
Expand All @@ -29,7 +28,7 @@ impl BunPlugin {
}

fn bun_bin(&self, tv: &ToolVersion) -> PathBuf {
tv.install_path().join("bin/bun")
tv.install_path().join("bin").join(bun_bin_name())
}

fn test_bun(&self, ctx: &InstallContext) -> Result<()> {
Expand Down Expand Up @@ -66,11 +65,13 @@ impl BunPlugin {
ctx.tv
.download_path()
.join(format!("bun-{}-{}", os(), arch()))
.join("bun"),
.join(bun_bin_name()),
self.bun_bin(&ctx.tv),
)?;
file::make_executable(self.bun_bin(&ctx.tv))?;
file::make_symlink(Path::new("./bun"), &ctx.tv.install_path().join("bin/bunx"))?;
if cfg!(unix) {
file::make_executable(self.bun_bin(&ctx.tv))?;
file::make_symlink(Path::new("./bun"), &ctx.tv.install_path().join("bin/bunx"))?;
}
Ok(())
}

Expand All @@ -85,9 +86,7 @@ impl Backend for BunPlugin {
}

fn _list_remote_versions(&self) -> Result<Vec<String>> {
let releases: Vec<GithubRelease> =
HTTP_FETCH.json("https://api.github.com/repos/oven-sh/bun/releases?per_page=100")?;
let versions = releases
let versions = github::list_releases("oven-sh/bun")?
.into_iter()
.map(|r| r.tag_name)
.filter_map(|v| v.strip_prefix("bun-v").map(|v| v.to_string()))
Expand Down Expand Up @@ -129,8 +128,20 @@ fn arch() -> &'static str {
"x64-baseline"
}
} else if cfg!(target_arch = "aarch64") {
"aarch64"
if cfg!(windows) {
"x64"
} else {
"aarch64"
}
} else {
&ARCH
}
}

fn bun_bin_name() -> &'static str {
if cfg!(windows) {
"bun.exe"
} else {
"bun"
}
}
4 changes: 1 addition & 3 deletions src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::cli::args::BackendArg;
use crate::config::SETTINGS;
use crate::env;
use crate::env::PATH_KEY;
#[cfg(unix)]
use crate::plugins::core::bun::BunPlugin;
use crate::plugins::core::deno::DenoPlugin;
#[cfg(unix)]
Expand All @@ -24,7 +23,6 @@ use crate::plugins::core::zig::ZigPlugin;
use crate::timeout::run_with_timeout;
use crate::toolset::ToolVersion;

#[cfg(unix)]
mod bun;
mod deno;
#[cfg(unix)]
Expand Down Expand Up @@ -53,7 +51,7 @@ pub static CORE_PLUGINS: Lazy<BackendMap> = Lazy::new(|| {
];
#[cfg(windows)]
let plugins: Vec<Arc<dyn Backend>> = vec![
// Arc::new(BunPlugin::new()),
Arc::new(BunPlugin::new()),
Arc::new(DenoPlugin::new()),
// Arc::new(ErlangPlugin::new()),
Arc::new(GoPlugin::new()),
Expand Down

0 comments on commit 8b5d4b8

Please sign in to comment.