Skip to content

Commit

Permalink
chore: allow publishing new major of workspace without prerelease (#6813
Browse files Browse the repository at this point in the history
)

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 <luke@lukekarrys.com>
  • Loading branch information
wraithgar and lukekarrys authored Sep 15, 2023
1 parent 608005d commit 512a239
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const resetdeps = () => npm('run', 'resetdeps')
const op = () => spawn('op', 'item', 'get', 'npm', '--otp', { out: true, ok: true })

const getVersion = async (s) => {
const mani = await pacote.manifest(s, { preferOnline: true })
return mani.version
const mani = await pacote.manifest(s, { preferOnline: true }).catch(() => null)
return mani?.version
}
const getLatest = async (s) => {
const pack = await pacote.packument(s, { preferOnline: true })
return pack['dist-tags'].latest
const getLatestMajor = async (s) => {
const pack = await pacote.packument(s, { preferOnline: true }).catch(() => null)
return pack?.['dist-tags']?.latest ? semver.major(pack['dist-tags'].latest) : 0
}

const TAG = {
Expand All @@ -23,7 +23,7 @@ const TAG = {
if (prerelease.length) {
return 'prerelease'
}
if (major === await getLatest(name).then(v => semver.major(v))) {
if (major >= await getLatestMajor(name)) {
return 'latest'
}
return 'backport'
Expand Down

0 comments on commit 512a239

Please sign in to comment.