@@ -46,15 +46,22 @@ async function main() {
4646 perPackageVersions . push ( { npmName, nextNpmVersion } ) ;
4747 }
4848
49- // Pick the highest prerelease version across all projects by sorting on the numeric suffix that
50- // follows "<preid>.". For example, given "2.0.1-alpha.3" and "2.0.1-alpha.7", this resolves to
51- // "2.0.1-alpha.7". The cast is safe because uniqueNextNpmVersions always has at least one entry.
49+ // Pick the highest prerelease version across all projects by comparing the base semver version
50+ // first (major.minor.patch) and then the numeric prerelease suffix. For example, given
51+ // "2.0.320-alpha.2" and "2.0.324-alpha.0", this resolves to "2.0.324-alpha.0" because the base
52+ // version 2.0.324 is higher. The cast is safe because uniqueNextNpmVersions always has at least
53+ // one entry.
5254 const resolvedVersion = /** @type {string } */ (
5355 Array . from ( uniqueNextNpmVersions )
5456 . sort ( ( a , b ) => {
55- const aPrereleaseNum = Number ( a . split ( `${ preid } .` ) [ 1 ] ?? '0' ) ;
56- const bPrereleaseNum = Number ( b . split ( `${ preid } .` ) [ 1 ] ?? '0' ) ;
57- return aPrereleaseNum - bPrereleaseNum ;
57+ const [ aBase , aPrereleaseSuffix ] = a . split ( `-${ preid } .` ) ;
58+ const [ bBase , bPrereleaseSuffix ] = b . split ( `-${ preid } .` ) ;
59+ const [ aMajor , aMinor , aPatch ] = ( aBase ?? '' ) . split ( '.' ) . map ( Number ) ;
60+ const [ bMajor , bMinor , bPatch ] = ( bBase ?? '' ) . split ( '.' ) . map ( Number ) ;
61+ if ( aMajor !== bMajor ) return aMajor - bMajor ;
62+ if ( aMinor !== bMinor ) return aMinor - bMinor ;
63+ if ( aPatch !== bPatch ) return aPatch - bPatch ;
64+ return Number ( aPrereleaseSuffix ?? '0' ) - Number ( bPrereleaseSuffix ?? '0' ) ;
5865 } )
5966 . at ( - 1 )
6067 ) ;
0 commit comments