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

fix(core): allow text lockfile for bun #29423

Closed
wants to merge 4 commits into from

Conversation

ludicast
Copy link

@ludicast ludicast commented Dec 19, 2024

Current Behavior

Nx does not respect a bun.lock, which is the new lockfile for bun (currently available and to be the default in bun 1.2)

The text-lockfile will allow dependabot to run, as well as prevent the merge conflicts caused with a binary lockfile.

Expected Behavior

Nx will respect a bun.lock

Note that we are still defaulting to the bun.lockb style here for generators, this is just to allow repos containing bun.lock. After bun.lock becomes the default there should be a second PR to make it the default for generators.

Related Issue(s)

Fixes #29422

Copy link

vercel bot commented Dec 19, 2024

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

Name Status Preview Updated (UTC)
nx-dev ❌ Failed (Inspect) Feb 14, 2025 11:14am

Copy link

nx-cloud bot commented Dec 19, 2024

View your CI Pipeline Execution ↗ for commit a594c26.

Command Status Duration Result
nx documentation ❌ Failed 1m 46s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-14 11:16:51 UTC

@ludicast
Copy link
Author

cc @Jordan-Hall

return existsSync(join(dir, 'bun.lockb'))
? 'bun'
: existsSync(join(dir, 'yarn.lock'))
return existsSync(join(dir, 'yarn.lock'))
? 'yarn'
Copy link
Author

Choose a reason for hiding this comment

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

made yarn the first lockfile just to make the bun/pnpm indentation identical for multiple lockfiles

Copy link
Contributor

Choose a reason for hiding this comment

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

e bun/pnpm indentation identical for multiple lockfiles

Doesnt bun current support to yarn lock still, This is why bun came frist

Copy link
Author

Choose a reason for hiding this comment

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

right, great point, will reverse

@Jordan-Hall
Copy link
Contributor

Jordan-Hall commented Dec 19, 2024

@ludicast This is a good start but personally I would change the interface. We need to keep bun lock first because bun still goes to yarn with additional parm.

I think its best to include a parser and writer as part of this PR.

I did some work on this in preparation a while ago. Feel free to take a look at interface changes

#28119

It also a branch from #27820 to add bun pack @ludicast can you add pack support too.

@Jordan-Hall
Copy link
Contributor

Added the PR back for pack as their no breaking change. #29426 I should of never pulled the PR tbf

@ludicast
Copy link
Author

ludicast commented Dec 19, 2024

@ludicast This is a good start but personally I would change the interface. We need to keep bun lock first because bun still goes to yarn with additional parm.

thanks for info - changed the ordering back

I think its best to include a parser and writer as part of this PR.

we could but was thinking for that as a follow-on. I believe the format is jsonc (which isn't compatible with json.parse in vanilla js) so might want to avoid dealing with that in this PR (though now thinking that nx does parse a similar style in schemas anyways). esp the part of writing that lockfile (since .lock is a few days old and might surprise folks).

I did some work on this in preparation a while ago. Feel free to take a look at interface changes

thanks @Jordan-Hall - gave it a look


update - guess I prob can use the json-c parser if installed then

import { parse, printParseErrorCode, stripComments } from 'jsonc-parser';

@ludicast ludicast changed the title Allow text lockfile for bun feat(nx): allow text lockfile for bun Dec 19, 2024
@ludicast
Copy link
Author

ludicast commented Dec 19, 2024

@Jordan-Hall - if by parser you mean writing something in the vein of https://github.com/nrwl/nx/blob/master/packages/nx/src/plugins/js/lock-file/yarn-parser.ts it def would need to be a follow-on (it's enough code to get caught up in PR purgatory)

@Jordan-Hall
Copy link
Contributor

Yes i was because as you can see from the PR i did their loads of work needs to be done. I dont think just adding new vars is the right idea. If not can you at least do the grunt work without that section

@protoEvangelion
Copy link

Hey @Jordan-Hall now that bun 1.2 has released text lock file by default, are there any workarounds until the required work is completed?

@matthewrj
Copy link

nx now doesn't work with the default bun settings. Has this PR gone stale or are we working towards getting it merged?

@Jordan-Hall
Copy link
Contributor

nx now doesn't work with the default bun settings. Has this PR gone stale or are we working towards getting it merged?

Whats the current issue. this PR directly wont resolve anything if im not mistaken

@JamesHenry
Copy link
Collaborator

@Jordan-Hall I believe they are referring to Bun 1.2 and onwards defaulting to the new text based lockfile

@JamesHenry
Copy link
Collaborator

@ludicast Thanks a lot for this!

@@ -182,7 +185,7 @@ function getLockFilePath(packageManager: PackageManager): string {
return NPM_LOCK_PATH;
}
if (packageManager === 'bun') {
return BUN_LOCK_PATH;
return BUN_LOCK_PATH; // defaulting to binary lockfile
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like we should be checking the Bun version and if >= 1.2 this should be defaulting to the text based one?

@JamesHenry
Copy link
Collaborator

@ludicast You will please need to ensure CI is green, right now you have invalid syntax in this PR and the nx package cannot be built

@Jordan-Hall
Copy link
Contributor

@ludicast You will please need to ensure CI is green, right now you have invalid syntax in this PR and the nx package cannot be built

Even so their supporting both and I think the interface is no longer fit for purpose having single lock files.

@JamesHenry JamesHenry changed the title feat(nx): allow text lockfile for bun fix(core): allow text lockfile for bun Feb 16, 2025
@JamesHenry
Copy link
Collaborator

Just to let you know, I'm personally excited about bun and I've added support for bun publish to be run behind the scenes instead of npm publish when using nx release in bun workspaces:

#30064

@JamesHenry
Copy link
Collaborator

@Jordan-Hall I understand where you are coming from, but (A) other package managers have had stable lock file names for many years (B) it seems unlikely would go through this churn again any time soon, so implementing some more complex handling just to make it feel like a cleaner implementation is probably overkill at this point. If something similar happened again we could definitely consider a broader refactor.

@ludicast Thanks again for this, to ensure it gets merged as soon as possible I am going to fold the changes into the linked PR

@JamesHenry JamesHenry closed this Feb 17, 2025
@matthewrj
Copy link

@Jordan-Hall the issue with the current defaults is I run into this bug: #29429. I have no binary lockfile, so I get the error

Error: Failed to convert JavaScript value Null into rust type String

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.

6 participants