Skip to content

Commit 813cb33

Browse files
authored
fix(nightly): check for already uploaded versions and support downgrades
The current nightly build is broken, because the next nightly version would be 2.9.0-beta-0, which was already uploaded (by accident) to npm in 2019, so it already exists, which breaks the build. This PR now checks for possible existing npm versions and increases the beta number accordingly. i found out that 2.9.0-beta.0 is not available in the versions property from the npm api, but it is in the time property of registry.npmjs.org/fomantic-ui This PR also allows for possible downgrades. Means, if we have a 2.9.0-beta.1234 but , by some reason, we would have to create a 2.8.9 at a later stage, the script would not allow that (the next github milestone was always supposed to be greater than the latest nightly)
1 parent e39a0ae commit 813cb33

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

scripts/nightly-version.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,38 @@ const getNpmPreRelease = async function () {
3535
.then(pr => pr === null ? ['beta', 0] : pr)
3636
}
3737

38+
const getAllNpmVersions = async function () {
39+
// The versions property sometimes does not include versions which are in "time"!
40+
// That's why "time" is used here
41+
return fetch(`${npmBase}/${npmPackage}`)
42+
.then(r => r.json())
43+
.then(p => Object.keys(p['time']))
44+
}
45+
3846
const getNightlyVersion = async function () {
3947
const nextVersion = await getGitHubVersion()
4048
const currentNightlyWithPre = semver.parse(await getCurrentNpmVersion())
4149
const currentNightly = `${currentNightlyWithPre.major}.${currentNightlyWithPre.minor}.${currentNightlyWithPre.patch}`
50+
const allNpmVersions = await getAllNpmVersions()
51+
let nightlyVersion = `${nextVersion}-beta.0`
4252

43-
if (!semver.gt(nextVersion, currentNightly)) {
44-
if (semver.minor(nextVersion) === semver.minor(currentNightly)) {
45-
const preRelease = await getNpmPreRelease()
53+
if (semver.eq(nextVersion, currentNightly)) {
54+
const preRelease = await getNpmPreRelease()
4655

47-
return semver.inc(
48-
`${nextVersion}-${preRelease[0]}.${preRelease[1]}`,
56+
nightlyVersion = semver.inc(
57+
`${nextVersion}-${preRelease[0]}.${preRelease[1]}`,
58+
'prerelease'
59+
)
60+
}
61+
//check if version was already uploaded to npm previously
62+
while (allNpmVersions.indexOf(nightlyVersion) !== -1) {
63+
nightlyVersion = semver.inc(
64+
nightlyVersion,
4965
'prerelease'
50-
)
51-
}
66+
)
5267
}
5368

54-
return `${nextVersion}-beta.0`
69+
return nightlyVersion
5570
}
5671

5772
getNightlyVersion()

0 commit comments

Comments
 (0)