semver 7.3.4 → 7.3.5
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/package.json +1 -1
- package/ranges/subset.js +67 -7
package/package.json
CHANGED
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,13 +31,16 @@ 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) => {
|
|
43
|
+
const subset = (sub, dom, options = {}) => {
|
|
33
44
|
if (sub === dom)
|
|
34
45
|
return true
|
|
35
46
|
|
|
@@ -58,8 +69,21 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
58
69
|
if (sub === dom)
|
|
59
70
|
return true
|
|
60
71
|
|
|
61
|
-
if (sub.length === 1 && sub[0].semver === ANY)
|
|
62
|
-
|
|
72
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
73
|
+
if (dom.length === 1 && dom[0].semver === ANY)
|
|
74
|
+
return true
|
|
75
|
+
else if (options.includePrerelease)
|
|
76
|
+
sub = [ new Comparator('>=0.0.0-0') ]
|
|
77
|
+
else
|
|
78
|
+
sub = [ new Comparator('>=0.0.0') ]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
82
|
+
if (options.includePrerelease)
|
|
83
|
+
return true
|
|
84
|
+
else
|
|
85
|
+
dom = [ new Comparator('>=0.0.0') ]
|
|
86
|
+
}
|
|
63
87
|
|
|
64
88
|
const eqSet = new Set()
|
|
65
89
|
let gt, lt
|
|
@@ -102,10 +126,32 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
102
126
|
|
|
103
127
|
let higher, lower
|
|
104
128
|
let hasDomLT, hasDomGT
|
|
129
|
+
// if the subset has a prerelease, we need a comparator in the superset
|
|
130
|
+
// with the same tuple and a prerelease, or it's not a subset
|
|
131
|
+
let needDomLTPre = lt &&
|
|
132
|
+
!options.includePrerelease &&
|
|
133
|
+
lt.semver.prerelease.length ? lt.semver : false
|
|
134
|
+
let needDomGTPre = gt &&
|
|
135
|
+
!options.includePrerelease &&
|
|
136
|
+
gt.semver.prerelease.length ? gt.semver : false
|
|
137
|
+
// exception: <1.2.3-0 is the same as <1.2.3
|
|
138
|
+
if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
|
|
139
|
+
lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
|
|
140
|
+
needDomLTPre = false
|
|
141
|
+
}
|
|
142
|
+
|
|
105
143
|
for (const c of dom) {
|
|
106
144
|
hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>='
|
|
107
145
|
hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<='
|
|
108
146
|
if (gt) {
|
|
147
|
+
if (needDomGTPre) {
|
|
148
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
149
|
+
c.semver.major === needDomGTPre.major &&
|
|
150
|
+
c.semver.minor === needDomGTPre.minor &&
|
|
151
|
+
c.semver.patch === needDomGTPre.patch) {
|
|
152
|
+
needDomGTPre = false
|
|
153
|
+
}
|
|
154
|
+
}
|
|
109
155
|
if (c.operator === '>' || c.operator === '>=') {
|
|
110
156
|
higher = higherGT(gt, c, options)
|
|
111
157
|
if (higher === c && higher !== gt)
|
|
@@ -114,6 +160,14 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
114
160
|
return false
|
|
115
161
|
}
|
|
116
162
|
if (lt) {
|
|
163
|
+
if (needDomLTPre) {
|
|
164
|
+
if (c.semver.prerelease && c.semver.prerelease.length &&
|
|
165
|
+
c.semver.major === needDomLTPre.major &&
|
|
166
|
+
c.semver.minor === needDomLTPre.minor &&
|
|
167
|
+
c.semver.patch === needDomLTPre.patch) {
|
|
168
|
+
needDomLTPre = false
|
|
169
|
+
}
|
|
170
|
+
}
|
|
117
171
|
if (c.operator === '<' || c.operator === '<=') {
|
|
118
172
|
lower = lowerLT(lt, c, options)
|
|
119
173
|
if (lower === c && lower !== lt)
|
|
@@ -134,6 +188,12 @@ const simpleSubset = (sub, dom, options) => {
|
|
|
134
188
|
if (lt && hasDomGT && !gt && gtltComp !== 0)
|
|
135
189
|
return false
|
|
136
190
|
|
|
191
|
+
// we needed a prerelease range in a specific tuple, but didn't get one
|
|
192
|
+
// then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
|
|
193
|
+
// because it includes prereleases in the 1.2.3 tuple
|
|
194
|
+
if (needDomGTPre || needDomLTPre)
|
|
195
|
+
return false
|
|
196
|
+
|
|
137
197
|
return true
|
|
138
198
|
}
|
|
139
199
|
|