semver 7.5.3 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/classes/range.js +1 -1
- package/functions/coerce.js +13 -5
- package/internal/re.js +13 -4
- package/package.json +4 -13
package/README.md
CHANGED
|
@@ -529,6 +529,10 @@ tuple. For example, `1.2.3.4` will return `2.3.4` in rtl mode, not
|
|
|
529
529
|
`4.0.0`. `1.2.3/4` will return `4.0.0`, because the `4` is not a part of
|
|
530
530
|
any other overlapping SemVer tuple.
|
|
531
531
|
|
|
532
|
+
If the `options.includePrerelease` flag is set, then the `coerce` result will contain
|
|
533
|
+
prerelease and build parts of a version. For example, `1.2.3.4-rc.1+rev.2`
|
|
534
|
+
will preserve prerelease `rc.1` and build `rev.2` in the result.
|
|
535
|
+
|
|
532
536
|
### Clean
|
|
533
537
|
|
|
534
538
|
* `clean(version)`: Clean a string to be a valid semver if possible
|
|
@@ -543,7 +547,7 @@ ex.
|
|
|
543
547
|
* `s.clean(' = v 2.1.5-foo')`: `null`
|
|
544
548
|
* `s.clean(' = v 2.1.5-foo', { loose: true })`: `'2.1.5-foo'`
|
|
545
549
|
* `s.clean('=v2.1.5')`: `'2.1.5'`
|
|
546
|
-
* `s.clean(' =v2.1.5')`: `2.1.5`
|
|
550
|
+
* `s.clean(' =v2.1.5')`: `'2.1.5'`
|
|
547
551
|
* `s.clean(' 2.1.5 ')`: `'2.1.5'`
|
|
548
552
|
* `s.clean('~1.0.0')`: `null`
|
|
549
553
|
|
package/classes/range.js
CHANGED
|
@@ -38,7 +38,7 @@ class Range {
|
|
|
38
38
|
this.set = this.raw
|
|
39
39
|
.split('||')
|
|
40
40
|
// map the range to a 2d array of comparators
|
|
41
|
-
.map(r => this.parseRange(r))
|
|
41
|
+
.map(r => this.parseRange(r.trim()))
|
|
42
42
|
// throw out any comparator lists that are empty
|
|
43
43
|
// this generally means that it was not a valid range, which is allowed
|
|
44
44
|
// in loose mode, but will still throw if the WHOLE range is invalid.
|
package/functions/coerce.js
CHANGED
|
@@ -19,34 +19,42 @@ const coerce = (version, options) => {
|
|
|
19
19
|
|
|
20
20
|
let match = null
|
|
21
21
|
if (!options.rtl) {
|
|
22
|
-
match = version.match(re[t.COERCE])
|
|
22
|
+
match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE])
|
|
23
23
|
} else {
|
|
24
24
|
// Find the right-most coercible string that does not share
|
|
25
25
|
// a terminus with a more left-ward coercible string.
|
|
26
26
|
// Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
|
|
27
|
+
// With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
|
|
27
28
|
//
|
|
28
29
|
// Walk through the string checking with a /g regexp
|
|
29
30
|
// Manually set the index so as to pick up overlapping matches.
|
|
30
31
|
// Stop when we get a match that ends at the string end, since no
|
|
31
32
|
// coercible string can be more right-ward without the same terminus.
|
|
33
|
+
const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL]
|
|
32
34
|
let next
|
|
33
|
-
while ((next =
|
|
35
|
+
while ((next = coerceRtlRegex.exec(version)) &&
|
|
34
36
|
(!match || match.index + match[0].length !== version.length)
|
|
35
37
|
) {
|
|
36
38
|
if (!match ||
|
|
37
39
|
next.index + next[0].length !== match.index + match[0].length) {
|
|
38
40
|
match = next
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length
|
|
41
43
|
}
|
|
42
44
|
// leave it in a clean state
|
|
43
|
-
|
|
45
|
+
coerceRtlRegex.lastIndex = -1
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
if (match === null) {
|
|
47
49
|
return null
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
const major = match[2]
|
|
53
|
+
const minor = match[3] || '0'
|
|
54
|
+
const patch = match[4] || '0'
|
|
55
|
+
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : ''
|
|
56
|
+
const build = options.includePrerelease && match[6] ? `+${match[6]}` : ''
|
|
57
|
+
|
|
58
|
+
return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
|
|
51
59
|
}
|
|
52
60
|
module.exports = coerce
|
package/internal/re.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {
|
|
2
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
3
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
4
|
+
MAX_LENGTH,
|
|
5
|
+
} = require('./constants')
|
|
2
6
|
const debug = require('./debug')
|
|
3
7
|
exports = module.exports = {}
|
|
4
8
|
|
|
@@ -19,7 +23,7 @@ const LETTERDASHNUMBER = '[a-zA-Z0-9-]'
|
|
|
19
23
|
// all input should have extra whitespace removed.
|
|
20
24
|
const safeRegexReplacements = [
|
|
21
25
|
['\\s', 1],
|
|
22
|
-
['\\d',
|
|
26
|
+
['\\d', MAX_LENGTH],
|
|
23
27
|
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
|
|
24
28
|
]
|
|
25
29
|
|
|
@@ -150,12 +154,17 @@ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`)
|
|
|
150
154
|
|
|
151
155
|
// Coercion.
|
|
152
156
|
// Extract anything that could conceivably be a part of a valid semver
|
|
153
|
-
createToken('
|
|
157
|
+
createToken('COERCEPLAIN', `${'(^|[^\\d])' +
|
|
154
158
|
'(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
|
|
155
159
|
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
|
|
156
|
-
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`
|
|
160
|
+
`(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`)
|
|
161
|
+
createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`)
|
|
162
|
+
createToken('COERCEFULL', src[t.COERCEPLAIN] +
|
|
163
|
+
`(?:${src[t.PRERELEASE]})?` +
|
|
164
|
+
`(?:${src[t.BUILD]})?` +
|
|
157
165
|
`(?:$|[^\\d])`)
|
|
158
166
|
createToken('COERCERTL', src[t.COERCE], true)
|
|
167
|
+
createToken('COERCERTLFULL', src[t.COERCEFULL], true)
|
|
159
168
|
|
|
160
169
|
// Tilde ranges.
|
|
161
170
|
// Meaning is "reasonably at or greater than"
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semver",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.0",
|
|
4
4
|
"description": "The semantic version parser used by npm.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "tap",
|
|
8
8
|
"snap": "tap",
|
|
9
|
-
"lint": "eslint \"**/*.js\"",
|
|
9
|
+
"lint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
|
|
10
10
|
"postlint": "template-oss-check",
|
|
11
11
|
"lintfix": "npm run lint -- --fix",
|
|
12
12
|
"posttest": "npm run lint",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@npmcli/eslint-config": "^4.0.0",
|
|
17
|
-
"@npmcli/template-oss": "4.
|
|
17
|
+
"@npmcli/template-oss": "4.21.3",
|
|
18
18
|
"tap": "^16.0.0"
|
|
19
19
|
},
|
|
20
20
|
"license": "ISC",
|
|
@@ -53,17 +53,8 @@
|
|
|
53
53
|
"author": "GitHub Inc.",
|
|
54
54
|
"templateOSS": {
|
|
55
55
|
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
56
|
-
"version": "4.
|
|
56
|
+
"version": "4.21.3",
|
|
57
57
|
"engines": ">=10",
|
|
58
|
-
"ciVersions": [
|
|
59
|
-
"10.0.0",
|
|
60
|
-
"10.x",
|
|
61
|
-
"12.x",
|
|
62
|
-
"14.x",
|
|
63
|
-
"16.x",
|
|
64
|
-
"18.x"
|
|
65
|
-
],
|
|
66
|
-
"npmSpec": "8",
|
|
67
58
|
"distPaths": [
|
|
68
59
|
"classes/",
|
|
69
60
|
"functions/",
|