@@ -18,12 +18,11 @@ export interface VerifyNpmReleaseOptions {
1818 log ?: ( message : string ) => void ;
1919}
2020
21- export function prereleaseTag ( version : string ) : 'alpha' | 'beta' | 'rc' {
21+ export function prereleaseTag ( version : string ) : 'alpha' | 'beta' | 'rc' | null {
2222 const match = version . match ( / ^ \d + \. \d + \. \d + - ( a l p h a | b e t a | r c ) \. \d + $ / u) ;
23- if ( ! match ) {
24- throw new Error ( 'Expected prerelease version x.y.z-alpha|beta|rc.n' ) ;
25- }
26- return match [ 1 ] as 'alpha' | 'beta' | 'rc' ;
23+ if ( match ) return match [ 1 ] as 'alpha' | 'beta' | 'rc' ;
24+ if ( / ^ \d + \. \d + \. \d + $ / u. test ( version ) ) return null ;
25+ throw new Error ( `Expected version x.y.z or x.y.z-alpha|beta|rc.n, got: ${ version } ` ) ;
2726}
2827
2928async function verifyField (
@@ -79,16 +78,19 @@ export async function verifyNpmRelease(options: VerifyNpmReleaseOptions): Promis
7978 options . version ,
8079 runtime ,
8180 ) ;
82- await verifyField (
83- `${ packageName } dist-tags.${ tag } ` ,
84- packageName ,
85- `dist-tags.${ tag } ` ,
86- options . version ,
87- runtime ,
88- ) ;
89- // latest dist-tag policy (alpha line): prerelease publishes also move
90- // `latest` (see tools/publish-npm.ts), so `latest` must equal the
91- // just-published version — it must never lag the active release line.
81+ if ( tag ) {
82+ await verifyField (
83+ `${ packageName } dist-tags.${ tag } ` ,
84+ packageName ,
85+ `dist-tags.${ tag } ` ,
86+ options . version ,
87+ runtime ,
88+ ) ;
89+ }
90+ // latest dist-tag policy: prerelease publishes also move `latest` (see
91+ // tools/publish-npm.ts); stable publishes keep the npm default of tagging
92+ // `latest`. Either way `latest` must equal the just-published version —
93+ // it must never lag the active release line.
9294 // Chosen invariant: dist-tags.latest === <published version> (exact match,
9395 // not semver >=), so a stale `latest` fails verification immediately.
9496 await verifyField (
@@ -98,6 +100,10 @@ export async function verifyNpmRelease(options: VerifyNpmReleaseOptions): Promis
98100 options . version ,
99101 runtime ,
100102 ) ;
101- options . log ?.( `${ packageName } @${ options . version } : ${ tag } and latest dist-tags verified` ) ;
103+ options . log ?.(
104+ tag
105+ ? `${ packageName } @${ options . version } : ${ tag } and latest dist-tags verified`
106+ : `${ packageName } @${ options . version } : latest dist-tag verified (stable)` ,
107+ ) ;
102108 }
103109}
0 commit comments