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: correct yarn detection #140

Merged
merged 2 commits into from
Aug 25, 2024
Merged

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Jul 5, 2024

Hi! 👋
Thanks for the project, it has been of great help for my own project: https://github.com/LekoArts/secco

I've found a small bug in this codepath:

const packageManager =
  packageManagers.find(
    (pm) => pm.name === name && pm.majorVersion === majorVersion,
  ) || packageManagers.find((pm) => pm.name === name);

The comparison of pm.majorVersion === majorVersion will currently be 3.0.0 === 3, so it'll fall back to the first name found. So if you e.g. run the detection in a yarn berry project you won't get back the files array.

In 3b0f0aa I added the assertion of files to the tests, which then were failing. The commit after that fixes it.

I'll leave some inline comments that we could consider for future PRs but I wanted to discuss first.

Comment on lines 59 to +61
name: "yarn",
command: "yarn",
majorVersion: "3.0.0",
majorVersion: "3",
Copy link
Contributor Author

@LekoArts LekoArts Jul 5, 2024

Choose a reason for hiding this comment

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

It would probably be a breaking change, but from a usability standpoint this here would be better:

name: "yarn-berry"
majorVersion: ["3", "4"]

Because right now on any new yarn berry project (the current major is 4) this whole detection system won't work. And there is no real differentiation between yarn classic and yarn berry.

So in my own code I need to write this at the moment:

if (pm.name === 'yarn' && (pm.majorVersion === "3" || pm.majorVersion === "4")) {}

Would be cool to be able to write this instead:

if (pm.name === 'yarn-berry') {}

@LekoArts LekoArts marked this pull request as ready for review July 5, 2024 07:28
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

LGTM. thanks.

@pi0 pi0 changed the title fix: Correct yarn detection fix: correct yarn detection Aug 25, 2024
@pi0 pi0 merged commit dd76583 into unjs:main Aug 25, 2024
@LekoArts LekoArts deleted the fix/yarn-berry-detection branch August 26, 2024 06:46
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.

2 participants