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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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

Copy link

vercel bot commented Apr 2, 2024

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

Name Status Preview Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview May 9, 2024 6:51pm

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

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

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

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
@Jordan-Hall Jordan-Hall force-pushed the feat/add-bun-packagemanager branch 5 times, most recently from 3f7800c to 9362912 Compare April 9, 2024 23:39
@Jordan-Hall
Copy link
Contributor Author

So latest pr revase broke it again -_- let me know when you want this in / ready and I'll fix it again.

@fahslaj fahslaj assigned jaysoo and unassigned fahslaj Apr 10, 2024
@Jordan-Hall Jordan-Hall force-pushed the feat/add-bun-packagemanager branch 3 times, most recently from 2f28cfb to 57480d9 Compare April 12, 2024 12:20
@Jordan-Hall Jordan-Hall force-pushed the feat/add-bun-packagemanager branch 2 times, most recently from 761923f to fe4ef4a Compare April 16, 2024 11:49
@jaysoo
Copy link
Member

jaysoo commented Apr 16, 2024

So latest pr revase broke it again -_- let me know when you want this in / ready and I'll fix it again.

Looks like it's green now. I'll do more testing on it, it looked good during my last test. If it's good, we can probably get it in for Nx 19.

@Jordan-Hall
Copy link
Contributor Author

So latest pr revase broke it again -_- let me know when you want this in / ready and I'll fix it again.

Looks like it's green now. I'll do more testing on it, it looked good during my last test. If it's good, we can probably get it in for Nx 19.

Thank you. Let me know if you find any issues. Next stop bun executors 😅

@enaluz
Copy link

enaluz commented Apr 17, 2024

Is there an ETA on when this can be merged in and be usable? I'm starting a new React/React Native project for my company this week or next and I really want to use Bun + Nx 👀

If I decided to go with an alternative package manager just to get the project started (like pnpm for example), would it involve significant overhead to switch over to Bun?

@mehrangta
Copy link

Is there an ETA on when this can be merged in and be usable? I'm starting a new React/React Native project for my company this week or next and I really want to use Bun + Nx 👀

If I decided to go with an alternative package manager just to get the project started (like pnpm for example), would it involve significant overhead to switch over to Bun?

As far as I know, bun cannot change pnpm lockfile to bun lockfile. so I would choose classic npm to start with. (also workspaces in pnpm are a little bit different too)

@jaysoo
Copy link
Member

jaysoo commented Apr 17, 2024

Pushed one more fix and doing more testing. We're ready to merge Nx 19 features, so we should be merging this very soon.

@jaysoo
Copy link
Member

jaysoo commented Apr 30, 2024

Quick update on this PR, we are planning to include this in Nx 19.1 rather than 19. The reason is that Nx 19 is a stability release to address some issues around Project Crystal, so we're pushing some new features to Nx 19.1, including Bun.

Jordan-Hall and others added 4 commits May 9, 2024 19:43
Bun uses yarn lock for it's binary file. Running the binary will produce the content of a yarn lock file (v1)
feat(core): check lock file for bunlock on push

Signed-off-by: Jordan Hall <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bun.js Support
10 participants