Skip to content

Commit 85b4473

Browse files
committed
[release-legacy] fix: backport release dist tag is latest
1 parent 56c3ae8 commit 85b4473

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

scripts/publish-release.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const path = require('path')
55
const execa = require('execa')
6+
const semver = require('semver')
67
const { Sema } = require('async-sema')
78
const { execSync } = require('child_process')
89
const fs = require('fs')
@@ -32,6 +33,34 @@ const cwd = process.cwd()
3233
}
3334
throw err
3435
}
36+
37+
let tag = isCanary ? 'canary' : isReleaseCandidate ? 'rc' : 'latest'
38+
39+
try {
40+
if (!isCanary && !isReleaseCandidate) {
41+
const version = JSON.parse(
42+
await fs.promises.readFile(path.join(cwd, 'lerna.json'), 'utf-8')
43+
).version
44+
45+
const res = await fetch(
46+
`https://registry.npmjs.org/-/package/next/dist-tags`
47+
)
48+
const tags = await res.json()
49+
50+
if (semver.lt(version, tags.latest)) {
51+
// If the current version is less than the latest, it means this
52+
// is a backport release. Since NPM sets the 'latest' tag by default
53+
// during publishing, when users install `next@latest`, they might
54+
// get the backported version instead of the actual "latest" version.
55+
// Therefore, we explicitly set the tag as 'stable' for backports.
56+
tag = 'stable'
57+
}
58+
}
59+
} catch (error) {
60+
console.log(error)
61+
throw error
62+
}
63+
3564
console.log(
3665
`Publishing ${isCanary ? 'canary' : isReleaseCandidate ? 'rc' : 'stable'}`
3766
)
@@ -57,11 +86,7 @@ const cwd = process.cwd()
5786
'--access',
5887
'public',
5988
'--ignore-scripts',
60-
...(isCanary
61-
? ['--tag', 'canary']
62-
: isReleaseCandidate
63-
? ['--tag', 'rc']
64-
: []),
89+
['--tag', tag],
6590
],
6691
{ stdio: 'pipe' }
6792
)

0 commit comments

Comments
 (0)