Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/backend/platform_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,39 @@ impl PlatformTarget {
self.platform.to_key()
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_platform_target_creation() {
let platform = Platform::parse("linux-x64").unwrap();
let target = PlatformTarget::new(platform.clone());

assert_eq!(target.platform, platform);
assert_eq!(target.os_name(), "linux");
assert_eq!(target.arch_name(), "x64");
assert_eq!(target.qualifier(), None);
assert_eq!(target.to_key(), "linux-x64");
}

#[test]
fn test_platform_target_with_qualifier() {
let platform = Platform::parse("linux-x64-musl").unwrap();
let target = PlatformTarget::new(platform);

assert_eq!(target.os_name(), "linux");
assert_eq!(target.arch_name(), "x64");
assert_eq!(target.qualifier(), Some("musl"));
assert_eq!(target.to_key(), "linux-x64-musl");
}

#[test]
fn test_from_current() {
let target = PlatformTarget::from_current();
let current_platform = Platform::current();

assert_eq!(target.platform, current_platform);
}
}
51 changes: 50 additions & 1 deletion src/plugins/core/bun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use crate::http::HTTP;
use crate::install_context::InstallContext;
use crate::toolset::ToolVersion;
use crate::ui::progress_report::SingleReport;
use crate::{backend::Backend, config::Config};
use crate::{
backend::{Backend, GitHubReleaseInfo, ReleaseType, platform_target::PlatformTarget},
config::Config,
};
use crate::{file, github, plugins};

#[derive(Debug)]
Expand Down Expand Up @@ -116,6 +119,52 @@ impl Backend for BunPlugin {

Ok(tv)
}

// ========== Lockfile Metadata Fetching Implementation ==========
Comment on lines +122 to +123

Copilot AI Sep 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove the extra blank line before the comment to maintain consistent spacing with the rest of the file.

Copilot uses AI. Check for mistakes.

async fn get_github_release_info(
&self,
tv: &ToolVersion,
target: &PlatformTarget,
) -> Result<Option<GitHubReleaseInfo>> {
let version = &tv.version;

// Build the asset pattern for Bun's GitHub releases
// Pattern: bun-{os}-{arch}.zip
let os_name = self.map_os_to_bun(target.os_name());
let arch_name = self.map_arch_to_bun(target.arch_name());
let asset_pattern = format!("bun-{os_name}-{arch_name}.zip");

Ok(Some(GitHubReleaseInfo {
repo: "oven-sh/bun".to_string(),
asset_pattern: Some(asset_pattern),
api_url: Some(format!(
"https://github.com/oven-sh/bun/releases/download/bun-v{version}"
)),
release_type: ReleaseType::GitHub,
}))
}
Comment thread
cursor[bot] marked this conversation as resolved.
}

impl BunPlugin {
/// Map our platform OS names to Bun's naming convention
fn map_os_to_bun<'a>(&self, os: &'a str) -> &'a str {
match os {
"macos" => "darwin",
"linux" => "linux",
"windows" => "windows",
other => other,
}
}

/// Map our platform arch names to Bun's naming convention
fn map_arch_to_bun<'a>(&self, arch: &'a str) -> &'a str {
match arch {
"x64" => "x64",
"arm64" | "aarch64" => "aarch64",
other => other,
}
}
}

fn os() -> &'static str {
Expand Down
64 changes: 63 additions & 1 deletion src/plugins/core/node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backend::{Backend, VersionCacheManager};
use crate::backend::{Backend, VersionCacheManager, platform_target::PlatformTarget};
use crate::build_time::built_info;
use crate::cache::CacheManagerBuilder;
use crate::cli::args::BackendArg;
Expand Down Expand Up @@ -534,6 +534,68 @@ impl Backend for NodePlugin {
})
.clone()
}

// ========== Lockfile Metadata Fetching Implementation ==========
Comment on lines +537 to +538

Copilot AI Sep 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Remove the extra blank line before the comment to maintain consistent spacing with the rest of the file.

Copilot uses AI. Check for mistakes.

async fn get_tarball_url(
&self,
tv: &ToolVersion,
target: &PlatformTarget,
) -> Result<Option<String>> {
let version = &tv.version;
let settings = Settings::get();

// Build platform-specific filename like Node.js does
let slug = self.build_platform_slug(version, target);
let filename = if target.os_name() == "windows" {
format!("{slug}.zip")
} else {
format!("{slug}.tar.gz")
};

// Use Node.js mirror URL to construct download URL
let url = settings
.node
.mirror_url()
.join(&format!("v{version}/{filename}"))
.map_err(|e| eyre::eyre!("Failed to construct Node.js download URL: {e}"))?;

Ok(Some(url.to_string()))
}
}

impl NodePlugin {
/// Build platform-specific slug for Node.js downloads
/// This mirrors the logic from BuildOpts::new() and slug() function
fn build_platform_slug(&self, version: &str, target: &PlatformTarget) -> String {
let settings = Settings::get();

// Map Platform enum to Node.js OS names
let os = match target.os_name() {
"macos" => "darwin",
"linux" => "linux",
"windows" => "win32",
other => other,

Copilot AI Sep 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider logging a warning when encountering unknown OS names to help with debugging platform mapping issues.

Suggested change
other => other,
other => {
eprintln!(
"Warning: Unknown OS name '{}' encountered in Node.js platform mapping. Passing through as-is.",
other
);
other
},

Copilot uses AI. Check for mistakes.
};
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

// Map Platform enum to Node.js arch names
let arch = match target.arch_name() {
"x86" => "x86",
"x64" => "x64",
"arm" => "armv7l",
"arm64" => "arm64",
"aarch64" => "arm64",
"loongarch64" => "loong64",
"riscv64" => "riscv64",
other => other,

Copilot AI Sep 7, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider logging a warning when encountering unknown architecture names to help with debugging platform mapping issues.

Suggested change
other => other,
other => {
eprintln!(
"Warning: Unknown architecture name '{}' encountered in build_platform_slug for target: {:?}. Using as-is.",
other,
target
);
other
},

Copilot uses AI. Check for mistakes.
};

if let Some(flavor) = &settings.node.flavor {
format!("node-v{version}-{os}-{arch}-{flavor}")
} else {
format!("node-v{version}-{os}-{arch}")
}
}
}

#[derive(Debug)]
Expand Down
Loading