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(core): add bun package manager #22602

Merged
merged 1 commit into from
May 22, 2024

Conversation

Jordan-Hall
Copy link
Contributor

@Jordan-Hall Jordan-Hall commented Apr 2, 2024

Bun uses yarn lock for it's binary file. Running the binary will produce the content of a yarn lock file (v1)

Other option is to use the -y command on add and install. This will create a yarn lock file and then createLockFile can just modify the yarn.lock file instead?

This is the PR made from #19113 and pushed due to #22402 being closed.

PS Bun feels more stable since the PR was first created!

This PR will resolve #22283 and start of #21075

@Jordan-Hall Jordan-Hall requested review from meeroslav and a team as code owners April 2, 2024 00:41
Copy link

vercel bot commented Apr 2, 2024

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview May 22, 2024 2:58pm

if (packageManager === 'bun') {
output.log({
title:
"Unable to create bun lock files. Run bun install it's just as quick",
Copy link
Contributor Author

@Jordan-Hall Jordan-Hall Apr 2, 2024

Choose a reason for hiding this comment

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

@edbzn Would it be worth calling stringifyYarnLockfile? But would have to edit how it is created into a file because it is a self-executable file

Copy link
Contributor Author

@Jordan-Hall Jordan-Hall Apr 2, 2024

Choose a reason for hiding this comment

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

My thinking is moving the following into a util

const lockFile = createLockFile(
      builtPackageJson,
      context.projectGraph,
      packageManager
    );
    writeFileSync(
      `${outDirRelativeToWorkspaceRoot}/${getLockFileName(packageManager)}`,
      lockFile,
      {
        encoding: 'utf-8',
      }
    );

its duplicated code but run IF check for bun and use the bun CLI to generate the binary file

Copy link
Contributor

Choose a reason for hiding this comment

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

Worth asking @meeroslav, he knows best how to deal with lockfiles

Copy link
Member

Choose a reason for hiding this comment

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

We should reuse stringifyYarnLockfile to parse the file, as long as it handles bun-specific strings: # bun at the top, and version "workspace:<proj>" if using bun workspaces.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since there doesn't seem to be a way to generate bun.lockb without running the install, I would use the stringifyYarnLockfile to be as close as possible to the intended package versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm looking at generating the binary file. Happy to update snapshot so this can go in and work on that after? Also love to get involved in adding runtime and bun test. I have plugin that does it for now, but be nice if NX can add native support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaysoo If you want to make the yarn.lock a follow up then I think this PR is completed?

Copy link

Choose a reason for hiding this comment

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

I reused Yarn in my PR bro. They still had problems with it. The people want Bun support!

If it builds and runs, then that's a start.

Help us brothers out for taking the time to do this for you.

It was my birthday btw when I built a working version for your project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is different, this is to handle the manual creation of lock files not the reading of the lock file. Nx team doing a great job BTW, they been so many unstable issues. The chunk of this was taken from my PR back in Sep 11, 2023. But I closed it due to Bun having too many bugs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@laynef you can always use nx-bun to get started for now

@Jordan-Hall
Copy link
Contributor Author

cc: @JamesHenry

@Jordan-Hall
Copy link
Contributor Author

I was working in WSL. I'll fix the test in the morning on my Linux laptop

@Jordan-Hall Jordan-Hall force-pushed the feat/add-bun-packagemanager branch from 743444b to b90d256 Compare April 2, 2024 08:03
Copy link
Collaborator

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this @Jordan-Hall!

We will need some e2e coverage in addition to the comments

e2e/utils/get-env-info.ts Outdated Show resolved Hide resolved
packages/create-nx-workspace/src/internal-utils/prompts.ts Outdated Show resolved Hide resolved
packages/create-nx-workspace/src/utils/package-manager.ts Outdated Show resolved Hide resolved
packages/nx/src/utils/package-manager.ts Outdated Show resolved Hide resolved
packages/nx/src/utils/package-manager.ts Outdated Show resolved Hide resolved
packages/nx/src/utils/package-manager.ts Outdated Show resolved Hide resolved
packages/create-nx-workspace/src/utils/package-manager.ts Outdated Show resolved Hide resolved
packages/nx/src/plugins/js/index.ts Outdated Show resolved Hide resolved
packages/nx/src/plugins/js/index.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@FrozenPandaz FrozenPandaz left a comment

Choose a reason for hiding this comment

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

Thank you for your work here! 👍

@benpsnyder
Copy link
Contributor

image

We are setting aside resources in the coming weeks to battle test bun in our repos with Nx and we'll submit PRs and open issues as necessary. Very excited about this. Thanks to all

@Jordan-Hall
Copy link
Contributor Author

I've had bun test working with NX it really good. Happy to help get a plugin in NX to support both runtime and tests. Would need guidance though by the team. I feel the node should turn into runtime and work with node and bun at least the generators

@Jordan-Hall
Copy link
Contributor Author

@FrozenPandaz I think this is ready now. Let me know if you have any queries or any more issues :)

@jaysoo
Copy link
Member

jaysoo commented May 22, 2024

@jaysoo are you on slack or discord. I'm confused why this is failing. Build and lint ok. Looks to me its a codeowner issue

Yes, I'm on Discord. I'll take a look at the errors now and try to push a fix.

Bun uses yarn lock for it's binary file. Running the binary will produce the content of a yarn lock file (v1)

feat(core): update new generator schema for bun and fix workspaces setup for bun

fix(core): update ci-workflow snapshot
feat(core): check lock file for bunlock on push

Signed-off-by: Jordan Hall <[email protected]>

fix(core): add bun as a valid option of packageManager for preset generator

fix(repo): make registry optional because of bun

fix: handle where get registry is optional
@jaysoo
Copy link
Member

jaysoo commented May 22, 2024

Trying a run here to see if it'll go green #25066

Need to debug further on why CI is failing.

@Jordan-Hall
Copy link
Contributor Author

Trying a run here to see if it'll go green #25066

Need to debug further on why CI is failing.

Thank you. I'm around now on laptop if you need anything

@jaysoo jaysoo force-pushed the feat/add-bun-packagemanager branch from d2416d7 to 631c414 Compare May 22, 2024 18:48
@Jordan-Hall
Copy link
Contributor Author

Yes yes yes @jaysoo merge before it goes again 🤣

@jaysoo
Copy link
Member

jaysoo commented May 22, 2024

Pushed a WIP PR to see how e2e tests are when we force Bun, since they are running with pnpm right now. If things are green or mostly green then we're good to go.

@Jordan-Hall
Copy link
Contributor Author

Can I ask what the issue was with the ci :/ be good for future reference if I make anymore prs

@jaysoo
Copy link
Member

jaysoo commented May 22, 2024

We'll need a follow-up to make sure that --generatePackageJson for executors that support it won't error out due to missing lockfiles. For Bun, we'll just skip the lockfile for now, and discuss whether generating yarn.lock file would be preferable.

This is the code we need to fix: https://github.com/nrwl/nx/blob/master/packages/js/src/utils/package-json/update-package-json.ts#L106-L118.

@jaysoo jaysoo merged commit 80702b5 into nrwl:master May 22, 2024
7 checks passed
@Jordan-Hall
Copy link
Contributor Author

We'll need a follow-up to make sure that --generatePackageJson for executors that support it won't error out due to missing lockfiles. For Bun, we'll just skip the lockfile for now, and discuss whether generating yarn.lock file would be preferable.

This is the code we need to fix: https://github.com/nrwl/nx/blob/master/packages/js/src/utils/package-json/update-package-json.ts#L106-L118.

Happy to make that PR later

@jaysoo
Copy link
Member

jaysoo commented May 22, 2024

Here's the PR :)

#25158

@jaysoo
Copy link
Member

jaysoo commented May 23, 2024

You can try this now in canary.

npx create-nx-workspace@canary --packageManager=bun

@Jordan-Hall Jordan-Hall deleted the feat/add-bun-packagemanager branch May 23, 2024 14:53
@benpsnyder
Copy link
Contributor

First issue filed. Going to spend some hours debugging this and will post findings there.

When using Bun and building within Dockerfile - Failed to process project graph. Run "nx reset" to fix this.' re: 'nx/js/dependencies-and-lockfile (#25965)

Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bun.js Support