3
3
4
4
const path = require ( 'path' )
5
5
const execa = require ( 'execa' )
6
+ const semver = require ( 'semver' )
6
7
const { Sema } = require ( 'async-sema' )
7
8
const { execSync } = require ( 'child_process' )
8
9
const fs = require ( 'fs' )
@@ -32,6 +33,34 @@ const cwd = process.cwd()
32
33
}
33
34
throw err
34
35
}
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
+
35
64
console . log (
36
65
`Publishing ${ isCanary ? 'canary' : isReleaseCandidate ? 'rc' : 'stable' } `
37
66
)
@@ -57,11 +86,7 @@ const cwd = process.cwd()
57
86
'--access' ,
58
87
'public' ,
59
88
'--ignore-scripts' ,
60
- ...( isCanary
61
- ? [ '--tag' , 'canary' ]
62
- : isReleaseCandidate
63
- ? [ '--tag' , 'rc' ]
64
- : [ ] ) ,
89
+ [ '--tag' , tag ] ,
65
90
] ,
66
91
{ stdio : 'pipe' }
67
92
)
0 commit comments