11'use strict'
22
3- const TagSemVerRx = / ^ v ? ( \d + ) \. ( \d + ) \. ( \d + ) (?: - ( R C | M ) ( \d + ) ) ? $ /
3+ const TagSemVerRx = / ^ v ? ( \d + ) \. ( \d + ) \. ( \d + ) (?: \. ( \d + ) ) ? (?: - ( R C | M ) ( \d + ) ) ? $ /
44
55const { name : packageName } = require ( '#package' )
66/**
@@ -21,7 +21,6 @@ module.exports.register = function ({ playbook }) {
2121 . filter ( ( a ) => a . origins [ 0 ] . tag )
2222 . sort ( ( a , b ) => compareSemVerAscending ( componentRefname ( a ) , componentRefname ( b ) ) )
2323 . reverse ( )
24-
2524 for ( const componentVersionBucket of tags ) {
2625 const { name : componentName } = componentVersionBucket
2726 if ( ! componentToGenerationMapping . has ( componentName ) ) {
@@ -71,7 +70,7 @@ function compareSemVerAscending (lhs, rhs) {
7170 for ( const [ index , leftPart ] of lhsParts . entries ( ) ) {
7271 const rightPart = rhsParts [ index ]
7372 if ( leftPart !== rightPart ) {
74- if ( index !== 3 ) {
73+ if ( index !== lhsParts . length - 2 ) {
7574 return Number ( leftPart ) - Number ( rightPart )
7675 }
7776 return leftPart < rightPart ? - 1 : 1
@@ -80,13 +79,32 @@ function compareSemVerAscending (lhs, rhs) {
8079 return 0
8180}
8281
82+ /**
83+ * Returns an array of the parsed version [int major, int minor, int patch, int hotfix, String type, int typeVersion].
84+ *
85+ * If hotfix is undefined, it is explicitly replaced with -1 to ensure proper sorting.
86+ *
87+ * The type is either M (milestones), RC (release candidates), or Z (explicitly replaced for releases to ensure proper
88+ * sorting of releases).
89+ *
90+ * The type version is the count of the type. If it is undefined (only releases), then it remains undefined since
91+ * this comparison is unnecessary.
92+ *
93+ * @param version the version in the format of a tag (e.g. v1.0.0-M1 v1.0.0-RC1 v1.0.0 v1.0.1 v1.0.1.1). The v prefix is
94+ * optional, so v1.0.0 and 1.0.0 are treated the same.
95+ * @returns an array of the parsed version used for comparison.
96+ */
8397function extractVersionParts ( version ) {
8498 const match = version . match ( TagSemVerRx )
8599 if ( ! match ) {
86100 throw new Error ( `Cannot parse version = ${ version } with regex ${ TagSemVerRx } ` )
87101 }
88102 const result = Array . from ( match )
89103 result . splice ( 0 , 1 )
104+ const hotfixIndex = result . length - 3
105+ if ( result [ hotfixIndex ] === undefined ) {
106+ result [ hotfixIndex ] = - 1
107+ }
90108 const milestoneRcIndex = result . length - 2
91109 if ( result [ milestoneRcIndex ] === undefined ) {
92110 result [ milestoneRcIndex ] = 'Z'
0 commit comments