1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const parseVersion = str => {
|
15 | var splitAndConvert = function (str) {
|
16 | return str.split(".").map(function (item) {
|
17 |
|
18 | return +item == item ? +item : item;
|
19 | });
|
20 | };
|
21 | var match = /^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str);
|
22 |
|
23 | var ver = match[1] ? splitAndConvert(match[1]) : [];
|
24 | if (match[2]) {
|
25 | ver.length++;
|
26 | ver.push.apply(ver, splitAndConvert(match[2]));
|
27 | }
|
28 | if (match[3]) {
|
29 | ver.push([]);
|
30 | ver.push.apply(ver, splitAndConvert(match[3]));
|
31 | }
|
32 | return ver;
|
33 | };
|
34 | exports.parseVersion = parseVersion;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | const versionLt = (a, b) => {
|
43 |
|
44 | a = parseVersion(a);
|
45 |
|
46 | b = parseVersion(b);
|
47 | var i = 0;
|
48 | for (;;) {
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | if (i >= a.length) return i < b.length && (typeof b[i])[0] != "u";
|
61 |
|
62 | var aValue = a[i];
|
63 | var aType = (typeof aValue)[0];
|
64 |
|
65 |
|
66 | if (i >= b.length) return aType == "u";
|
67 |
|
68 | var bValue = b[i];
|
69 | var bType = (typeof bValue)[0];
|
70 |
|
71 | if (aType == bType) {
|
72 | if (aType != "o" && aType != "u" && aValue != bValue) {
|
73 | return aValue < bValue;
|
74 | }
|
75 | i++;
|
76 | } else {
|
77 |
|
78 | if (aType == "o" && bType == "n") return true;
|
79 | return bType == "s" || aType == "u";
|
80 | }
|
81 | }
|
82 | };
|
83 |
|
84 | exports.versionLt = versionLt;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | exports.parseRange = str => {
|
91 | const splitAndConvert = str => {
|
92 | return str.split(".").map(item => (`${+item}` === item ? +item : item));
|
93 | };
|
94 |
|
95 | const parsePartial = str => {
|
96 | const match = /^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(str);
|
97 |
|
98 | const ver = match[1] ? [0, ...splitAndConvert(match[1])] : [0];
|
99 | if (match[2]) {
|
100 | ver.length++;
|
101 | ver.push.apply(ver, splitAndConvert(match[2]));
|
102 | }
|
103 |
|
104 |
|
105 | let last = ver[ver.length - 1];
|
106 | while (
|
107 | ver.length &&
|
108 | (last === undefined || /^[*xX]$/.test( (last)))
|
109 | ) {
|
110 | ver.pop();
|
111 | last = ver[ver.length - 1];
|
112 | }
|
113 |
|
114 | return ver;
|
115 | };
|
116 | const toFixed = range => {
|
117 | if (range.length === 1) {
|
118 |
|
119 | return [0];
|
120 | } else if (range.length === 2) {
|
121 |
|
122 | return [1, ...range.slice(1)];
|
123 | } else if (range.length === 3) {
|
124 |
|
125 | return [2, ...range.slice(1)];
|
126 | } else {
|
127 | return [range.length, ...range.slice(1)];
|
128 | }
|
129 | };
|
130 | const negate = range => {
|
131 | return [-range[0] - 1, ...range.slice(1)];
|
132 | };
|
133 | const parseSimple = str => {
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | const match = /^(\^|~|<=|<|>=|>|=|v|!)/.exec(str);
|
139 | const start = match ? match[0] : "";
|
140 | const remainder = parsePartial(str.slice(start.length));
|
141 | switch (start) {
|
142 | case "^":
|
143 | if (remainder.length > 1 && remainder[1] === 0) {
|
144 | if (remainder.length > 2 && remainder[2] === 0) {
|
145 | return [3, ...remainder.slice(1)];
|
146 | }
|
147 | return [2, ...remainder.slice(1)];
|
148 | }
|
149 | return [1, ...remainder.slice(1)];
|
150 | case "~":
|
151 | return [2, ...remainder.slice(1)];
|
152 | case ">=":
|
153 | return remainder;
|
154 | case "=":
|
155 | case "v":
|
156 | case "":
|
157 | return toFixed(remainder);
|
158 | case "<":
|
159 | return negate(remainder);
|
160 | case ">": {
|
161 |
|
162 | const fixed = toFixed(remainder);
|
163 |
|
164 | return [, fixed, 0, remainder, 2];
|
165 | }
|
166 | case "<=":
|
167 |
|
168 |
|
169 | return [, toFixed(remainder), negate(remainder), 1];
|
170 | case "!": {
|
171 |
|
172 | const fixed = toFixed(remainder);
|
173 |
|
174 | return [, fixed, 0];
|
175 | }
|
176 | default:
|
177 | throw new Error("Unexpected start value");
|
178 | }
|
179 | };
|
180 | const combine = (items, fn) => {
|
181 | if (items.length === 1) return items[0];
|
182 | const arr = [];
|
183 | for (const item of items.slice().reverse()) {
|
184 | if (0 in item) {
|
185 | arr.push(item);
|
186 | } else {
|
187 | arr.push(...item.slice(1));
|
188 | }
|
189 | }
|
190 |
|
191 | return [, ...arr, ...items.slice(1).map(() => fn)];
|
192 | };
|
193 | const parseRange = str => {
|
194 |
|
195 |
|
196 | const items = str.split(" - ");
|
197 | if (items.length === 1) {
|
198 | const items = str.trim().split(/\s+/g).map(parseSimple);
|
199 | return combine(items, 2);
|
200 | }
|
201 | const a = parsePartial(items[0]);
|
202 | const b = parsePartial(items[1]);
|
203 |
|
204 |
|
205 | return [, toFixed(b), negate(b), 1, a, 2];
|
206 | };
|
207 | const parseLogicalOr = str => {
|
208 |
|
209 |
|
210 | const items = str.split(/\s*\|\|\s*/).map(parseRange);
|
211 | return combine(items, 1);
|
212 | };
|
213 | return parseLogicalOr(str);
|
214 | };
|
215 |
|
216 |
|
217 | const rangeToString = range => {
|
218 | var fixCount = range[0];
|
219 | var str = "";
|
220 | if (range.length === 1) {
|
221 | return "*";
|
222 | } else if (fixCount + 0.5) {
|
223 | str +=
|
224 | fixCount == 0
|
225 | ? ">="
|
226 | : fixCount == -1
|
227 | ? "<"
|
228 | : fixCount == 1
|
229 | ? "^"
|
230 | : fixCount == 2
|
231 | ? "~"
|
232 | : fixCount > 0
|
233 | ? "="
|
234 | : "!=";
|
235 | var needDot = 1;
|
236 |
|
237 | for (var i = 1; i < range.length; i++) {
|
238 | var item = range[i];
|
239 | var t = (typeof item)[0];
|
240 | needDot--;
|
241 | str +=
|
242 | t == "u"
|
243 | ?
|
244 | "-"
|
245 | :
|
246 | (needDot > 0 ? "." : "") + ((needDot = 2), item);
|
247 | }
|
248 | return str;
|
249 | } else {
|
250 | var stack = [];
|
251 |
|
252 | for (var i = 1; i < range.length; i++) {
|
253 |
|
254 | var item = range[i];
|
255 | stack.push(
|
256 | item === 0
|
257 | ? "not(" + pop() + ")"
|
258 | : item === 1
|
259 | ? "(" + pop() + " || " + pop() + ")"
|
260 | : item === 2
|
261 | ? stack.pop() + " " + stack.pop()
|
262 | : rangeToString(item)
|
263 | );
|
264 | }
|
265 | return pop();
|
266 | }
|
267 | function pop() {
|
268 | return stack.pop().replace(/^\((.+)\)$/, "$1");
|
269 | }
|
270 | };
|
271 |
|
272 | exports.rangeToString = rangeToString;
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | const satisfy = (range, version) => {
|
281 | if (0 in range) {
|
282 |
|
283 | version = parseVersion(version);
|
284 | var fixCount = range[0];
|
285 |
|
286 | var negated = fixCount < 0;
|
287 | if (negated) fixCount = -fixCount - 1;
|
288 | for (var i = 0, j = 1, isEqual = true; ; j++, i++) {
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 | var rangeType = j < range.length ? (typeof range[j])[0] : "";
|
334 |
|
335 | var versionValue;
|
336 | var versionType;
|
337 |
|
338 |
|
339 | if (
|
340 | i >= version.length ||
|
341 | ((versionValue = version[i]),
|
342 | (versionType = (typeof versionValue)[0]) == "o")
|
343 | ) {
|
344 |
|
345 | if (!isEqual) return true;
|
346 |
|
347 | if (rangeType == "u") return j > fixCount && !negated;
|
348 |
|
349 | return (rangeType == "") != negated;
|
350 | }
|
351 |
|
352 |
|
353 | if (versionType == "u") {
|
354 | if (!isEqual || rangeType != "u") {
|
355 | return false;
|
356 | }
|
357 | }
|
358 |
|
359 |
|
360 | else if (isEqual) {
|
361 |
|
362 | if (rangeType == versionType) {
|
363 | if (j <= fixCount) {
|
364 |
|
365 | if (versionValue != range[j]) {
|
366 | return false;
|
367 | }
|
368 | } else {
|
369 |
|
370 | if (negated ? versionValue > range[j] : versionValue < range[j]) {
|
371 | return false;
|
372 | }
|
373 | if (versionValue != range[j]) isEqual = false;
|
374 | }
|
375 | }
|
376 |
|
377 |
|
378 | else if (rangeType != "s" && rangeType != "n") {
|
379 | if (negated || j <= fixCount) return false;
|
380 | isEqual = false;
|
381 | j--;
|
382 | }
|
383 |
|
384 |
|
385 | else if (j <= fixCount || versionType < rangeType != negated) {
|
386 | return false;
|
387 | } else {
|
388 | isEqual = false;
|
389 | }
|
390 | } else {
|
391 |
|
392 | if (rangeType != "s" && rangeType != "n") {
|
393 | isEqual = false;
|
394 | j--;
|
395 | }
|
396 |
|
397 |
|
398 | }
|
399 | }
|
400 | }
|
401 |
|
402 | var stack = [];
|
403 | var p = stack.pop.bind(stack);
|
404 |
|
405 | for (var i = 1; i < range.length; i++) {
|
406 | var item = (range[i]);
|
407 | stack.push(
|
408 | item == 1
|
409 | ? p() | p()
|
410 | : item == 2
|
411 | ? p() & p()
|
412 | : item
|
413 | ? satisfy(item, version)
|
414 | : !p()
|
415 | );
|
416 | }
|
417 | return !!p();
|
418 | };
|
419 |
|
420 | exports.satisfy = satisfy;
|
421 |
|
422 | exports.stringifyHoley = json => {
|
423 | switch (typeof json) {
|
424 | case "undefined":
|
425 | return "";
|
426 | case "object":
|
427 | if (Array.isArray(json)) {
|
428 | let str = "[";
|
429 | for (let i = 0; i < json.length; i++) {
|
430 | if (i !== 0) str += ",";
|
431 | str += this.stringifyHoley(json[i]);
|
432 | }
|
433 | str += "]";
|
434 | return str;
|
435 | } else {
|
436 | return JSON.stringify(json);
|
437 | }
|
438 | default:
|
439 | return JSON.stringify(json);
|
440 | }
|
441 | };
|
442 |
|
443 |
|
444 | exports.parseVersionRuntimeCode = runtimeTemplate =>
|
445 | `var parseVersion = ${runtimeTemplate.basicFunction("str", [
|
446 | "// see webpack/lib/util/semver.js for original code",
|
447 | `var p=${
|
448 | runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"
|
449 | }{return p.split(".").map((${
|
450 | runtimeTemplate.supportsArrowFunction() ? "p=>" : "function(p)"
|
451 | }{return+p==p?+p:p}))},n=/^([^-+]+)?(?:-([^+]+))?(?:\\+(.+))?$/.exec(str),r=n[1]?p(n[1]):[];return n[2]&&(r.length++,r.push.apply(r,p(n[2]))),n[3]&&(r.push([]),r.push.apply(r,p(n[3]))),r;`
|
452 | ])}`;
|
453 |
|
454 |
|
455 |
|
456 | exports.versionLtRuntimeCode = runtimeTemplate =>
|
457 | `var versionLt = ${runtimeTemplate.basicFunction("a, b", [
|
458 | "// see webpack/lib/util/semver.js for original code",
|
459 | 'a=parseVersion(a),b=parseVersion(b);for(var r=0;;){if(r>=a.length)return r<b.length&&"u"!=(typeof b[r])[0];var e=a[r],n=(typeof e)[0];if(r>=b.length)return"u"==n;var t=b[r],f=(typeof t)[0];if(n!=f)return"o"==n&&"n"==f||("s"==f||"u"==n);if("o"!=n&&"u"!=n&&e!=t)return e<t;r++}'
|
460 | ])}`;
|
461 |
|
462 |
|
463 |
|
464 | exports.rangeToStringRuntimeCode = runtimeTemplate =>
|
465 | `var rangeToString = ${runtimeTemplate.basicFunction("range", [
|
466 | "// see webpack/lib/util/semver.js for original code",
|
467 | 'var r=range[0],n="";if(1===range.length)return"*";if(r+.5){n+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var e=1,a=1;a<range.length;a++){e--,n+="u"==(typeof(t=range[a]))[0]?"-":(e>0?".":"")+(e=2,t)}return n}var g=[];for(a=1;a<range.length;a++){var t=range[a];g.push(0===t?"not("+o()+")":1===t?"("+o()+" || "+o()+")":2===t?g.pop()+" "+g.pop():rangeToString(t))}return o();function o(){return g.pop().replace(/^\\((.+)\\)$/,"$1")}'
|
468 | ])}`;
|
469 |
|
470 |
|
471 |
|
472 | exports.satisfyRuntimeCode = runtimeTemplate =>
|
473 | `var satisfy = ${runtimeTemplate.basicFunction("range, version", [
|
474 | "// see webpack/lib/util/semver.js for original code",
|
475 | 'if(0 in range){version=parseVersion(version);var e=range[0],r=e<0;r&&(e=-e-1);for(var n=0,i=1,a=!0;;i++,n++){var f,s,g=i<range.length?(typeof range[i])[0]:"";if(n>=version.length||"o"==(s=(typeof(f=version[n]))[0]))return!a||("u"==g?i>e&&!r:""==g!=r);if("u"==s){if(!a||"u"!=g)return!1}else if(a)if(g==s)if(i<=e){if(f!=range[i])return!1}else{if(r?f>range[i]:f<range[i])return!1;f!=range[i]&&(a=!1)}else if("s"!=g&&"n"!=g){if(r||i<=e)return!1;a=!1,i--}else{if(i<=e||s<g!=r)return!1;a=!1}else"s"!=g&&"n"!=g&&(a=!1,i--)}}var t=[],o=t.pop.bind(t);for(n=1;n<range.length;n++){var u=range[n];t.push(1==u?o()|o():2==u?o()&o():u?satisfy(u,version):!o())}return!!o();'
|
476 | ])}`;
|
477 |
|