Skip to content

Commit e1fba33

Browse files
author
Loïc Mangeonjean
committed
fix: fix/simplify next release publishing script
1 parent 9feb263 commit e1fba33

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

releaseNext.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,21 @@ $.env = {
2626
GIT_TERMINAL_PROMPT: '0'
2727
}
2828

29-
function escapeRegExp (string: string) {
30-
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
31-
}
32-
3329
const vscodeVersion = process.argv[process.argv.length - 1]!
34-
const minorVscodeVersion = `${semver.major(vscodeVersion)}.${semver.minor(vscodeVersion)}`
35-
const tagPattern = new RegExp(`^v?(${escapeRegExp(minorVscodeVersion)}\\.\\d+)$`)
36-
37-
async function getLastTag () {
38-
const tags = (await $`git tag -l --sort=-v:refname`).toString().split('\n').map(tag => tag.trim())
39-
40-
const matchingTags = tags.filter(tag => tagPattern.test(tag)).sort(semver.compare)
41-
const lastTag = matchingTags[matchingTags.length - 1]!
30+
const vscodeVersionRange = `${semver.major(vscodeVersion)}.${semver.minor(vscodeVersion)}.*`
4231

43-
return lastTag
44-
}
45-
46-
async function getNextVersion (lastTag: string) {
47-
// Find available next version
32+
async function getNextVersion () {
4833
const allVersions = new Set(Object.keys((await packageJson('@codingame/monaco-vscode-api', {
4934
allVersions: true
5035
})).versions))
51-
let nextVersion: string = lastTag
52-
do {
53-
nextVersion = semver.inc(nextVersion, 'prerelease', true, 'next')!
54-
} while (allVersions.has(nextVersion))
5536

56-
return nextVersion
37+
const lastPublishedVersion = semver.maxSatisfying(Array.from(allVersions), vscodeVersionRange, { includePrerelease: true })
38+
39+
if (lastPublishedVersion != null) {
40+
return semver.inc(lastPublishedVersion, 'prerelease', true, 'next')!
41+
} else {
42+
return `${semver.major(vscodeVersion)}.${semver.minor(vscodeVersion)}.0-next.0`
43+
}
5744
}
5845

5946
async function publishNpm (version: string) {
@@ -81,8 +68,7 @@ async function publishNpm (version: string) {
8168
}
8269

8370
async function run () {
84-
const lastTag = await getLastTag()
85-
const nextVersion = await getNextVersion(lastTag)
71+
const nextVersion = await getNextVersion()
8672
await publishNpm(nextVersion)
8773
}
8874

0 commit comments

Comments
 (0)