Skip to content

Commit 512a239

Browse files
chore: allow publishing new major of workspace without prerelease (#6813)
Previously the publish script assumed that a new major version of a workspace would always be preceeded by a prerelease. This updates the script so that a workspace will be published to the `latest` tag if it is greater than the current latest major version. This also fixes an issue where getting a version of a workspace could fail if it is the first time being published to a new tag. The script now catches this error and treats it like a workspace that needs publishing. Co-authored-by: Luke Karrys <[email protected]>
1 parent 608005d commit 512a239

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/publish.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const resetdeps = () => npm('run', 'resetdeps')
88
const op = () => spawn('op', 'item', 'get', 'npm', '--otp', { out: true, ok: true })
99

1010
const getVersion = async (s) => {
11-
const mani = await pacote.manifest(s, { preferOnline: true })
12-
return mani.version
11+
const mani = await pacote.manifest(s, { preferOnline: true }).catch(() => null)
12+
return mani?.version
1313
}
14-
const getLatest = async (s) => {
15-
const pack = await pacote.packument(s, { preferOnline: true })
16-
return pack['dist-tags'].latest
14+
const getLatestMajor = async (s) => {
15+
const pack = await pacote.packument(s, { preferOnline: true }).catch(() => null)
16+
return pack?.['dist-tags']?.latest ? semver.major(pack['dist-tags'].latest) : 0
1717
}
1818

1919
const TAG = {
@@ -23,7 +23,7 @@ const TAG = {
2323
if (prerelease.length) {
2424
return 'prerelease'
2525
}
26-
if (major === await getLatest(name).then(v => semver.major(v))) {
26+
if (major >= await getLatestMajor(name)) {
2727
return 'latest'
2828
}
2929
return 'backport'

0 commit comments

Comments
 (0)