Semantic sorting for prerelease versions fixed

Nov 12 2024

We've improved our versioning logic to accurately handle the parsing and semantic sorting of versions with prerelease components. 🛠

What changed?

Previously, our implementation treated all numbers in prerelease components as a single integer when comparing versions.

For example, when comparing versions 1.0.0-alpha.1.3.1 and 1.0.0-alpha.1.22, the prerelease components of 1.3.1 and 1.22 would be converted into single integers, 131 and 122, then compared. This naive parsing led to incorrect sorting, as 131 was considered greater than 122, marking the wrong version as the latest.

With this recent update, we individually parse and compare each numerical part of the prerelease components within a version. In the same example, 3 is now correctly compared to 22, ensuring 1.0.0-alpha.1.22 is correctly determined to be the latest version.

Why does this matter? 🤔

This improvement aligns our handling more closely with the Semantic Versioning 2.0.0 Specification, resulting in more precise and accurate sorting for versions with a prerelease component and better consistency when we need to automatically determine a package's "latest" version tag.

How does this impact you?

Whether you have existing packages with prerelease components or are uploading new packages, this update ensures more accurate version comparisons and sorting. 📝

For existing packages with prerelease components in the version:

  • They’ll retain their existing parsed versions with no automatic changes.
  • The version will be parsed with the new logic if the package is resynced.
  • You’re in control to choose whether to resync or retain existing versions.

For newly uploaded packages with prerelease components in the version:

  • They will automatically use the new logic to parse versions correctly.
  • The more accurately parsed versions with prerelease components will impact the determination of the “latest” version tag for packages (relative to other prereleases).
  • If you have a mixture of old and new packages and notice that the ordering isn’t correct, you’ll need to resync the old packages first, as above.

If you have any questions or concerns about this change, please reach out to us and we’d be happy to have a chat. 🗯

Keep up to date with our monthly product bulletin

By submitting this form, you agree to our privacy policy