semver 7.1.3 → 7.2.3
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/CHANGELOG.md +16 -0
- package/README.md +9 -0
- package/classes/range.js +21 -16
- package/index.js +1 -0
- package/package.json +7 -7
- package/ranges/simplify.js +44 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# changes log
|
|
2
2
|
|
|
3
|
+
## 7.2.2
|
|
4
|
+
|
|
5
|
+
* Fix bug where `2.0.0-pre` would be included in `^1.0.0` if
|
|
6
|
+
`includePrerelease` was set to true.
|
|
7
|
+
|
|
8
|
+
## 7.2.0
|
|
9
|
+
|
|
10
|
+
* Add `simplifyRange` method to attempt to generate a more human-readable
|
|
11
|
+
range expression that is equivalent to a supplied range, for a given set
|
|
12
|
+
of versions.
|
|
13
|
+
|
|
14
|
+
## 7.1.2
|
|
15
|
+
|
|
16
|
+
* Remove fancy lazy-loading logic, as it was causing problems for webpack
|
|
17
|
+
users.
|
|
18
|
+
|
|
3
19
|
## 7.1.0
|
|
4
20
|
|
|
5
21
|
* Add `require('semver/preload')` to load the entire module without using
|
package/README.md
CHANGED
|
@@ -78,6 +78,7 @@ const semverOutside = require('semver/ranges/outside')
|
|
|
78
78
|
const semverGtr = require('semver/ranges/gtr')
|
|
79
79
|
const semverLtr = require('semver/ranges/ltr')
|
|
80
80
|
const semverIntersects = require('semver/ranges/intersects')
|
|
81
|
+
const simplifyRange = require('semver/ranges/simplify')
|
|
81
82
|
```
|
|
82
83
|
|
|
83
84
|
As a command-line utility:
|
|
@@ -446,6 +447,14 @@ strings that they parse.
|
|
|
446
447
|
`hilo` argument must be either the string `'>'` or `'<'`. (This is
|
|
447
448
|
the function called by `gtr` and `ltr`.)
|
|
448
449
|
* `intersects(range)`: Return true if any of the ranges comparators intersect
|
|
450
|
+
* `simplifyRange(versions, range)`: Return a "simplified" range that
|
|
451
|
+
matches the same items in `versions` list as the range specified. Note
|
|
452
|
+
that it does *not* guarantee that it would match the same versions in all
|
|
453
|
+
cases, only for the set of versions provided. This is useful when
|
|
454
|
+
generating ranges by joining together multiple versions with `||`
|
|
455
|
+
programmatically, to provide the user with something a bit more
|
|
456
|
+
ergonomic. If the provided range is shorter in string-length than the
|
|
457
|
+
generated range, then that is returned.
|
|
449
458
|
|
|
450
459
|
Note that, since ranges may be non-contiguous, a version might not be
|
|
451
460
|
greater than a range, less than a range, *or* satisfy a range! For
|
package/classes/range.js
CHANGED
|
@@ -68,7 +68,7 @@ class Range {
|
|
|
68
68
|
range = range.trim()
|
|
69
69
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
70
70
|
const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE]
|
|
71
|
-
range = range.replace(hr, hyphenReplace)
|
|
71
|
+
range = range.replace(hr, hyphenReplace(this.options.includePrerelease))
|
|
72
72
|
debug('hyphen replace', range)
|
|
73
73
|
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
74
74
|
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
|
|
@@ -243,6 +243,7 @@ const replaceCarets = (comp, options) =>
|
|
|
243
243
|
const replaceCaret = (comp, options) => {
|
|
244
244
|
debug('caret', comp, options)
|
|
245
245
|
const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET]
|
|
246
|
+
const z = options.includePrerelease ? '-0' : ''
|
|
246
247
|
return comp.replace(r, (_, M, m, p, pr) => {
|
|
247
248
|
debug('caret', comp, _, M, m, p, pr)
|
|
248
249
|
let ret
|
|
@@ -250,40 +251,40 @@ const replaceCaret = (comp, options) => {
|
|
|
250
251
|
if (isX(M)) {
|
|
251
252
|
ret = ''
|
|
252
253
|
} else if (isX(m)) {
|
|
253
|
-
ret = `>=${M}.0.0 <${+M + 1}.0.0`
|
|
254
|
+
ret = `>=${M}.0.0${z} <${+M + 1}.0.0${z}`
|
|
254
255
|
} else if (isX(p)) {
|
|
255
256
|
if (M === '0') {
|
|
256
|
-
ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0`
|
|
257
|
+
ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0${z}`
|
|
257
258
|
} else {
|
|
258
|
-
ret = `>=${M}.${m}.0 <${+M + 1}.0.0`
|
|
259
|
+
ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0${z}`
|
|
259
260
|
}
|
|
260
261
|
} else if (pr) {
|
|
261
262
|
debug('replaceCaret pr', pr)
|
|
262
263
|
if (M === '0') {
|
|
263
264
|
if (m === '0') {
|
|
264
265
|
ret = `>=${M}.${m}.${p}-${pr
|
|
265
|
-
} <${M}.${m}.${+p + 1}`
|
|
266
|
+
} <${M}.${m}.${+p + 1}${z}`
|
|
266
267
|
} else {
|
|
267
268
|
ret = `>=${M}.${m}.${p}-${pr
|
|
268
|
-
} <${M}.${+m + 1}.0`
|
|
269
|
+
} <${M}.${+m + 1}.0${z}`
|
|
269
270
|
}
|
|
270
271
|
} else {
|
|
271
272
|
ret = `>=${M}.${m}.${p}-${pr
|
|
272
|
-
} <${+M + 1}.0.0`
|
|
273
|
+
} <${+M + 1}.0.0${z}`
|
|
273
274
|
}
|
|
274
275
|
} else {
|
|
275
276
|
debug('no pr')
|
|
276
277
|
if (M === '0') {
|
|
277
278
|
if (m === '0') {
|
|
278
279
|
ret = `>=${M}.${m}.${p
|
|
279
|
-
} <${M}.${m}.${+p + 1}`
|
|
280
|
+
}${z} <${M}.${m}.${+p + 1}${z}`
|
|
280
281
|
} else {
|
|
281
282
|
ret = `>=${M}.${m}.${p
|
|
282
|
-
} <${M}.${+m + 1}.0`
|
|
283
|
+
}${z} <${M}.${+m + 1}.0${z}`
|
|
283
284
|
}
|
|
284
285
|
} else {
|
|
285
286
|
ret = `>=${M}.${m}.${p
|
|
286
|
-
} <${+M + 1}.0.0`
|
|
287
|
+
} <${+M + 1}.0.0${z}`
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
|
|
@@ -383,27 +384,31 @@ const replaceStars = (comp, options) => {
|
|
|
383
384
|
// 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
|
|
384
385
|
// 1.2.3 - 3.4 => >=1.2.0 <3.5.0 Any 3.4.x will do
|
|
385
386
|
// 1.2 - 3.4 => >=1.2.0 <3.5.0
|
|
386
|
-
const hyphenReplace = ($0,
|
|
387
|
+
const hyphenReplace = incPr => ($0,
|
|
387
388
|
from, fM, fm, fp, fpr, fb,
|
|
388
389
|
to, tM, tm, tp, tpr, tb) => {
|
|
389
390
|
if (isX(fM)) {
|
|
390
391
|
from = ''
|
|
391
392
|
} else if (isX(fm)) {
|
|
392
|
-
from = `>=${fM}.0.0`
|
|
393
|
+
from = `>=${fM}.0.0${incPr ? '-0' : ''}`
|
|
393
394
|
} else if (isX(fp)) {
|
|
394
|
-
from = `>=${fM}.${fm}.0`
|
|
395
|
-
} else {
|
|
395
|
+
from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`
|
|
396
|
+
} else if (fpr) {
|
|
396
397
|
from = `>=${from}`
|
|
398
|
+
} else {
|
|
399
|
+
from = `>=${from}${incPr ? '-0' : ''}`
|
|
397
400
|
}
|
|
398
401
|
|
|
399
402
|
if (isX(tM)) {
|
|
400
403
|
to = ''
|
|
401
404
|
} else if (isX(tm)) {
|
|
402
|
-
to = `<${+tM + 1}.0.0`
|
|
405
|
+
to = `<${+tM + 1}.0.0${incPr ? '-0' : ''}`
|
|
403
406
|
} else if (isX(tp)) {
|
|
404
|
-
to = `<${tM}.${+tm + 1}.0`
|
|
407
|
+
to = `<${tM}.${+tm + 1}.0${incPr ? '-0' : ''}`
|
|
405
408
|
} else if (tpr) {
|
|
406
409
|
to = `<=${tM}.${tm}.${tp}-${tpr}`
|
|
410
|
+
} else if (incPr) {
|
|
411
|
+
to = `<${tM}.${tm}.${+tp + 1}-0`
|
|
407
412
|
} else {
|
|
408
413
|
to = `<=${to}`
|
|
409
414
|
}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semver",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "The semantic version parser used by npm.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"postpublish": "git push origin --follow-tags"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"tap": "^14.10.
|
|
14
|
+
"tap": "^14.10.7"
|
|
15
15
|
},
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"repository": "https://github.com/npm/node-semver",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"semver": "./bin/semver.js"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
-
"bin",
|
|
22
|
+
"bin/**/*.js",
|
|
23
23
|
"range.bnf",
|
|
24
|
-
"classes",
|
|
25
|
-
"functions",
|
|
26
|
-
"internal",
|
|
27
|
-
"ranges",
|
|
24
|
+
"classes/**/*.js",
|
|
25
|
+
"functions/**/*.js",
|
|
26
|
+
"internal/**/*.js",
|
|
27
|
+
"ranges/**/*.js",
|
|
28
28
|
"index.js",
|
|
29
29
|
"preload.js"
|
|
30
30
|
],
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// given a set of versions and a range, create a "simplified" range
|
|
2
|
+
// that includes the same versions that the original range does
|
|
3
|
+
// If the original range is shorter than the simplified one, return that.
|
|
4
|
+
const satisfies = require('../functions/satisfies.js')
|
|
5
|
+
const compare = require('../functions/compare.js')
|
|
6
|
+
module.exports = (versions, range, options) => {
|
|
7
|
+
const set = []
|
|
8
|
+
let min = null
|
|
9
|
+
let prev = null
|
|
10
|
+
const v = versions.sort((a, b) => compare(a, b, options))
|
|
11
|
+
for (const version of v) {
|
|
12
|
+
const included = satisfies(version, range, options)
|
|
13
|
+
if (included) {
|
|
14
|
+
prev = version
|
|
15
|
+
if (!min)
|
|
16
|
+
min = version
|
|
17
|
+
} else {
|
|
18
|
+
if (prev) {
|
|
19
|
+
set.push([min, prev])
|
|
20
|
+
}
|
|
21
|
+
prev = null
|
|
22
|
+
min = null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (min)
|
|
26
|
+
set.push([min, null])
|
|
27
|
+
|
|
28
|
+
const ranges = []
|
|
29
|
+
for (const [min, max] of set) {
|
|
30
|
+
if (min === max)
|
|
31
|
+
ranges.push(min)
|
|
32
|
+
else if (!max && min === v[0])
|
|
33
|
+
ranges.push('*')
|
|
34
|
+
else if (!max)
|
|
35
|
+
ranges.push(`>=${min}`)
|
|
36
|
+
else if (min === v[0])
|
|
37
|
+
ranges.push(`<=${max}`)
|
|
38
|
+
else
|
|
39
|
+
ranges.push(`${min} - ${max}`)
|
|
40
|
+
}
|
|
41
|
+
const simplified = ranges.join(' || ')
|
|
42
|
+
const original = typeof range.raw === 'string' ? range.raw : String(range)
|
|
43
|
+
return simplified.length < original.length ? simplified : range
|
|
44
|
+
}
|