-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: Add Bun tier 1 support. (#1163)
* Add tier 1. * Update tests. * Bump version. * Fix tests.
- Loading branch information
Showing
82 changed files
with
436 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
releases: | ||
"@moonrepo/cli": minor | ||
"@moonrepo/core-linux-arm64-gnu": minor | ||
"@moonrepo/core-linux-arm64-musl": minor | ||
"@moonrepo/core-linux-x64-gnu": minor | ||
"@moonrepo/core-linux-x64-musl": minor | ||
"@moonrepo/core-macos-arm64": minor | ||
"@moonrepo/core-macos-x64": minor | ||
"@moonrepo/core-windows-x64-msvc": minor | ||
'@moonrepo/cli': minor | ||
'@moonrepo/core-linux-arm64-gnu': minor | ||
'@moonrepo/core-linux-arm64-musl': minor | ||
'@moonrepo/core-linux-x64-gnu': minor | ||
'@moonrepo/core-linux-x64-musl': minor | ||
'@moonrepo/core-macos-arm64': minor | ||
'@moonrepo/core-macos-x64': minor | ||
'@moonrepo/core-windows-x64-msvc': minor | ||
'@moonrepo/types': minor | ||
|
||
declined: | ||
- '@moonrepo/report' | ||
- '@moonrepo/runtime' | ||
- website |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use cached::proc_macro::cached; | ||
use miette::IntoDiagnostic; | ||
use moon_lang::LockfileDependencyVersions; | ||
use moon_utils::regex; | ||
use once_cell::sync::Lazy; | ||
use rustc_hash::FxHashMap; | ||
use yarn_lock_parser::{parse_str, Entry}; | ||
|
||
static REPLACE_WS_VERSION: Lazy<regex::Regex> = | ||
Lazy::new(|| regex::create_regex("version \"workspace:([^\"]+)\"").unwrap()); | ||
|
||
#[cached(result)] | ||
pub fn load_lockfile_dependencies( | ||
lockfile_text: String, | ||
) -> miette::Result<LockfileDependencyVersions> { | ||
let mut deps: LockfileDependencyVersions = FxHashMap::default(); | ||
|
||
// Lockfile explodes: https://github.com/robertohuertasm/yarn-lock-parser/issues/15 | ||
let mut lockfile_text = lockfile_text | ||
.lines() | ||
.filter_map(|line| { | ||
if line.starts_with("# bun") { | ||
None | ||
} else if line.contains("version \"workspace:") { | ||
Some( | ||
REPLACE_WS_VERSION | ||
.replace(line, "version \"0.0.0\"") | ||
.to_string(), | ||
) | ||
} else { | ||
Some(line.to_owned()) | ||
} | ||
}) | ||
.collect::<Vec<_>>() | ||
.join("\n"); | ||
|
||
lockfile_text.push('\n'); | ||
|
||
// Bun lockfiles are binary, but can be represented as text in Yarn v1 format! | ||
let entries: Vec<Entry> = parse_str(&lockfile_text).into_diagnostic()?; | ||
|
||
for entry in entries { | ||
// All workspace dependencies have empty integrities, so we will skip them | ||
if entry.integrity.is_empty() { | ||
continue; | ||
} | ||
|
||
let dep = deps.entry(entry.name.to_owned()).or_default(); | ||
dep.push(entry.integrity.to_owned()); | ||
} | ||
|
||
Ok(deps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "moon_bun_tool" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
moon_config = { path = "../../../nextgen/config" } | ||
moon_logger = { path = "../../core/logger" } | ||
moon_platform_runtime = { path = "../../../nextgen/platform-runtime" } | ||
moon_terminal = { path = "../../core/terminal" } | ||
moon_tool = { path = "../../core/tool" } | ||
miette = { workspace = true } | ||
proto_core = { workspace = true } | ||
rustc-hash = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use moon_config::BunConfig; | ||
use moon_logger::debug; | ||
use moon_platform_runtime::RuntimeReq; | ||
use moon_terminal::{print_checkpoint, Checkpoint}; | ||
use moon_tool::{async_trait, load_tool_plugin, use_global_tool_on_path, Tool}; | ||
use proto_core::{Id, ProtoEnvironment, Tool as ProtoTool, UnresolvedVersionSpec}; | ||
use rustc_hash::FxHashMap; | ||
use std::path::PathBuf; | ||
|
||
pub struct BunTool { | ||
pub config: BunConfig, | ||
|
||
pub global: bool, | ||
|
||
pub tool: ProtoTool, | ||
} | ||
|
||
impl BunTool { | ||
pub async fn new( | ||
proto: &ProtoEnvironment, | ||
config: &BunConfig, | ||
req: &RuntimeReq, | ||
) -> miette::Result<BunTool> { | ||
let mut bun = BunTool { | ||
config: config.to_owned(), | ||
global: false, | ||
tool: load_tool_plugin(&Id::raw("bun"), proto, config.plugin.as_ref().unwrap()).await?, | ||
}; | ||
|
||
if use_global_tool_on_path() || req.is_global() { | ||
bun.global = true; | ||
bun.config.version = None; | ||
} else { | ||
bun.config.version = req.to_spec(); | ||
}; | ||
|
||
Ok(bun) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Tool for BunTool { | ||
fn as_any(&self) -> &(dyn std::any::Any + Send + Sync) { | ||
self | ||
} | ||
|
||
fn get_bin_path(&self) -> miette::Result<PathBuf> { | ||
Ok(PathBuf::from("bun")) | ||
} | ||
|
||
async fn setup( | ||
&mut self, | ||
last_versions: &mut FxHashMap<String, UnresolvedVersionSpec>, | ||
) -> miette::Result<u8> { | ||
let mut installed = 0; | ||
|
||
let Some(version) = &self.config.version else { | ||
return Ok(installed); | ||
}; | ||
|
||
if self.global { | ||
debug!("Using global binary in PATH"); | ||
} else if self.tool.is_setup(version).await? { | ||
debug!("Bun has already been setup"); | ||
|
||
// When offline and the tool doesn't exist, fallback to the global binary | ||
} else if proto_core::is_offline() { | ||
debug!( | ||
"No internet connection and Bun has not been setup, falling back to global binary in PATH" | ||
); | ||
|
||
self.global = true; | ||
|
||
// Otherwise try and install the tool | ||
} else { | ||
let setup = match last_versions.get("bun") { | ||
Some(last) => version != last, | ||
None => true, | ||
}; | ||
|
||
if setup || !self.tool.get_tool_dir().exists() { | ||
print_checkpoint(format!("installing bun {version}"), Checkpoint::Setup); | ||
|
||
if self.tool.setup(version, false).await? { | ||
last_versions.insert("bun".into(), version.to_owned()); | ||
installed += 1; | ||
} | ||
} | ||
} | ||
|
||
self.tool.locate_globals_dir().await?; | ||
|
||
Ok(installed) | ||
} | ||
|
||
async fn teardown(&mut self) -> miette::Result<()> { | ||
self.tool.teardown().await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod bun_tool; | ||
|
||
pub use bun_tool::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.