Skip to content
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

feat(bun): support bun.lock #9783

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

chris-olszewski
Copy link
Member

@chris-olszewski chris-olszewski commented Jan 23, 2025

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:

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.

Copy link

vercel bot commented Jan 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-designsystem-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-gatsby-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-kitchensink-blog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-svelte-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 9:39pm

@chris-olszewski chris-olszewski force-pushed the chrisolszewski/turbo-4268-warning-when-using-text-based-bun-lockfile branch from 7400701 to f50149a Compare January 24, 2025 00:59
@chris-olszewski chris-olszewski marked this pull request as ready for review January 24, 2025 01:41
@chris-olszewski chris-olszewski requested a review from a team as a code owner January 24, 2025 01:41
@nicksrandall
Copy link

This is a great step toward support turbo prune with bun's new text based lock file.

Copy link
Contributor

@NicholasLYang NicholasLYang left a comment

Choose a reason for hiding this comment

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

A couple notes. The biome -> serde setup could potentially be cleaner, but otherwise looks good!

// npm -> [
// "name@version",
// registry (TODO: remove if default),
// INFO,
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, this is the structure of a package entry? Bun stores it in an array? And what is the .bun-tag?

Copy link
Member Author

Choose a reason for hiding this comment

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

To clarify, this is the structure of a package entry? Bun stores it in an array?

Yes these are the various variants of a package entry according to this comment

And what is the .bun-tag?

It seems to be a special string, I haven't found where it is generated.

}

fn less_specific_key(key: &str) -> Option<&str> {
let slash_idx = key.find('/')?;
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit: split_once might work better here

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of those cases where might need a str that includes the / I split on so I feel like find is a little easier to work with here.

// TODO
}
let syntax_tree = parsed_json.syntax();
let format = biome_json_formatter::format_node(
Copy link
Contributor

Choose a reason for hiding this comment

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

if you want a slightly shorter trip, I think you can use biome_deserialize to get a serde_json::Value, then use serde to deserialize that into BunLockfile.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not seeing serde_json::Value as being supported by biome_deserialize.

@XavierGeerinck
Copy link

Big thanks to @chris-olszewski for working on this!!! Can't wait to have this in a release

@isaacharrisholt
Copy link

Hey, is there anything that could be done to help move this along? We use Bun with Turbo and the conversion to a Yarn lockfile has some issues (whether it's on Bun's side or Turbo's, I'm not sure - #9628), which means we can't use Turbo reliably in our Dockerfiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning when using text-based Bun lockfile
5 participants