1
1
'use strict'
2
2
3
- const TagSemVerRx = / ^ v ? ( \d + ) \. ( \d + ) \. ( \d + ) (?: - ( R C | M ) ( \d + ) ) ? $ /
3
+ const TagSemVerRx = / ^ v ? ( \d + ) \. ( \d + ) \. ( \d + ) (?: \. ( \d + ) ) ? (?: - ( R C | M ) ( \d + ) ) ? $ /
4
4
5
5
const { name : packageName } = require ( '#package' )
6
6
/**
@@ -21,7 +21,6 @@ module.exports.register = function ({ playbook }) {
21
21
. filter ( ( a ) => a . origins [ 0 ] . tag )
22
22
. sort ( ( a , b ) => compareSemVerAscending ( componentRefname ( a ) , componentRefname ( b ) ) )
23
23
. reverse ( )
24
-
25
24
for ( const componentVersionBucket of tags ) {
26
25
const { name : componentName } = componentVersionBucket
27
26
if ( ! componentToGenerationMapping . has ( componentName ) ) {
@@ -71,7 +70,7 @@ function compareSemVerAscending (lhs, rhs) {
71
70
for ( const [ index , leftPart ] of lhsParts . entries ( ) ) {
72
71
const rightPart = rhsParts [ index ]
73
72
if ( leftPart !== rightPart ) {
74
- if ( index !== 3 ) {
73
+ if ( index !== lhsParts . length - 2 ) {
75
74
return Number ( leftPart ) - Number ( rightPart )
76
75
}
77
76
return leftPart < rightPart ? - 1 : 1
@@ -80,13 +79,32 @@ function compareSemVerAscending (lhs, rhs) {
80
79
return 0
81
80
}
82
81
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
+ */
83
97
function extractVersionParts ( version ) {
84
98
const match = version . match ( TagSemVerRx )
85
99
if ( ! match ) {
86
100
throw new Error ( `Cannot parse version = ${ version } with regex ${ TagSemVerRx } ` )
87
101
}
88
102
const result = Array . from ( match )
89
103
result . splice ( 0 , 1 )
104
+ const hotfixIndex = result . length - 3
105
+ if ( result [ hotfixIndex ] === undefined ) {
106
+ result [ hotfixIndex ] = - 1
107
+ }
90
108
const milestoneRcIndex = result . length - 2
91
109
if ( result [ milestoneRcIndex ] === undefined ) {
92
110
result [ milestoneRcIndex ] = 'Z'
0 commit comments