semver 7.3.4 → 7.3.7
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 +3 -1
- package/bin/semver.js +19 -9
- package/classes/comparator.js +3 -2
- package/classes/index.js +1 -1
- package/classes/range.js +31 -22
- package/classes/semver.js +1 -1
- package/functions/cmp.js +8 -4
- package/functions/coerce.js +3 -2
- package/functions/inc.js +4 -1
- package/functions/parse.js +1 -1
- package/internal/constants.js +2 -2
- package/internal/identifiers.js +1 -1
- package/internal/parse-options.js +3 -3
- package/internal/re.js +3 -3
- package/package.json +45 -11
- package/ranges/min-version.js +2 -1
- package/ranges/outside.js +1 -1
- package/ranges/simplify.js +15 -12
- package/ranges/subset.js +111 -29
- package/CHANGELOG.md +0 -111
package/README.md
CHANGED
|
@@ -264,7 +264,9 @@ provided tuple parts.
|
|
|
264
264
|
Any of `X`, `x`, or `*` may be used to "stand in" for one of the
|
|
265
265
|
numeric values in the `[major, minor, patch]` tuple.
|
|
266
266
|
|
|
267
|
-
* `*` := `>=0.0.0` (Any version satisfies
|
|
267
|
+
* `*` := `>=0.0.0` (Any non-prerelease version satisfies, unless
|
|
268
|
+
`includePrerelease` is specified, in which case any version at all
|
|
269
|
+
satisfies)
|
|
268
270
|
* `1.x` := `>=1.0.0 <2.0.0-0` (Matching major version)
|
|
269
271
|
* `1.2.x` := `>=1.2.0 <1.3.0-0` (Matching major and minor versions)
|
|
270
272
|
|
package/bin/semver.js
CHANGED
|
@@ -27,16 +27,19 @@ const semver = require('../')
|
|
|
27
27
|
|
|
28
28
|
let reverse = false
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
let options = {}
|
|
31
31
|
|
|
32
32
|
const main = () => {
|
|
33
|
-
if (!argv.length)
|
|
33
|
+
if (!argv.length) {
|
|
34
|
+
return help()
|
|
35
|
+
}
|
|
34
36
|
while (argv.length) {
|
|
35
37
|
let a = argv.shift()
|
|
36
38
|
const indexOfEqualSign = a.indexOf('=')
|
|
37
39
|
if (indexOfEqualSign !== -1) {
|
|
40
|
+
const value = a.slice(indexOfEqualSign + 1)
|
|
38
41
|
a = a.slice(0, indexOfEqualSign)
|
|
39
|
-
argv.unshift(
|
|
42
|
+
argv.unshift(value)
|
|
40
43
|
}
|
|
41
44
|
switch (a) {
|
|
42
45
|
case '-rv': case '-rev': case '--rev': case '--reverse':
|
|
@@ -85,26 +88,31 @@ const main = () => {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
options = { loose: loose, includePrerelease: includePrerelease, rtl: rtl }
|
|
89
92
|
|
|
90
93
|
versions = versions.map((v) => {
|
|
91
94
|
return coerce ? (semver.coerce(v, options) || { version: v }).version : v
|
|
92
95
|
}).filter((v) => {
|
|
93
96
|
return semver.valid(v)
|
|
94
97
|
})
|
|
95
|
-
if (!versions.length)
|
|
96
|
-
|
|
98
|
+
if (!versions.length) {
|
|
99
|
+
return fail()
|
|
100
|
+
}
|
|
101
|
+
if (inc && (versions.length !== 1 || range.length)) {
|
|
102
|
+
return failInc()
|
|
103
|
+
}
|
|
97
104
|
|
|
98
105
|
for (let i = 0, l = range.length; i < l; i++) {
|
|
99
106
|
versions = versions.filter((v) => {
|
|
100
107
|
return semver.satisfies(v, range[i], options)
|
|
101
108
|
})
|
|
102
|
-
if (!versions.length)
|
|
109
|
+
if (!versions.length) {
|
|
110
|
+
return fail()
|
|
111
|
+
}
|
|
103
112
|
}
|
|
104
113
|
return success(versions)
|
|
105
114
|
}
|
|
106
115
|
|
|
107
|
-
|
|
108
116
|
const failInc = () => {
|
|
109
117
|
console.error('--inc can only be used on a single version with no range')
|
|
110
118
|
fail()
|
|
@@ -120,7 +128,9 @@ const success = () => {
|
|
|
120
128
|
return semver.clean(v, options)
|
|
121
129
|
}).map((v) => {
|
|
122
130
|
return inc ? semver.inc(v, inc, options, identifier) : v
|
|
123
|
-
}).forEach((v, i, _) => {
|
|
131
|
+
}).forEach((v, i, _) => {
|
|
132
|
+
console.log(v)
|
|
133
|
+
})
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
const help = () => console.log(
|
package/classes/comparator.js
CHANGED
|
@@ -4,6 +4,7 @@ class Comparator {
|
|
|
4
4
|
static get ANY () {
|
|
5
5
|
return ANY
|
|
6
6
|
}
|
|
7
|
+
|
|
7
8
|
constructor (comp, options) {
|
|
8
9
|
options = parseOptions(options)
|
|
9
10
|
|
|
@@ -80,7 +81,7 @@ class Comparator {
|
|
|
80
81
|
if (!options || typeof options !== 'object') {
|
|
81
82
|
options = {
|
|
82
83
|
loose: !!options,
|
|
83
|
-
includePrerelease: false
|
|
84
|
+
includePrerelease: false,
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -128,7 +129,7 @@ class Comparator {
|
|
|
128
129
|
module.exports = Comparator
|
|
129
130
|
|
|
130
131
|
const parseOptions = require('../internal/parse-options')
|
|
131
|
-
const {re, t} = require('../internal/re')
|
|
132
|
+
const { re, t } = require('../internal/re')
|
|
132
133
|
const cmp = require('../functions/cmp')
|
|
133
134
|
const debug = require('../internal/debug')
|
|
134
135
|
const SemVer = require('./semver')
|
package/classes/index.js
CHANGED
package/classes/range.js
CHANGED
|
@@ -29,9 +29,9 @@ class Range {
|
|
|
29
29
|
// First, split based on boolean or ||
|
|
30
30
|
this.raw = range
|
|
31
31
|
this.set = range
|
|
32
|
-
.split(
|
|
32
|
+
.split('||')
|
|
33
33
|
// map the range to a 2d array of comparators
|
|
34
|
-
.map(
|
|
34
|
+
.map(r => this.parseRange(r.trim()))
|
|
35
35
|
// throw out any comparator lists that are empty
|
|
36
36
|
// this generally means that it was not a valid range, which is allowed
|
|
37
37
|
// in loose mode, but will still throw if the WHOLE range is invalid.
|
|
@@ -46,9 +46,9 @@ class Range {
|
|
|
46
46
|
// keep the first one, in case they're all null sets
|
|
47
47
|
const first = this.set[0]
|
|
48
48
|
this.set = this.set.filter(c => !isNullSet(c[0]))
|
|
49
|
-
if (this.set.length === 0)
|
|
49
|
+
if (this.set.length === 0) {
|
|
50
50
|
this.set = [first]
|
|
51
|
-
else if (this.set.length > 1) {
|
|
51
|
+
} else if (this.set.length > 1) {
|
|
52
52
|
// if we have any that are *, then the range is just *
|
|
53
53
|
for (const c of this.set) {
|
|
54
54
|
if (c.length === 1 && isAny(c[0])) {
|
|
@@ -84,8 +84,9 @@ class Range {
|
|
|
84
84
|
const memoOpts = Object.keys(this.options).join(',')
|
|
85
85
|
const memoKey = `parseRange:${memoOpts}:${range}`
|
|
86
86
|
const cached = cache.get(memoKey)
|
|
87
|
-
if (cached)
|
|
87
|
+
if (cached) {
|
|
88
88
|
return cached
|
|
89
|
+
}
|
|
89
90
|
|
|
90
91
|
const loose = this.options.loose
|
|
91
92
|
// `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
|
|
@@ -94,7 +95,7 @@ class Range {
|
|
|
94
95
|
debug('hyphen replace', range)
|
|
95
96
|
// `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
|
|
96
97
|
range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace)
|
|
97
|
-
debug('comparator trim', range
|
|
98
|
+
debug('comparator trim', range)
|
|
98
99
|
|
|
99
100
|
// `~ 1.2.3` => `~1.2.3`
|
|
100
101
|
range = range.replace(re[t.TILDETRIM], tildeTrimReplace)
|
|
@@ -108,30 +109,37 @@ class Range {
|
|
|
108
109
|
// At this point, the range is completely trimmed and
|
|
109
110
|
// ready to be split into comparators.
|
|
110
111
|
|
|
111
|
-
|
|
112
|
-
const rangeList = range
|
|
112
|
+
let rangeList = range
|
|
113
113
|
.split(' ')
|
|
114
114
|
.map(comp => parseComparator(comp, this.options))
|
|
115
115
|
.join(' ')
|
|
116
116
|
.split(/\s+/)
|
|
117
117
|
// >=0.0.0 is equivalent to *
|
|
118
118
|
.map(comp => replaceGTE0(comp, this.options))
|
|
119
|
+
|
|
120
|
+
if (loose) {
|
|
119
121
|
// in loose mode, throw out any that are not valid comparators
|
|
120
|
-
.filter(
|
|
121
|
-
|
|
122
|
+
rangeList = rangeList.filter(comp => {
|
|
123
|
+
debug('loose invalid filter', comp, this.options)
|
|
124
|
+
return !!comp.match(re[t.COMPARATORLOOSE])
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
debug('range list', rangeList)
|
|
122
128
|
|
|
123
129
|
// if any comparators are the null set, then replace with JUST null set
|
|
124
130
|
// if more than one comparator, remove any * comparators
|
|
125
131
|
// also, don't include the same comparator more than once
|
|
126
|
-
const l = rangeList.length
|
|
127
132
|
const rangeMap = new Map()
|
|
128
|
-
|
|
129
|
-
|
|
133
|
+
const comparators = rangeList.map(comp => new Comparator(comp, this.options))
|
|
134
|
+
for (const comp of comparators) {
|
|
135
|
+
if (isNullSet(comp)) {
|
|
130
136
|
return [comp]
|
|
137
|
+
}
|
|
131
138
|
rangeMap.set(comp.value, comp)
|
|
132
139
|
}
|
|
133
|
-
if (rangeMap.size > 1 && rangeMap.has(''))
|
|
140
|
+
if (rangeMap.size > 1 && rangeMap.has('')) {
|
|
134
141
|
rangeMap.delete('')
|
|
142
|
+
}
|
|
135
143
|
|
|
136
144
|
const result = [...rangeMap.values()]
|
|
137
145
|
cache.set(memoKey, result)
|
|
@@ -196,7 +204,7 @@ const {
|
|
|
196
204
|
t,
|
|
197
205
|
comparatorTrimReplace,
|
|
198
206
|
tildeTrimReplace,
|
|
199
|
-
caretTrimReplace
|
|
207
|
+
caretTrimReplace,
|
|
200
208
|
} = require('../internal/re')
|
|
201
209
|
|
|
202
210
|
const isNullSet = c => c.value === '<0.0.0-0'
|
|
@@ -245,8 +253,8 @@ const isX = id => !id || id.toLowerCase() === 'x' || id === '*'
|
|
|
245
253
|
// ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
|
|
246
254
|
// ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
|
|
247
255
|
const replaceTildes = (comp, options) =>
|
|
248
|
-
comp.trim().split(/\s+/).map((
|
|
249
|
-
return replaceTilde(
|
|
256
|
+
comp.trim().split(/\s+/).map((c) => {
|
|
257
|
+
return replaceTilde(c, options)
|
|
250
258
|
}).join(' ')
|
|
251
259
|
|
|
252
260
|
const replaceTilde = (comp, options) => {
|
|
@@ -284,8 +292,8 @@ const replaceTilde = (comp, options) => {
|
|
|
284
292
|
// ^1.2.3 --> >=1.2.3 <2.0.0-0
|
|
285
293
|
// ^1.2.0 --> >=1.2.0 <2.0.0-0
|
|
286
294
|
const replaceCarets = (comp, options) =>
|
|
287
|
-
comp.trim().split(/\s+/).map((
|
|
288
|
-
return replaceCaret(
|
|
295
|
+
comp.trim().split(/\s+/).map((c) => {
|
|
296
|
+
return replaceCaret(c, options)
|
|
289
297
|
}).join(' ')
|
|
290
298
|
|
|
291
299
|
const replaceCaret = (comp, options) => {
|
|
@@ -343,8 +351,8 @@ const replaceCaret = (comp, options) => {
|
|
|
343
351
|
|
|
344
352
|
const replaceXRanges = (comp, options) => {
|
|
345
353
|
debug('replaceXRanges', comp, options)
|
|
346
|
-
return comp.split(/\s+/).map((
|
|
347
|
-
return replaceXRange(
|
|
354
|
+
return comp.split(/\s+/).map((c) => {
|
|
355
|
+
return replaceXRange(c, options)
|
|
348
356
|
}).join(' ')
|
|
349
357
|
}
|
|
350
358
|
|
|
@@ -405,8 +413,9 @@ const replaceXRange = (comp, options) => {
|
|
|
405
413
|
}
|
|
406
414
|
}
|
|
407
415
|
|
|
408
|
-
if (gtlt === '<')
|
|
416
|
+
if (gtlt === '<') {
|
|
409
417
|
pr = '-0'
|
|
418
|
+
}
|
|
410
419
|
|
|
411
420
|
ret = `${gtlt + M}.${m}.${p}${pr}`
|
|
412
421
|
} else if (xm) {
|
package/classes/semver.js
CHANGED
|
@@ -265,7 +265,7 @@ class SemVer {
|
|
|
265
265
|
if (identifier) {
|
|
266
266
|
// 1.2.0-beta.1 bumps to 1.2.0-beta.2,
|
|
267
267
|
// 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
|
|
268
|
-
if (this.prerelease[0] ===
|
|
268
|
+
if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
|
|
269
269
|
if (isNaN(this.prerelease[1])) {
|
|
270
270
|
this.prerelease = [identifier, 0]
|
|
271
271
|
}
|
package/functions/cmp.js
CHANGED
|
@@ -8,17 +8,21 @@ const lte = require('./lte')
|
|
|
8
8
|
const cmp = (a, op, b, loose) => {
|
|
9
9
|
switch (op) {
|
|
10
10
|
case '===':
|
|
11
|
-
if (typeof a === 'object')
|
|
11
|
+
if (typeof a === 'object') {
|
|
12
12
|
a = a.version
|
|
13
|
-
|
|
13
|
+
}
|
|
14
|
+
if (typeof b === 'object') {
|
|
14
15
|
b = b.version
|
|
16
|
+
}
|
|
15
17
|
return a === b
|
|
16
18
|
|
|
17
19
|
case '!==':
|
|
18
|
-
if (typeof a === 'object')
|
|
20
|
+
if (typeof a === 'object') {
|
|
19
21
|
a = a.version
|
|
20
|
-
|
|
22
|
+
}
|
|
23
|
+
if (typeof b === 'object') {
|
|
21
24
|
b = b.version
|
|
25
|
+
}
|
|
22
26
|
return a !== b
|
|
23
27
|
|
|
24
28
|
case '':
|
package/functions/coerce.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const SemVer = require('../classes/semver')
|
|
2
2
|
const parse = require('./parse')
|
|
3
|
-
const {re, t} = require('../internal/re')
|
|
3
|
+
const { re, t } = require('../internal/re')
|
|
4
4
|
|
|
5
5
|
const coerce = (version, options) => {
|
|
6
6
|
if (version instanceof SemVer) {
|
|
@@ -43,8 +43,9 @@ const coerce = (version, options) => {
|
|
|
43
43
|
re[t.COERCERTL].lastIndex = -1
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
if (match === null)
|
|
46
|
+
if (match === null) {
|
|
47
47
|
return null
|
|
48
|
+
}
|
|
48
49
|
|
|
49
50
|
return parse(`${match[2]}.${match[3] || '0'}.${match[4] || '0'}`, options)
|
|
50
51
|
}
|
package/functions/inc.js
CHANGED
|
@@ -7,7 +7,10 @@ const inc = (version, release, options, identifier) => {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
try {
|
|
10
|
-
return new SemVer(
|
|
10
|
+
return new SemVer(
|
|
11
|
+
version instanceof SemVer ? version.version : version,
|
|
12
|
+
options
|
|
13
|
+
).inc(release, identifier).version
|
|
11
14
|
} catch (er) {
|
|
12
15
|
return null
|
|
13
16
|
}
|
package/functions/parse.js
CHANGED
package/internal/constants.js
CHANGED
|
@@ -4,7 +4,7 @@ const SEMVER_SPEC_VERSION = '2.0.0'
|
|
|
4
4
|
|
|
5
5
|
const MAX_LENGTH = 256
|
|
6
6
|
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
|
|
7
|
-
|
|
7
|
+
/* istanbul ignore next */ 9007199254740991
|
|
8
8
|
|
|
9
9
|
// Max safe segment length for coercion.
|
|
10
10
|
const MAX_SAFE_COMPONENT_LENGTH = 16
|
|
@@ -13,5 +13,5 @@ module.exports = {
|
|
|
13
13
|
SEMVER_SPEC_VERSION,
|
|
14
14
|
MAX_LENGTH,
|
|
15
15
|
MAX_SAFE_INTEGER,
|
|
16
|
-
MAX_SAFE_COMPONENT_LENGTH
|
|
16
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
17
17
|
}
|
package/internal/identifiers.js
CHANGED
|
@@ -4,8 +4,8 @@ const opts = ['includePrerelease', 'loose', 'rtl']
|
|
|
4
4
|
const parseOptions = options =>
|
|
5
5
|
!options ? {}
|
|
6
6
|
: typeof options !== 'object' ? { loose: true }
|
|
7
|
-
: opts.filter(k => options[k]).reduce((
|
|
8
|
-
|
|
9
|
-
return
|
|
7
|
+
: opts.filter(k => options[k]).reduce((o, k) => {
|
|
8
|
+
o[k] = true
|
|
9
|
+
return o
|
|
10
10
|
}, {})
|
|
11
11
|
module.exports = parseOptions
|
package/internal/re.js
CHANGED
|
@@ -10,7 +10,7 @@ let R = 0
|
|
|
10
10
|
|
|
11
11
|
const createToken = (name, value, isGlobal) => {
|
|
12
12
|
const index = R++
|
|
13
|
-
debug(index, value)
|
|
13
|
+
debug(name, index, value)
|
|
14
14
|
t[name] = index
|
|
15
15
|
src[index] = value
|
|
16
16
|
re[index] = new RegExp(value, isGlobal ? 'g' : undefined)
|
|
@@ -178,5 +178,5 @@ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
|
|
|
178
178
|
// Star ranges basically just allow anything at all.
|
|
179
179
|
createToken('STAR', '(<|>)?=?\\s*\\*')
|
|
180
180
|
// >=0.0.0 is like a star
|
|
181
|
-
createToken('GTE0', '^\\s*>=\\s*0
|
|
182
|
-
createToken('GTE0PRE', '^\\s*>=\\s*0
|
|
181
|
+
createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$')
|
|
182
|
+
createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semver",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.7",
|
|
4
4
|
"description": "The semantic version parser used by npm.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,25 +8,36 @@
|
|
|
8
8
|
"snap": "tap",
|
|
9
9
|
"preversion": "npm test",
|
|
10
10
|
"postversion": "npm publish",
|
|
11
|
-
"postpublish": "git push origin --follow-tags"
|
|
11
|
+
"postpublish": "git push origin --follow-tags",
|
|
12
|
+
"lint": "eslint \"**/*.js\"",
|
|
13
|
+
"postlint": "template-oss-check",
|
|
14
|
+
"lintfix": "npm run lint -- --fix",
|
|
15
|
+
"prepublishOnly": "git push origin --follow-tags",
|
|
16
|
+
"posttest": "npm run lint",
|
|
17
|
+
"template-oss-apply": "template-oss-apply --force"
|
|
12
18
|
},
|
|
13
19
|
"devDependencies": {
|
|
14
|
-
"
|
|
20
|
+
"@npmcli/eslint-config": "^3.0.1",
|
|
21
|
+
"@npmcli/template-oss": "3.3.2",
|
|
22
|
+
"tap": "^16.0.0"
|
|
15
23
|
},
|
|
16
24
|
"license": "ISC",
|
|
17
|
-
"repository":
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/npm/node-semver.git"
|
|
28
|
+
},
|
|
18
29
|
"bin": {
|
|
19
30
|
"semver": "bin/semver.js"
|
|
20
31
|
},
|
|
21
32
|
"files": [
|
|
22
|
-
"bin
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"ranges/**/*.js",
|
|
33
|
+
"bin/",
|
|
34
|
+
"classes/",
|
|
35
|
+
"functions/",
|
|
36
|
+
"internal/",
|
|
37
|
+
"ranges/",
|
|
28
38
|
"index.js",
|
|
29
|
-
"preload.js"
|
|
39
|
+
"preload.js",
|
|
40
|
+
"range.bnf"
|
|
30
41
|
],
|
|
31
42
|
"tap": {
|
|
32
43
|
"check-coverage": true,
|
|
@@ -37,5 +48,28 @@
|
|
|
37
48
|
},
|
|
38
49
|
"dependencies": {
|
|
39
50
|
"lru-cache": "^6.0.0"
|
|
51
|
+
},
|
|
52
|
+
"author": "GitHub Inc.",
|
|
53
|
+
"templateOSS": {
|
|
54
|
+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
|
55
|
+
"version": "3.3.2",
|
|
56
|
+
"engines": ">=10",
|
|
57
|
+
"ciVersions": [
|
|
58
|
+
"10.0.0",
|
|
59
|
+
"10.x",
|
|
60
|
+
"12.x",
|
|
61
|
+
"14.x",
|
|
62
|
+
"16.x"
|
|
63
|
+
],
|
|
64
|
+
"distPaths": [
|
|
65
|
+
"bin/",
|
|
66
|
+
"classes/",
|
|
67
|
+
"functions/",
|
|
68
|
+
"internal/",
|
|
69
|
+
"ranges/",
|
|
70
|
+
"index.js",
|
|
71
|
+
"preload.js",
|
|
72
|
+
"range.bnf"
|
|
73
|
+
]
|
|
40
74
|
}
|
|
41
75
|
}
|
package/ranges/min-version.js
CHANGED
|
@@ -47,8 +47,9 @@ const minVersion = (range, loose) => {
|
|
|
47
47
|
throw new Error(`Unexpected operation: ${comparator.operator}`)
|
|
48
48
|
}
|
|
49
49
|
})
|
|
50
|
-
if (setMin && (!minver || gt(minver, setMin)))
|
|
50
|
+
if (setMin && (!minver || gt(minver, setMin))) {
|
|
51
51
|
minver = setMin
|
|
52
|
+
}
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
if (minver && range.test(minver)) {
|
package/ranges/outside.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const SemVer = require('../classes/semver')
|
|
2
2
|
const Comparator = require('../classes/comparator')
|
|
3
|
-
const {ANY} = Comparator
|
|
3
|
+
const { ANY } = Comparator
|
|
4
4
|
const Range = require('../classes/range')
|
|
5
5
|
const satisfies = require('../functions/satisfies')
|
|
6
6
|
const gt = require('../functions/gt')
|
package/ranges/simplify.js
CHANGED
|
@@ -5,38 +5,41 @@ const satisfies = require('../functions/satisfies.js')
|
|
|
5
5
|
const compare = require('../functions/compare.js')
|
|
6
6
|
module.exports = (versions, range, options) => {
|
|
7
7
|
const set = []
|
|
8
|
-
let
|
|
8
|
+
let first = null
|
|
9
9
|
let prev = null
|
|
10
10
|
const v = versions.sort((a, b) => compare(a, b, options))
|
|
11
11
|
for (const version of v) {
|
|
12
12
|
const included = satisfies(version, range, options)
|
|
13
13
|
if (included) {
|
|
14
14
|
prev = version
|
|
15
|
-
if (!
|
|
16
|
-
|
|
15
|
+
if (!first) {
|
|
16
|
+
first = version
|
|
17
|
+
}
|
|
17
18
|
} else {
|
|
18
19
|
if (prev) {
|
|
19
|
-
set.push([
|
|
20
|
+
set.push([first, prev])
|
|
20
21
|
}
|
|
21
22
|
prev = null
|
|
22
|
-
|
|
23
|
+
first = null
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
if (
|
|
26
|
-
set.push([
|
|
26
|
+
if (first) {
|
|
27
|
+
set.push([first, null])
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
const ranges = []
|
|
29
31
|
for (const [min, max] of set) {
|
|
30
|
-
if (min === max)
|
|
32
|
+
if (min === max) {
|
|
31
33
|
ranges.push(min)
|
|
32
|
-
else if (!max && min === v[0])
|
|
34
|
+
} else if (!max && min === v[0]) {
|
|
33
35
|
ranges.push('*')
|
|
34
|
-
else if (!max)
|
|
36
|
+
} else if (!max) {
|
|
35
37
|
ranges.push(`>=${min}`)
|
|
36
|
-
else if (min === v[0])
|
|
38
|
+
} else if (min === v[0]) {
|
|
37
39
|
ranges.push(`<=${max}`)
|
|
38
|
-
else
|
|
40
|
+
} else {
|
|
39
41
|
ranges.push(`${min} - ${max}`)
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
const simplified = ranges.join(' || ')
|
|
42
45
|
const original = typeof range.raw === 'string' ? range.raw : String(range)
|
package/ranges/subset.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
const Range = require('../classes/range.js')
|
|
2
|
-
const
|
|
2
|
+
const Comparator = require('../classes/comparator.js')
|
|
3
|
+
const { ANY } = Comparator
|
|
3
4
|
const satisfies = require('../functions/satisfies.js')
|
|
4
5
|
const compare = require('../functions/compare.js')
|
|
5
6
|
|
|
6
7
|
// Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
|
|
7
|
-
// - Every simple range `r1, r2, ...` is a
|
|
8
|
+
// - Every simple range `r1, r2, ...` is a null set, OR
|
|
9
|
+
// - Every simple range `r1, r2, ...` which is not a null set is a subset of
|
|
10
|
+
// some `R1, R2, ...`
|
|
8
11
|
//
|
|
9
12
|
// Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
|
|
10
13
|
// - If c is only the ANY comparator
|
|
11
14
|
// - If C is only the ANY comparator, return true
|
|
12
|
-
// - Else return false
|
|
15
|
+
// - Else if in prerelease mode, return false
|
|
16
|
+
// - else replace c with `[>=0.0.0]`
|
|
17
|
+
// - If C is only the ANY comparator
|
|
18
|
+
// - if in prerelease mode, return true
|
|
19
|
+
// - else replace C with `[>=0.0.0]`
|
|
13
20
|
// - Let EQ be the set of = comparators in c
|
|
14
21
|
// - If EQ is more than one, return true (null set)
|
|
15
22
|
// - Let GT be the highest > or >= comparator in c
|
|
16
23
|
// - Let LT be the lowest < or <= comparator in c
|
|
17
24
|
// - If GT and LT, and GT.semver > LT.semver, return true (null set)
|
|
25
|
+
// - If any C is a = range, and GT or LT are set, return false
|
|
18
26
|
// - If EQ
|
|
19
27
|
// - If GT, and EQ does not satisfy GT, return true (null set)
|
|
20
28
|
// - If LT, and EQ does not satisfy LT, return true (null set)
|
|
@@ -23,15 +31,19 @@ const compare = require('../functions/compare.js')
|
|
|
23
31
|
// - If GT
|
|
24
32
|
// - If GT.semver is lower than any > or >= comp in C, return false
|
|
25
33
|
// - If GT is >=, and GT.semver does not satisfy every C, return false
|
|
34
|
+
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
35
|
+
// - If no C has a prerelease and the GT.semver tuple, return false
|
|
26
36
|
// - If LT
|
|
27
37
|
// - If LT.semver is greater than any < or <= comp in C, return false
|
|
28
38
|
// - If LT is <=, and LT.semver does not satisfy every C, return false
|
|
29
|
-
//
|
|
39
|
+
// - If GT.semver has a prerelease, and not in prerelease mode
|
|
40
|
+
// - If no C has a prerelease and the LT.semver tuple, return false
|
|
30
41
|
// - Else return true
|
|
31
42
|
|
|
32
|
-
const subset = (sub, dom, options) => {
|
|
33
|
-
if (sub === dom)
|
|
43
|
+
const subset = (sub, dom, options = {}) => {
|
|
44
|
+
if (sub === dom) {
|
|
34
45
|
return true
|
|
46
|
+
}
|
|
35
47
|
|
|
36
48
|
sub = new Range(sub, options)
|
|
37
49
|
dom = new Range(dom, options)
|
|
@@ -41,60 +53,84 @@ const subset = (sub, dom, options) => {
|
|
|
41
53
|
for (const simpleDom of dom.set) {
|
|
42
54
|
const isSub = simpleSubset(simpleSub, simpleDom, options)
|
|
43
55
|
sawNonNull = sawNonNull || isSub !== null
|
|
44
|
-
if (isSub)
|
|
56
|
+
if (isSub) {
|
|
45
57
|
continue OUTER
|
|
58
|
+
}
|
|
46
59
|
}
|
|
47
60
|
// the null set is a subset of everything, but null simple ranges in
|
|
48
61
|
// a complex range should be ignored. so if we saw a non-null range,
|
|
49
62
|
// then we know this isn't a subset, but if EVERY simple range was null,
|
|
50
63
|
// then it is a subset.
|
|
51
|
-
if (sawNonNull)
|
|
64
|
+
if (sawNonNull) {
|
|
52
65
|
return false
|
|
66
|
+
}
|
|
53
67
|
}
|
|
54
68
|
return true
|
|
55
69
|
}
|
|
56
70
|
|
|
57
71
|
const simpleSubset = (sub, dom, options) => {
|
|
58
|
-
if (sub === dom)
|
|
72
|
+
if (sub === dom) {
|
|
59
73
|
return true
|
|
74
|
+
}
|
|
60
75
|
|
|
61
|
-
if (sub.length === 1 && sub[0].semver === ANY)
|
|
62
|
-
|
|
76
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
77
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
78
|
+
return true
|
|
79
|
+
} else if (options.includePrerelease) {
|
|
80
|
+
sub = [new Comparator('>=0.0.0-0')]
|
|
81
|
+
} else {
|
|
82
|
+
sub = [new Comparator('>=0.0.0')]
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
87
|
+
if (options.includePrerelease) {
|
|
88
|
+
return true
|
|
89
|
+
} else {
|
|
90
|
+
dom = [new Comparator('>=0.0.0')]
|
|
91
|
+
}
|
|
92
|
+
}
|
|
63
93
|
|
|
64
94
|
const eqSet = new Set()
|
|
65
95
|
let gt, lt
|
|
66
96
|
for (const c of sub) {
|
|
67
|
-
if (c.operator === '>' || c.operator === '>=')
|
|
97
|
+
if (c.operator === '>' || c.operator === '>=') {
|
|
68
98
|
gt = higherGT(gt, c, options)
|
|
69
|
-
else if (c.operator === '<' || c.operator === '<=')
|
|
99
|
+
} else if (c.operator === '<' || c.operator === '<=') {
|
|
70
100
|
lt = lowerLT(lt, c, options)
|
|
71
|
-
else
|
|
101
|
+
} else {
|
|
72
102
|
eqSet.add(c.semver)
|
|
103
|
+
}
|
|
73
104
|
}
|
|
74
105
|
|
|
75
|
-
if (eqSet.size > 1)
|
|
106
|
+
if (eqSet.size > 1) {
|
|
76
107
|
return null
|
|
108
|
+
}
|
|
77
109
|
|
|
78
110
|
let gtltComp
|
|
79
111
|
if (gt && lt) {
|
|
80
112
|
gtltComp = compare(gt.semver, lt.semver, options)
|
|
81
|
-
if (gtltComp > 0)
|
|
113
|
+
if (gtltComp > 0) {
|
|
82
114
|
return null
|
|
83
|
-
else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<='))
|
|
115
|
+
} else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
|
|
84
116
|
return null
|
|
117
|
+
}
|
|
85
118
|
}
|
|
86
119
|
|
|
87
120
|
// will iterate one or zero times
|
|
88
121
|
for (const eq of eqSet) {
|
|
89
|
-
if (gt && !satisfies(eq, String(gt), options))
|
|
122
|
+
if (gt && !satisfies(eq, String(gt), options)) {
|
|
90
123
|
return null
|
|
124
|
+
}
|
|
91
125
|
|
|
92
|
-
if (lt && !satisfies(eq, String(lt), options))
|
|
126
|
+
if (lt && !satisfies(eq, String(lt), options)) {
|
|
93
127
|
return null
|
|
128
|
+
}
|
|
94
129
|
|
|
95
130
|
for (const c of dom) {
|
|
96
|
-
if (!satisfies(eq, String(c), options))
|
|
131
|
+
if (!satisfies(eq, String(c), options)) {
|
|
97
132
|
return false
|
|
133
|
+
}
|
|
98
134
|
}
|
|
99
135
|
|
|
100
136
|
return true
|
|
@@ -102,45 +138,90 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
102
138
|
|
|
103
139
|
let higher, lower
|
|
104
140
|
let hasDomLT, hasDomGT
|
|
141
|
+
// if the subset has a prerelease, we need a comparator in the superset
|
|
142
|
+
// with the same tuple and a prerelease, or it's not a subset
|
|
143
|
+
let needDomLTPre = lt &&
|
|
144
|
+
!options.includePrerelease &&
|
|
145
|
+
lt.semver.prerelease.length ? lt.semver : false
|
|
146
|
+
let needDomGTPre = gt &&
|
|
147
|
+
!options.includePrerelease &&
|
|
148
|
+
gt.semver.prerelease.length ? gt.semver : false
|
|
149
|
+
// exception: <1.2.3-0 is the same as <1.2.3
|
|
150
|
+
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
|
151
|
+
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
|
152
|
+
needDomLTPre = false
|
|
153
|
+
}
|
|
154
|
+
|
|
105
155
|
for (const c of dom) {
|
|
106
156
|
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>='
|
|
107
157
|
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<='
|
|
108
158
|
if (gt) {
|
|
159
|
+
if (needDomGTPre) {
|
|
160
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
161
|
+
c.semver.major === needDomGTPre.major &&
|
|
162
|
+
c.semver.minor === needDomGTPre.minor &&
|
|
163
|
+
c.semver.patch === needDomGTPre.patch) {
|
|
164
|
+
needDomGTPre = false
|
|
165
|
+
}
|
|
166
|
+
}
|
|
109
167
|
if (c.operator === '>' || c.operator === '>=') {
|
|
110
168
|
higher = higherGT(gt, c, options)
|
|
111
|
-
if (higher === c && higher !== gt)
|
|
169
|
+
if (higher === c && higher !== gt) {
|
|
112
170
|
return false
|
|
113
|
-
|
|
171
|
+
}
|
|
172
|
+
} else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) {
|
|
114
173
|
return false
|
|
174
|
+
}
|
|
115
175
|
}
|
|
116
176
|
if (lt) {
|
|
177
|
+
if (needDomLTPre) {
|
|
178
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
179
|
+
c.semver.major === needDomLTPre.major &&
|
|
180
|
+
c.semver.minor === needDomLTPre.minor &&
|
|
181
|
+
c.semver.patch === needDomLTPre.patch) {
|
|
182
|
+
needDomLTPre = false
|
|
183
|
+
}
|
|
184
|
+
}
|
|
117
185
|
if (c.operator === '<' || c.operator === '<=') {
|
|
118
186
|
lower = lowerLT(lt, c, options)
|
|
119
|
-
if (lower === c && lower !== lt)
|
|
187
|
+
if (lower === c && lower !== lt) {
|
|
120
188
|
return false
|
|
121
|
-
|
|
189
|
+
}
|
|
190
|
+
} else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) {
|
|
122
191
|
return false
|
|
192
|
+
}
|
|
123
193
|
}
|
|
124
|
-
if (!c.operator && (lt || gt) && gtltComp !== 0)
|
|
194
|
+
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
125
195
|
return false
|
|
196
|
+
}
|
|
126
197
|
}
|
|
127
198
|
|
|
128
199
|
// if there was a < or >, and nothing in the dom, then must be false
|
|
129
200
|
// UNLESS it was limited by another range in the other direction.
|
|
130
201
|
// Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
|
|
131
|
-
if (gt && hasDomLT && !lt && gtltComp !== 0)
|
|
202
|
+
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
|
132
203
|
return false
|
|
204
|
+
}
|
|
133
205
|
|
|
134
|
-
if (lt && hasDomGT && !gt && gtltComp !== 0)
|
|
206
|
+
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
|
135
207
|
return false
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// we needed a prerelease range in a specific tuple, but didn't get one
|
|
211
|
+
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
|
212
|
+
// because it includes prereleases in the 1.2.3 tuple
|
|
213
|
+
if (needDomGTPre || needDomLTPre) {
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
136
216
|
|
|
137
217
|
return true
|
|
138
218
|
}
|
|
139
219
|
|
|
140
220
|
// >=1.2.3 is lower than >1.2.3
|
|
141
221
|
const higherGT = (a, b, options) => {
|
|
142
|
-
if (!a)
|
|
222
|
+
if (!a) {
|
|
143
223
|
return b
|
|
224
|
+
}
|
|
144
225
|
const comp = compare(a.semver, b.semver, options)
|
|
145
226
|
return comp > 0 ? a
|
|
146
227
|
: comp < 0 ? b
|
|
@@ -150,8 +231,9 @@ const higherGT = (a, b, options) => {
|
|
|
150
231
|
|
|
151
232
|
// <=1.2.3 is higher than <1.2.3
|
|
152
233
|
const lowerLT = (a, b, options) => {
|
|
153
|
-
if (!a)
|
|
234
|
+
if (!a) {
|
|
154
235
|
return b
|
|
236
|
+
}
|
|
155
237
|
const comp = compare(a.semver, b.semver, options)
|
|
156
238
|
return comp < 0 ? a
|
|
157
239
|
: comp > 0 ? b
|
package/CHANGELOG.md
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
# changes log
|
|
2
|
-
|
|
3
|
-
## 7.3.0
|
|
4
|
-
|
|
5
|
-
* Add `subset(r1, r2)` method to determine if `r1` range is entirely
|
|
6
|
-
contained by `r2` range.
|
|
7
|
-
|
|
8
|
-
## 7.2.3
|
|
9
|
-
|
|
10
|
-
* Fix handling of `includePrelease` mode where version ranges like `1.0.0 -
|
|
11
|
-
2.0.0` would include `3.0.0-pre` and not `1.0.0-pre`.
|
|
12
|
-
|
|
13
|
-
## 7.2.2
|
|
14
|
-
|
|
15
|
-
* Fix bug where `2.0.0-pre` would be included in `^1.0.0` if
|
|
16
|
-
`includePrerelease` was set to true.
|
|
17
|
-
|
|
18
|
-
## 7.2.0
|
|
19
|
-
|
|
20
|
-
* Add `simplifyRange` method to attempt to generate a more human-readable
|
|
21
|
-
range expression that is equivalent to a supplied range, for a given set
|
|
22
|
-
of versions.
|
|
23
|
-
|
|
24
|
-
## 7.1.2
|
|
25
|
-
|
|
26
|
-
* Remove fancy lazy-loading logic, as it was causing problems for webpack
|
|
27
|
-
users.
|
|
28
|
-
|
|
29
|
-
## 7.1.0
|
|
30
|
-
|
|
31
|
-
* Add `require('semver/preload')` to load the entire module without using
|
|
32
|
-
lazy getter methods.
|
|
33
|
-
|
|
34
|
-
## 7.0.0
|
|
35
|
-
|
|
36
|
-
* Refactor module into separate files for better tree-shaking
|
|
37
|
-
* Drop support for very old node versions, use const/let, `=>` functions,
|
|
38
|
-
and classes.
|
|
39
|
-
|
|
40
|
-
## 6.3.0
|
|
41
|
-
|
|
42
|
-
* Expose the token enum on the exports
|
|
43
|
-
|
|
44
|
-
## 6.2.0
|
|
45
|
-
|
|
46
|
-
* Coerce numbers to strings when passed to semver.coerce()
|
|
47
|
-
* Add `rtl` option to coerce from right to left
|
|
48
|
-
|
|
49
|
-
## 6.1.3
|
|
50
|
-
|
|
51
|
-
* Handle X-ranges properly in includePrerelease mode
|
|
52
|
-
|
|
53
|
-
## 6.1.2
|
|
54
|
-
|
|
55
|
-
* Do not throw when testing invalid version strings
|
|
56
|
-
|
|
57
|
-
## 6.1.1
|
|
58
|
-
|
|
59
|
-
* Add options support for semver.coerce()
|
|
60
|
-
* Handle undefined version passed to Range.test
|
|
61
|
-
|
|
62
|
-
## 6.1.0
|
|
63
|
-
|
|
64
|
-
* Add semver.compareBuild function
|
|
65
|
-
* Support `*` in semver.intersects
|
|
66
|
-
|
|
67
|
-
## 6.0
|
|
68
|
-
|
|
69
|
-
* Fix `intersects` logic.
|
|
70
|
-
|
|
71
|
-
This is technically a bug fix, but since it is also a change to behavior
|
|
72
|
-
that may require users updating their code, it is marked as a major
|
|
73
|
-
version increment.
|
|
74
|
-
|
|
75
|
-
## 5.7
|
|
76
|
-
|
|
77
|
-
* Add `minVersion` method
|
|
78
|
-
|
|
79
|
-
## 5.6
|
|
80
|
-
|
|
81
|
-
* Move boolean `loose` param to an options object, with
|
|
82
|
-
backwards-compatibility protection.
|
|
83
|
-
* Add ability to opt out of special prerelease version handling with
|
|
84
|
-
the `includePrerelease` option flag.
|
|
85
|
-
|
|
86
|
-
## 5.5
|
|
87
|
-
|
|
88
|
-
* Add version coercion capabilities
|
|
89
|
-
|
|
90
|
-
## 5.4
|
|
91
|
-
|
|
92
|
-
* Add intersection checking
|
|
93
|
-
|
|
94
|
-
## 5.3
|
|
95
|
-
|
|
96
|
-
* Add `minSatisfying` method
|
|
97
|
-
|
|
98
|
-
## 5.2
|
|
99
|
-
|
|
100
|
-
* Add `prerelease(v)` that returns prerelease components
|
|
101
|
-
|
|
102
|
-
## 5.1
|
|
103
|
-
|
|
104
|
-
* Add Backus-Naur for ranges
|
|
105
|
-
* Remove excessively cute inspection methods
|
|
106
|
-
|
|
107
|
-
## 5.0
|
|
108
|
-
|
|
109
|
-
* Remove AMD/Browserified build artifacts
|
|
110
|
-
* Fix ltr and gtr when using the `*` range
|
|
111
|
-
* Fix for range `*` with a prerelease identifier
|