Skip to content

Commit 1240cd4

Browse files
feat(bun): support bun.lock (#9783)
### Description Closes #9628 Switch over from our usage of `yarn.lock` and directly support `bun.lock` parsing. We use `biome` to strip out the trailing commas that appear in the `workspaces` and `packages` objects to leverage `serde` which I am more competent in. We can switch to `biome` in the future and avoid a second pass, but I do not know how to do correct deserialization logic for `PackageEntry` (see `de.rs` for examples of what this looks like) in `biome`. I will call out is the fact that the lockfile keys in `bun.lock` aren't used directly unlike other lockfile implementation. Instead we use resolved package identifiers e.g. `package@(protocol:)?version`. The keys themselves can shift when the underlying package does not change resulting in incorrect behavior. A quick example to illustrate: - `a` depends on `[email protected]` - `b` depends on `[email protected]` - `[email protected]` will get they key of `shared` since `a` is before `b` - `[email protected]` will get a key of `b/shared` - If `a` updates to `[email protected]`, then the `shared` key will now point to `[email protected]` - If we used the key instead of the ident we would rebuild `b` since it's key changed from `b/shared` to `shared` and not rebuild `a` since it's key remained `shared` This PR does not add support for `turbo prune`. Reviewing each commit on it's own would probably be helpful. ### Testing Instructions Unit tests. Manual testing on a `create-turbo` repository.
1 parent 7d804ad commit 1240cd4

File tree

16 files changed

+1748
-436
lines changed

16 files changed

+1748
-436
lines changed

Cargo.lock

+95-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ biome_console = { version = "0.5.7" }
8888
biome_deserialize = { version = "0.6.0", features = ["serde"] }
8989
biome_deserialize_macros = { version = "0.6.0" }
9090
biome_diagnostics = { version = "0.5.7" }
91+
biome_formatter = { version = "0.5.7" }
9192
biome_json_parser = { version = "0.5.7" }
93+
biome_json_formatter = { version = "0.5.7" }
9294
biome_json_syntax = { version = "0.5.7" }
9395
bytes = "1.1.0"
9496
camino = { version = "1.1.4", features = ["serde1"] }

crates/turborepo-errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ license = "MIT"
99
[dependencies]
1010
biome_deserialize = { workspace = true }
1111
biome_diagnostics = { workspace = true }
12+
biome_json_parser = { workspace = true }
1213
miette = { workspace = true }
1314
serde = { workspace = true, features = ["derive"] }
1415
thiserror = { workspace = true }

crates/turborepo-errors/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ pub struct ParseDiagnostic {
3030
label: Option<SourceSpan>,
3131
}
3232

33-
struct BiomeMessage<'a>(&'a biome_diagnostics::Error);
33+
struct BiomeMessage<'a, T: ?Sized>(&'a T);
3434

35-
impl Display for BiomeMessage<'_> {
35+
impl<T: biome_diagnostics::Diagnostic + ?Sized> Display for BiomeMessage<'_, T> {
3636
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3737
self.0.description(f)
3838
}
3939
}
4040

41-
impl From<biome_diagnostics::Error> for ParseDiagnostic {
42-
fn from(diagnostic: biome_diagnostics::Error) -> Self {
41+
impl<T: biome_diagnostics::Diagnostic + ?Sized> From<&'_ T> for ParseDiagnostic {
42+
fn from(diagnostic: &T) -> Self {
4343
let location = diagnostic.location();
44-
let message = BiomeMessage(&diagnostic).to_string();
44+
let message = BiomeMessage(diagnostic).to_string();
4545
let path = location
4646
.resource
4747
.and_then(|r| r.as_file().map(|p| p.to_string()))

crates/turborepo-lib/src/turbo_json/parser.rs

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl RawTurboJson {
199199
.map(|d| {
200200
d.with_file_source_code(text)
201201
.with_file_path(file_path)
202+
.as_ref()
202203
.into()
203204
})
204205
.collect();

crates/turborepo-lockfiles/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ license = "MIT"
1010
workspace = true
1111

1212
[dependencies]
13+
biome_formatter = { workspace = true }
14+
biome_json_formatter = { workspace = true }
15+
biome_json_parser = { workspace = true }
16+
itertools = { workspace = true }
1317
nom = "7"
1418
pest = "2.7.9"
1519
pest_derive = "2.7.9"
@@ -22,8 +26,8 @@ serde_yaml = "0.9.27"
2226
thiserror = "1.0.38"
2327
tracing.workspace = true
2428
turbopath = { path = "../turborepo-paths" }
29+
turborepo-errors = { workspace = true }
2530

2631
[dev-dependencies]
27-
itertools = { workspace = true }
2832
pretty_assertions = "1.3"
2933
test-case = "3.1.0"

0 commit comments

Comments
 (0)