@@ -9957,35 +9957,43 @@ const coerce = (version, options) => {
9957
9957
9958
9958
let match = null
9959
9959
if ( ! options . rtl ) {
9960
- match = version . match ( re [ t . COERCE ] )
9960
+ match = version . match ( options . includePrerelease ? re [ t . COERCEFULL ] : re [ t . COERCE ] )
9961
9961
} else {
9962
9962
// Find the right-most coercible string that does not share
9963
9963
// a terminus with a more left-ward coercible string.
9964
9964
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
9965
+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
9965
9966
//
9966
9967
// Walk through the string checking with a /g regexp
9967
9968
// Manually set the index so as to pick up overlapping matches.
9968
9969
// Stop when we get a match that ends at the string end, since no
9969
9970
// coercible string can be more right-ward without the same terminus.
9971
+ const coerceRtlRegex = options . includePrerelease ? re [ t . COERCERTLFULL ] : re [ t . COERCERTL ]
9970
9972
let next
9971
- while ( ( next = re [ t . COERCERTL ] . exec ( version ) ) &&
9973
+ while ( ( next = coerceRtlRegex . exec ( version ) ) &&
9972
9974
( ! match || match . index + match [ 0 ] . length !== version . length )
9973
9975
) {
9974
9976
if ( ! match ||
9975
9977
next . index + next [ 0 ] . length !== match . index + match [ 0 ] . length ) {
9976
9978
match = next
9977
9979
}
9978
- re [ t . COERCERTL ] . lastIndex = next . index + next [ 1 ] . length + next [ 2 ] . length
9980
+ coerceRtlRegex . lastIndex = next . index + next [ 1 ] . length + next [ 2 ] . length
9979
9981
}
9980
9982
// leave it in a clean state
9981
- re [ t . COERCERTL ] . lastIndex = - 1
9983
+ coerceRtlRegex . lastIndex = - 1
9982
9984
}
9983
9985
9984
9986
if ( match === null ) {
9985
9987
return null
9986
9988
}
9987
9989
9988
- return parse ( `${ match [ 2 ] } .${ match [ 3 ] || '0' } .${ match [ 4 ] || '0' } ` , options )
9990
+ const major = match [ 2 ]
9991
+ const minor = match [ 3 ] || '0'
9992
+ const patch = match [ 4 ] || '0'
9993
+ const prerelease = options . includePrerelease && match [ 5 ] ? `-${ match [ 5 ] } ` : ''
9994
+ const build = options . includePrerelease && match [ 6 ] ? `+${ match [ 6 ] } ` : ''
9995
+
9996
+ return parse ( `${ major } .${ minor } .${ patch } ${ prerelease } ${ build } ` , options )
9989
9997
}
9990
9998
module . exports = coerce
9991
9999
@@ -10677,12 +10685,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
10677
10685
10678
10686
// Coercion.
10679
10687
// Extract anything that could conceivably be a part of a valid semver
10680
- createToken ( 'COERCE ' , `${ '(^|[^\\d])' +
10688
+ createToken ( 'COERCEPLAIN ' , `${ '(^|[^\\d])' +
10681
10689
'(\\d{1,' } ${ MAX_SAFE_COMPONENT_LENGTH } })` +
10682
10690
`(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` +
10683
- `(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` +
10691
+ `(?:\\.(\\d{1,${ MAX_SAFE_COMPONENT_LENGTH } }))?` )
10692
+ createToken ( 'COERCE' , `${ src [ t . COERCEPLAIN ] } (?:$|[^\\d])` )
10693
+ createToken ( 'COERCEFULL' , src [ t . COERCEPLAIN ] +
10694
+ `(?:${ src [ t . PRERELEASE ] } )?` +
10695
+ `(?:${ src [ t . BUILD ] } )?` +
10684
10696
`(?:$|[^\\d])` )
10685
10697
createToken ( 'COERCERTL' , src [ t . COERCE ] , true )
10698
+ createToken ( 'COERCERTLFULL' , src [ t . COERCEFULL ] , true )
10686
10699
10687
10700
// Tilde ranges.
10688
10701
// Meaning is "reasonably at or greater than"
0 commit comments