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: support for sorting dependenciesMeta in Yarn berry #323

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

rickh18
Copy link
Contributor

@rickh18 rickh18 commented Aug 21, 2024

A PR for fixing #301

This implementation follows the sorting of yarn.

In Yarn berry, the dependenciesMeta field can also contain a range ("package-name@1.2.3").

The Yarn source code only uses the identifier when sorting dependencyMeta. This is different from the current implementation of this package. Each time when running Yarn, this will result in a conflict. This fix will bring the sorting in line with that of Yarn.

The current implementation sorts on the whole name including the range. Therefore, in the example below, "bats-assert@2.0.0" comes before "bats@1.10.0" (because - comes before @)

In this implementation, the range will be stripped from the name before sorting. Therefore, it will sort like yarn: "bats" comes before "bats-assert"

current sort-package-json implementation:

"dependenciesMeta": {
    "bats-assert@2.0.0": {
      "unplugged": true
    },
    "bats-support@0.3.0": {
      "unplugged": true
    },
    "bats@1.10.0": {
      "unplugged": true
    }
  },

yarn:

  "dependenciesMeta": {
    "bats@1.10.0": {
      "unplugged": true
    },
    "bats-assert@2.0.0": {
      "unplugged": true
    },
    "bats-support@0.3.0": {
      "unplugged": true
    }

The sorting stays the same for dependenciesMeta that do not have a range in their name.

I also checked if peerDependenciesMeta should have the same fix, however a range is not supported there in Yarn Berry.

keithamus
keithamus previously approved these changes Aug 21, 2024
Copy link
Owner

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

LGTM 👍. Let's ship it and if anyone has any further issues we can refine.

index.js Outdated Show resolved Hide resolved
- renamed getIdent to getPackageName
- moved getPackageName and parseNameAndVersionRange functions to outer scope.
@keithamus keithamus merged commit 7e1dd1f into keithamus:main Aug 21, 2024
4 checks passed
Copy link

🎉 This PR is included in version 2.10.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants