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 beta versioning #675

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

lydell
Copy link

@lydell lydell commented Mar 16, 2024

Beta versions currently have suffixes like -beta1, -beta2, -beta3 etc. That works fine until we reach -beta10. Unfortunately, the 10 in there is not treated numerically, so according to npm’s semver -beta2 is “higher” than -beta10. Numbers only seem to be treated numerically when preceded by a ..

This is problematic because:

  • ^1.1.0-beta1 happens to work as expected.
  • ^1.1.0-beta2 on the other hand matches 1.1.0-beta2 to 1.1.0-beta9 and then 1.1.0-beta20, but not 1.1.0-beta10 to 1.1.0-beta19.

You can play around with the above at https://semver.npmjs.com/.

In this example, I want -1 all the time, but it fails when going from 9 to 10:

> require("semver").compare("1.0.0-beta8", "1.0.0-beta9")
-1

> require("semver").compare("1.0.0-beta9", "1.0.0-beta10")
1 // 🚨 !!!

> require("semver").compare("1.0.0-beta10", "1.0.0-beta11")
-1

But with a dot it works:

> require("semver").compare("1.0.0-beta.8", "1.0.0-beta.9")
-1

> require("semver").compare("1.0.0-beta.9", "1.0.0-beta.10")
-1

> require("semver").compare("1.0.0-beta.10", "1.0.0-beta.11")
-1

Unfortunately, 1.1.0-beta.13 is considered lower than 1.1.0-beta12, so I recommend waiting with merging this until you have released the next stable version.

> require("semver").compare("1.1.0-beta.13", "1.1.0-beta12")
-1

}

function getPublishedVersions(version, tag) {
const versionsProcess = cp.spawnSync('npm', ['view', packageJson.name, 'versions', '--json']);
const versionsJson = JSON.parse(versionsProcess.stdout);
if (tag) {
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}[0-9]+`)));
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}\.[0-9]+`)));
Copy link
Author

Choose a reason for hiding this comment

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

If you want to merge this straight away even with the 1.1.0-beta.13 < 1.1.0-beta12 caveat, you need to add a ? here:

Suggested change
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}\.[0-9]+`)));
return versionsJson.filter(v => !v.search(new RegExp(`${version}-${tag}\.?[0-9]+`)));

@deepak1556 deepak1556 requested a review from Tyriar March 18, 2024 04:22
@deepak1556 deepak1556 added this to the 1.1.0 milestone Mar 18, 2024
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