这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(bun): bun prune support #10175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 0 additions & 9 deletions crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub enum Error {
MissingWorkspace(PackageName),
#[error("Cannot prune without parsed lockfile.")]
MissingLockfile,
#[error("`prune` is not supported for Bun.")]
BunUnsupported,
#[error("Unable to read config: {0}")]
Config(#[from] crate::config::Error),
}
Expand Down Expand Up @@ -106,13 +104,6 @@ pub async fn prune(

let prune = Prune::new(base, scope, docker, output_dir, use_gitignore, telemetry).await?;

if matches!(
prune.package_graph.package_manager(),
turborepo_repository::package_manager::PackageManager::Bun
) {
return Err(Error::BunUnsupported);
}

println!(
"Generating pruned monorepo for {} in {}",
base.color_config.apply(BOLD.apply_to(scope.join(", "))),
Expand Down
70 changes: 60 additions & 10 deletions crates/turborepo-lockfiles/src/bun/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::VecDeque;
use serde::Deserialize;

use super::{PackageEntry, PackageInfo};
use crate::bun::RootInfo;
// Comment explaining entry schemas taken from bun.lock.zig
// first index is resolution for each type of package
// npm -> [
Expand Down Expand Up @@ -32,6 +33,8 @@ impl<'de> Deserialize<'de> for PackageEntry {
Info(Box<PackageInfo>),
}
let mut vals = VecDeque::<Vals>::deserialize(deserializer)?;

// First value is always the package key
let key = vals
.pop_front()
.ok_or_else(|| de::Error::custom("expected package entry to not be empty"))?;
Expand All @@ -44,22 +47,53 @@ impl<'de> Deserialize<'de> for PackageEntry {
Vals::Str(_) => None,
Vals::Info(package_info) => Some(*package_info),
};
// For workspace packages deps are second element, rest have them as third
// element
let info = vals
.pop_front()
.and_then(val_to_info)
.or_else(|| vals.pop_front().and_then(val_to_info));

let mut registry = None;
let mut info = None;

// Special case: root packages have a unique second value, so we handle it here
if key.ends_with("@root:") {
let root = vals.pop_front().and_then(|val| {
serde_json::from_value::<RootInfo>(match val {
Vals::Info(info) => {
serde_json::to_value(info.other).expect("failed to convert info to value")
}
_ => return None,
})
.ok()
});
return Ok(Self {
ident: key,
info,
registry,
checksum: None,
root,
});
}

// The second value can be either registry (string) or info (object)
if let Some(val) = vals.pop_front() {
match val {
Vals::Str(reg) => registry = Some(reg),
Vals::Info(package_info) => info = Some(*package_info),
}
};

// Info will be next if we haven't already found it
if info.is_none() {
info = vals.pop_front().and_then(val_to_info);
}

// Checksum is last
let checksum = vals.pop_front().and_then(|val| match val {
Vals::Str(sha) => Some(sha),
Vals::Info(_) => None,
});

Ok(Self {
ident: key,
info,
// The rest are only necessary for serializing a lockfile and aren't needed until adding
// `prune` support
registry: None,
registry,
checksum,
root: None,
})
Expand Down Expand Up @@ -114,7 +148,7 @@ mod test {
PackageEntry,
PackageEntry {
ident: "is-odd@3.0.1".into(),
registry: None,
registry: Some("".into()),
info: Some(PackageInfo {
dependencies: Some(("is-number".into(), "^6.0.0".into()))
.into_iter()
Expand Down Expand Up @@ -142,10 +176,26 @@ mod test {
root: None,
}
);

fixture!(
root_pkg,
PackageEntry,
PackageEntry {
ident: "some-package@root:".into(),
root: Some(RootInfo {
bin: Some("bin".into()),
bin_dir: Some("binDir".into()),
}),
info: None,
registry: None,
checksum: None,
}
);
#[test_case(json!({"name": "bun-test", "devDependencies": {"turbo": "^2.3.3"}}), basic_workspace() ; "basic")]
#[test_case(json!({"name": "docs", "version": "0.1.0"}), workspace_with_version() ; "with version")]
#[test_case(json!(["is-odd@3.0.1", "", {"dependencies": {"is-number": "^6.0.0"}}, "sha"]), registry_pkg() ; "registry package")]
#[test_case(json!(["docs", {"dependencies": {"is-odd": "3.0.1"}}]), workspace_pkg() ; "workspace package")]
#[test_case(json!(["some-package@root:", {"bin": "bin", "binDir": "binDir"}]), root_pkg() ; "root package")]
fn test_deserialization<T: for<'a> Deserialize<'a> + PartialEq + std::fmt::Debug>(
input: serde_json::Value,
expected: &T,
Expand Down
Loading
Loading