@@ -9404,35 +9404,43 @@ const coerce = (version, options) => {
9404
9404
9405
9405
let match = null
9406
9406
if (!options.rtl) {
9407
- match = version.match(re[t.COERCE])
9407
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE])
9408
9408
} else {
9409
9409
// Find the right-most coercible string that does not share
9410
9410
// a terminus with a more left-ward coercible string.
9411
9411
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
9412
+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
9412
9413
//
9413
9414
// Walk through the string checking with a /g regexp
9414
9415
// Manually set the index so as to pick up overlapping matches.
9415
9416
// Stop when we get a match that ends at the string end, since no
9416
9417
// coercible string can be more right-ward without the same terminus.
9418
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL]
9417
9419
let next
9418
- while ((next = re[t.COERCERTL] .exec(version)) &&
9420
+ while ((next = coerceRtlRegex .exec(version)) &&
9419
9421
(!match || match.index + match[0].length !== version.length)
9420
9422
) {
9421
9423
if (!match ||
9422
9424
next.index + next[0].length !== match.index + match[0].length) {
9423
9425
match = next
9424
9426
}
9425
- re[t.COERCERTL] .lastIndex = next.index + next[1].length + next[2].length
9427
+ coerceRtlRegex .lastIndex = next.index + next[1].length + next[2].length
9426
9428
}
9427
9429
// leave it in a clean state
9428
- re[t.COERCERTL] .lastIndex = -1
9430
+ coerceRtlRegex .lastIndex = -1
9429
9431
}
9430
9432
9431
9433
if (match === null) {
9432
9434
return null
9433
9435
}
9434
9436
9435
- return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
9437
+ const major = match[2]
9438
+ const minor = match[3] || '0'
9439
+ const patch = match[4] || '0'
9440
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ''
9441
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : ''
9442
+
9443
+ return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
9436
9444
}
9437
9445
module.exports = coerce
9438
9446
@@ -10124,12 +10132,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
10124
10132
10125
10133
// Coercion.
10126
10134
// Extract anything that could conceivably be a part of a valid semver
10127
- createToken('COERCE ', `${'(^|[^\\d])' +
10135
+ createToken('COERCEPLAIN ', `${'(^|[^\\d])' +
10128
10136
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
10129
10137
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
10130
- `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
10138
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`)
10139
+ createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`)
10140
+ createToken('COERCEFULL', src[t.COERCEPLAIN] +
10141
+ `(?:${src[t.PRERELEASE]})?` +
10142
+ `(?:${src[t.BUILD]})?` +
10131
10143
`(?:$|[^\\d])`)
10132
10144
createToken('COERCERTL', src[t.COERCE], true)
10145
+ createToken('COERCERTLFULL', src[t.COERCEFULL], true)
10133
10146
10134
10147
// Tilde ranges.
10135
10148
// Meaning is "reasonably at or greater than"
0 commit comments