semver
Advanced tools
Comparing version 7.5.4 to 7.6.0
@@ -22,3 +22,3 @@ const SemVer = require('../classes/semver') | ||
if (!options.rtl) { | ||
match = version.match(re[t.COERCE]) | ||
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]) | ||
} else { | ||
@@ -28,2 +28,3 @@ // Find the right-most coercible string that does not share | ||
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4' | ||
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4' | ||
// | ||
@@ -34,4 +35,5 @@ // Walk through the string checking with a /g regexp | ||
// coercible string can be more right-ward without the same terminus. | ||
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL] | ||
let next | ||
while ((next = re[t.COERCERTL].exec(version)) && | ||
while ((next = coerceRtlRegex.exec(version)) && | ||
(!match || match.index + match[0].length !== version.length) | ||
@@ -43,6 +45,6 @@ ) { | ||
} | ||
re[t.COERCERTL].lastIndex = next.index + next[1].length + next[2].length | ||
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length | ||
} | ||
// leave it in a clean state | ||
re[t.COERCERTL].lastIndex = -1 | ||
coerceRtlRegex.lastIndex = -1 | ||
} | ||
@@ -54,4 +56,10 @@ | ||
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options) | ||
const major = match[2] | ||
const minor = match[3] || '0' | ||
const patch = match[4] || '0' | ||
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '' | ||
const build = options.includePrerelease && match[6] ? `+${match[6]}` : '' | ||
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options) | ||
} | ||
module.exports = coerce |
@@ -157,8 +157,13 @@ const { | ||
// Extract anything that could conceivably be a part of a valid semver | ||
createToken('COERCE', `${'(^|[^\\d])' + | ||
createToken('COERCEPLAIN', `${'(^|[^\\d])' + | ||
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` + | ||
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + | ||
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` + | ||
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`) | ||
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`) | ||
createToken('COERCEFULL', src[t.COERCEPLAIN] + | ||
`(?:${src[t.PRERELEASE]})?` + | ||
`(?:${src[t.BUILD]})?` + | ||
`(?:$|[^\\d])`) | ||
createToken('COERCERTL', src[t.COERCE], true) | ||
createToken('COERCERTLFULL', src[t.COERCEFULL], true) | ||
@@ -165,0 +170,0 @@ // Tilde ranges. |
{ | ||
"name": "semver", | ||
"version": "7.5.4", | ||
"version": "7.6.0", | ||
"description": "The semantic version parser used by npm.", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"snap": "tap", | ||
"lint": "eslint \"**/*.js\"", | ||
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"", | ||
"postlint": "template-oss-check", | ||
@@ -18,3 +18,3 @@ "lintfix": "npm run lint -- --fix", | ||
"@npmcli/eslint-config": "^4.0.0", | ||
"@npmcli/template-oss": "4.17.0", | ||
"@npmcli/template-oss": "4.21.3", | ||
"tap": "^16.0.0" | ||
@@ -58,13 +58,4 @@ }, | ||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", | ||
"version": "4.17.0", | ||
"version": "4.21.3", | ||
"engines": ">=10", | ||
"ciVersions": [ | ||
"10.0.0", | ||
"10.x", | ||
"12.x", | ||
"14.x", | ||
"16.x", | ||
"18.x" | ||
], | ||
"npmSpec": "8", | ||
"distPaths": [ | ||
@@ -71,0 +62,0 @@ "classes/", |
@@ -532,2 +532,6 @@ semver(1) -- The semantic versioner for npm | ||
If the `options.includePrerelease` flag is set, then the `coerce` result will contain | ||
prerelease and build parts of a version. For example, `1.2.3.4-rc.1+rev.2` | ||
will preserve prerelease `rc.1` and build `rev.2` in the result. | ||
### Clean | ||
@@ -547,3 +551,3 @@ | ||
* `s.clean('=v2.1.5')`: `'2.1.5'` | ||
* `s.clean(' =v2.1.5')`: `2.1.5` | ||
* `s.clean(' =v2.1.5')`: `'2.1.5'` | ||
* `s.clean(' 2.1.5 ')`: `'2.1.5'` | ||
@@ -550,0 +554,0 @@ * `s.clean('~1.0.0')`: `null` |
94244
2093
642