@heybox/hb-sdk 0.3.3 → 0.4.1

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.
Files changed (35) hide show
  1. package/README.md +63 -28
  2. package/dist/cli-chunks/browser-RAy8e8cV.cjs +635 -0
  3. package/dist/cli-chunks/create-Ds8A82lV.cjs +1376 -0
  4. package/dist/cli-chunks/deploy-D4uxwB2W.cjs +3730 -0
  5. package/dist/cli-chunks/dev-v-tcA7mM.cjs +955 -0
  6. package/dist/cli-chunks/doctor-C8NP7bow.cjs +186 -0
  7. package/dist/cli-chunks/index-BWrMUHh9.cjs +64023 -0
  8. package/dist/cli-chunks/index-DDqd9qAR.cjs +13348 -0
  9. package/dist/cli-chunks/login-BJVOo-hq.cjs +193 -0
  10. package/dist/cli-chunks/session-Iyxc2AGl.cjs +3040 -0
  11. package/dist/cli.cjs +19 -77707
  12. package/dist/devtools/mock-host/index.html +62 -2
  13. package/dist/devtools/mock-host/main.js +3246 -20
  14. package/dist/index.cjs.js +20 -0
  15. package/dist/index.esm.js +20 -0
  16. package/dist/miniapp-publish.cjs.js +2810 -4
  17. package/dist/miniapp-publish.esm.js +2809 -4
  18. package/dist/protocol.cjs.js +15 -0
  19. package/dist/protocol.esm.js +15 -1
  20. package/dist/templates/vue3-vite-ts/README.md.ejs +6 -2
  21. package/dist/vite.cjs.js +2814 -14
  22. package/dist/vite.esm.js +2814 -14
  23. package/package.json +6 -1
  24. package/skill/SKILL.md +19 -13
  25. package/skill/references/api-protocol.md +7 -2
  26. package/skill/references/api-root.md +24 -13
  27. package/skill/references/cli.md +339 -104
  28. package/skill/scripts/sync-references.mjs +17 -1
  29. package/skill/skill.json +4 -4
  30. package/types/index.d.ts +1 -1
  31. package/types/miniapp-manifest/schema.d.ts +2 -1
  32. package/types/miniapp-publish/index.d.ts +2 -1
  33. package/types/modules/viewport/index.d.ts +33 -0
  34. package/types/protocol/capabilities.d.ts +17 -2
  35. package/types/protocol.d.ts +2 -2
package/dist/vite.esm.js CHANGED
@@ -1,20 +1,2824 @@
1
1
  import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
2
  import path from 'node:path';
3
3
 
4
- const MINIAPP_TEMPLATE_VERSION = '0.0.0';
5
- const BUILD_VERSION_RE = /^\d+\.\d+\.\d+(?:[-+].*)?$/;
6
- function getMiniappManifestBuildWarning(version) {
7
- if (version === MINIAPP_TEMPLATE_VERSION) {
8
- return '@heybox/hb-sdk 提示:package.json.version 仍是模板默认的 0.0.0;manifest 会写入,但发布前必须改成实际 x.y.z 版本';
9
- }
10
- if (!BUILD_VERSION_RE.test(version)) {
11
- return `package.json.version "${version}" 不是标准 semver,仍会写入 manifest.json`;
4
+ var re = {exports: {}};
5
+
6
+ var constants;
7
+ var hasRequiredConstants;
8
+
9
+ function requireConstants () {
10
+ if (hasRequiredConstants) return constants;
11
+ hasRequiredConstants = 1;
12
+
13
+ // Note: this is the semver.org version of the spec that it implements
14
+ // Not necessarily the package version of this code.
15
+ const SEMVER_SPEC_VERSION = '2.0.0';
16
+
17
+ const MAX_LENGTH = 256;
18
+ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
19
+ /* istanbul ignore next */ 9007199254740991;
20
+
21
+ // Max safe segment length for coercion.
22
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
23
+
24
+ // Max safe length for a build identifier. The max length minus 6 characters for
25
+ // the shortest version with a build 0.0.0+BUILD.
26
+ const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
27
+
28
+ const RELEASE_TYPES = [
29
+ 'major',
30
+ 'premajor',
31
+ 'minor',
32
+ 'preminor',
33
+ 'patch',
34
+ 'prepatch',
35
+ 'prerelease',
36
+ ];
37
+
38
+ constants = {
39
+ MAX_LENGTH,
40
+ MAX_SAFE_COMPONENT_LENGTH,
41
+ MAX_SAFE_BUILD_LENGTH,
42
+ MAX_SAFE_INTEGER,
43
+ RELEASE_TYPES,
44
+ SEMVER_SPEC_VERSION,
45
+ FLAG_INCLUDE_PRERELEASE: 0b001,
46
+ FLAG_LOOSE: 0b010,
47
+ };
48
+ return constants;
49
+ }
50
+
51
+ var debug_1;
52
+ var hasRequiredDebug;
53
+
54
+ function requireDebug () {
55
+ if (hasRequiredDebug) return debug_1;
56
+ hasRequiredDebug = 1;
57
+
58
+ const debug = (
59
+ typeof process === 'object' &&
60
+ process.env &&
61
+ process.env.NODE_DEBUG &&
62
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)
63
+ ) ? (...args) => console.error('SEMVER', ...args)
64
+ : () => {};
65
+
66
+ debug_1 = debug;
67
+ return debug_1;
68
+ }
69
+
70
+ var hasRequiredRe;
71
+
72
+ function requireRe () {
73
+ if (hasRequiredRe) return re.exports;
74
+ hasRequiredRe = 1;
75
+ (function (module, exports) {
76
+
77
+ const {
78
+ MAX_SAFE_COMPONENT_LENGTH,
79
+ MAX_SAFE_BUILD_LENGTH,
80
+ MAX_LENGTH,
81
+ } = requireConstants();
82
+ const debug = requireDebug();
83
+ exports = module.exports = {};
84
+
85
+ // The actual regexps go on exports.re
86
+ const re = exports.re = [];
87
+ const safeRe = exports.safeRe = [];
88
+ const src = exports.src = [];
89
+ const safeSrc = exports.safeSrc = [];
90
+ const t = exports.t = {};
91
+ let R = 0;
92
+
93
+ const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
94
+
95
+ // Replace some greedy regex tokens to prevent regex dos issues. These regex are
96
+ // used internally via the safeRe object since all inputs in this library get
97
+ // normalized first to trim and collapse all extra whitespace. The original
98
+ // regexes are exported for userland consumption and lower level usage. A
99
+ // future breaking change could export the safer regex only with a note that
100
+ // all input should have extra whitespace removed.
101
+ const safeRegexReplacements = [
102
+ ['\\s', 1],
103
+ ['\\d', MAX_LENGTH],
104
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
105
+ ];
106
+
107
+ const makeSafeRegex = (value) => {
108
+ for (const [token, max] of safeRegexReplacements) {
109
+ value = value
110
+ .split(`${token}*`).join(`${token}{0,${max}}`)
111
+ .split(`${token}+`).join(`${token}{1,${max}}`);
112
+ }
113
+ return value
114
+ };
115
+
116
+ const createToken = (name, value, isGlobal) => {
117
+ const safe = makeSafeRegex(value);
118
+ const index = R++;
119
+ debug(name, index, value);
120
+ t[name] = index;
121
+ src[index] = value;
122
+ safeSrc[index] = safe;
123
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
124
+ safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
125
+ };
126
+
127
+ // The following Regular Expressions can be used for tokenizing,
128
+ // validating, and parsing SemVer version strings.
129
+
130
+ // ## Numeric Identifier
131
+ // A single `0`, or a non-zero digit followed by zero or more digits.
132
+
133
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
134
+ createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
135
+
136
+ // ## Non-numeric Identifier
137
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
138
+ // more letters, digits, or hyphens.
139
+
140
+ createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
141
+
142
+ // ## Main Version
143
+ // Three dot-separated numeric identifiers.
144
+
145
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
146
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
147
+ `(${src[t.NUMERICIDENTIFIER]})`);
148
+
149
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
150
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
151
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
152
+
153
+ // ## Pre-release Version Identifier
154
+ // A numeric identifier, or a non-numeric identifier.
155
+ // Non-numeric identifiers include numeric identifiers but can be longer.
156
+ // Therefore non-numeric identifiers must go first.
157
+
158
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
159
+ }|${src[t.NUMERICIDENTIFIER]})`);
160
+
161
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
162
+ }|${src[t.NUMERICIDENTIFIERLOOSE]})`);
163
+
164
+ // ## Pre-release Version
165
+ // Hyphen, followed by one or more dot-separated pre-release version
166
+ // identifiers.
167
+
168
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
169
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
170
+
171
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
172
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
173
+
174
+ // ## Build Metadata Identifier
175
+ // Any combination of digits, letters, or hyphens.
176
+
177
+ createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
178
+
179
+ // ## Build Metadata
180
+ // Plus sign, followed by one or more period-separated build metadata
181
+ // identifiers.
182
+
183
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
184
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
185
+
186
+ // ## Full Version String
187
+ // A main version, followed optionally by a pre-release version and
188
+ // build metadata.
189
+
190
+ // Note that the only major, minor, patch, and pre-release sections of
191
+ // the version string are capturing groups. The build metadata is not a
192
+ // capturing group, because it should not ever be used in version
193
+ // comparison.
194
+
195
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
196
+ }${src[t.PRERELEASE]}?${
197
+ src[t.BUILD]}?`);
198
+
199
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`);
200
+
201
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
202
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
203
+ // common in the npm registry.
204
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
205
+ }${src[t.PRERELEASELOOSE]}?${
206
+ src[t.BUILD]}?`);
207
+
208
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
209
+
210
+ createToken('GTLT', '((?:<|>)?=?)');
211
+
212
+ // Something like "2.*" or "1.2.x".
213
+ // Note that "x.x" is a valid xRange identifier, meaning "any version"
214
+ // Only the first item is strictly required.
215
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
216
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
217
+
218
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
219
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
220
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
221
+ `(?:${src[t.PRERELEASE]})?${
222
+ src[t.BUILD]}?` +
223
+ `)?)?`);
224
+
225
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
226
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
227
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
228
+ `(?:${src[t.PRERELEASELOOSE]})?${
229
+ src[t.BUILD]}?` +
230
+ `)?)?`);
231
+
232
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
233
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
234
+
235
+ // Coercion.
236
+ // Extract anything that could conceivably be a part of a valid semver
237
+ createToken('COERCEPLAIN', `${'(^|[^\\d])' +
238
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
239
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
240
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
241
+ createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
242
+ createToken('COERCEFULL', src[t.COERCEPLAIN] +
243
+ `(?:${src[t.PRERELEASE]})?` +
244
+ `(?:${src[t.BUILD]})?` +
245
+ `(?:$|[^\\d])`);
246
+ createToken('COERCERTL', src[t.COERCE], true);
247
+ createToken('COERCERTLFULL', src[t.COERCEFULL], true);
248
+
249
+ // Tilde ranges.
250
+ // Meaning is "reasonably at or greater than"
251
+ createToken('LONETILDE', '(?:~>?)');
252
+
253
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
254
+ exports.tildeTrimReplace = '$1~';
255
+
256
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
257
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
258
+
259
+ // Caret ranges.
260
+ // Meaning is "at least and backwards compatible with"
261
+ createToken('LONECARET', '(?:\\^)');
262
+
263
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
264
+ exports.caretTrimReplace = '$1^';
265
+
266
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
267
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
268
+
269
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
270
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
271
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
272
+
273
+ // An expression to strip any whitespace between the gtlt and the thing
274
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
275
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
276
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
277
+ exports.comparatorTrimReplace = '$1$2$3';
278
+
279
+ // Something like `1.2.3 - 1.2.4`
280
+ // Note that these all use the loose form, because they'll be
281
+ // checked against either the strict or loose comparator form
282
+ // later.
283
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
284
+ `\\s+-\\s+` +
285
+ `(${src[t.XRANGEPLAIN]})` +
286
+ `\\s*$`);
287
+
288
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
289
+ `\\s+-\\s+` +
290
+ `(${src[t.XRANGEPLAINLOOSE]})` +
291
+ `\\s*$`);
292
+
293
+ // Star ranges basically just allow anything at all.
294
+ createToken('STAR', '(<|>)?=?\\s*\\*');
295
+ // >=0.0.0 is like a star
296
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
297
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
298
+ } (re, re.exports));
299
+ return re.exports;
300
+ }
301
+
302
+ var parseOptions_1;
303
+ var hasRequiredParseOptions;
304
+
305
+ function requireParseOptions () {
306
+ if (hasRequiredParseOptions) return parseOptions_1;
307
+ hasRequiredParseOptions = 1;
308
+
309
+ // parse out just the options we care about
310
+ const looseOption = Object.freeze({ loose: true });
311
+ const emptyOpts = Object.freeze({ });
312
+ const parseOptions = options => {
313
+ if (!options) {
314
+ return emptyOpts
315
+ }
316
+
317
+ if (typeof options !== 'object') {
318
+ return looseOption
319
+ }
320
+
321
+ return options
322
+ };
323
+ parseOptions_1 = parseOptions;
324
+ return parseOptions_1;
325
+ }
326
+
327
+ var identifiers;
328
+ var hasRequiredIdentifiers;
329
+
330
+ function requireIdentifiers () {
331
+ if (hasRequiredIdentifiers) return identifiers;
332
+ hasRequiredIdentifiers = 1;
333
+
334
+ const numeric = /^[0-9]+$/;
335
+ const compareIdentifiers = (a, b) => {
336
+ if (typeof a === 'number' && typeof b === 'number') {
337
+ return a === b ? 0 : a < b ? -1 : 1
338
+ }
339
+
340
+ const anum = numeric.test(a);
341
+ const bnum = numeric.test(b);
342
+
343
+ if (anum && bnum) {
344
+ a = +a;
345
+ b = +b;
346
+ }
347
+
348
+ return a === b ? 0
349
+ : (anum && !bnum) ? -1
350
+ : (bnum && !anum) ? 1
351
+ : a < b ? -1
352
+ : 1
353
+ };
354
+
355
+ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
356
+
357
+ identifiers = {
358
+ compareIdentifiers,
359
+ rcompareIdentifiers,
360
+ };
361
+ return identifiers;
362
+ }
363
+
364
+ var semver$1;
365
+ var hasRequiredSemver$1;
366
+
367
+ function requireSemver$1 () {
368
+ if (hasRequiredSemver$1) return semver$1;
369
+ hasRequiredSemver$1 = 1;
370
+
371
+ const debug = requireDebug();
372
+ const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
373
+ const { safeRe: re, t } = requireRe();
374
+
375
+ const parseOptions = requireParseOptions();
376
+ const { compareIdentifiers } = requireIdentifiers();
377
+ class SemVer {
378
+ constructor (version, options) {
379
+ options = parseOptions(options);
380
+
381
+ if (version instanceof SemVer) {
382
+ if (version.loose === !!options.loose &&
383
+ version.includePrerelease === !!options.includePrerelease) {
384
+ return version
385
+ } else {
386
+ version = version.version;
387
+ }
388
+ } else if (typeof version !== 'string') {
389
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
390
+ }
391
+
392
+ if (version.length > MAX_LENGTH) {
393
+ throw new TypeError(
394
+ `version is longer than ${MAX_LENGTH} characters`
395
+ )
396
+ }
397
+
398
+ debug('SemVer', version, options);
399
+ this.options = options;
400
+ this.loose = !!options.loose;
401
+ // this isn't actually relevant for versions, but keep it so that we
402
+ // don't run into trouble passing this.options around.
403
+ this.includePrerelease = !!options.includePrerelease;
404
+
405
+ const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
406
+
407
+ if (!m) {
408
+ throw new TypeError(`Invalid Version: ${version}`)
409
+ }
410
+
411
+ this.raw = version;
412
+
413
+ // these are actually numbers
414
+ this.major = +m[1];
415
+ this.minor = +m[2];
416
+ this.patch = +m[3];
417
+
418
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
419
+ throw new TypeError('Invalid major version')
420
+ }
421
+
422
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
423
+ throw new TypeError('Invalid minor version')
424
+ }
425
+
426
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
427
+ throw new TypeError('Invalid patch version')
428
+ }
429
+
430
+ // numberify any prerelease numeric ids
431
+ if (!m[4]) {
432
+ this.prerelease = [];
433
+ } else {
434
+ this.prerelease = m[4].split('.').map((id) => {
435
+ if (/^[0-9]+$/.test(id)) {
436
+ const num = +id;
437
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
438
+ return num
439
+ }
440
+ }
441
+ return id
442
+ });
443
+ }
444
+
445
+ this.build = m[5] ? m[5].split('.') : [];
446
+ this.format();
447
+ }
448
+
449
+ format () {
450
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
451
+ if (this.prerelease.length) {
452
+ this.version += `-${this.prerelease.join('.')}`;
453
+ }
454
+ return this.version
455
+ }
456
+
457
+ toString () {
458
+ return this.version
459
+ }
460
+
461
+ compare (other) {
462
+ debug('SemVer.compare', this.version, this.options, other);
463
+ if (!(other instanceof SemVer)) {
464
+ if (typeof other === 'string' && other === this.version) {
465
+ return 0
466
+ }
467
+ other = new SemVer(other, this.options);
468
+ }
469
+
470
+ if (other.version === this.version) {
471
+ return 0
472
+ }
473
+
474
+ return this.compareMain(other) || this.comparePre(other)
475
+ }
476
+
477
+ compareMain (other) {
478
+ if (!(other instanceof SemVer)) {
479
+ other = new SemVer(other, this.options);
480
+ }
481
+
482
+ if (this.major < other.major) {
483
+ return -1
484
+ }
485
+ if (this.major > other.major) {
486
+ return 1
487
+ }
488
+ if (this.minor < other.minor) {
489
+ return -1
490
+ }
491
+ if (this.minor > other.minor) {
492
+ return 1
493
+ }
494
+ if (this.patch < other.patch) {
495
+ return -1
496
+ }
497
+ if (this.patch > other.patch) {
498
+ return 1
499
+ }
500
+ return 0
501
+ }
502
+
503
+ comparePre (other) {
504
+ if (!(other instanceof SemVer)) {
505
+ other = new SemVer(other, this.options);
506
+ }
507
+
508
+ // NOT having a prerelease is > having one
509
+ if (this.prerelease.length && !other.prerelease.length) {
510
+ return -1
511
+ } else if (!this.prerelease.length && other.prerelease.length) {
512
+ return 1
513
+ } else if (!this.prerelease.length && !other.prerelease.length) {
514
+ return 0
515
+ }
516
+
517
+ let i = 0;
518
+ do {
519
+ const a = this.prerelease[i];
520
+ const b = other.prerelease[i];
521
+ debug('prerelease compare', i, a, b);
522
+ if (a === undefined && b === undefined) {
523
+ return 0
524
+ } else if (b === undefined) {
525
+ return 1
526
+ } else if (a === undefined) {
527
+ return -1
528
+ } else if (a === b) {
529
+ continue
530
+ } else {
531
+ return compareIdentifiers(a, b)
532
+ }
533
+ } while (++i)
534
+ }
535
+
536
+ compareBuild (other) {
537
+ if (!(other instanceof SemVer)) {
538
+ other = new SemVer(other, this.options);
539
+ }
540
+
541
+ let i = 0;
542
+ do {
543
+ const a = this.build[i];
544
+ const b = other.build[i];
545
+ debug('build compare', i, a, b);
546
+ if (a === undefined && b === undefined) {
547
+ return 0
548
+ } else if (b === undefined) {
549
+ return 1
550
+ } else if (a === undefined) {
551
+ return -1
552
+ } else if (a === b) {
553
+ continue
554
+ } else {
555
+ return compareIdentifiers(a, b)
556
+ }
557
+ } while (++i)
558
+ }
559
+
560
+ // preminor will bump the version up to the next minor release, and immediately
561
+ // down to pre-release. premajor and prepatch work the same way.
562
+ inc (release, identifier, identifierBase) {
563
+ if (release.startsWith('pre')) {
564
+ if (!identifier && identifierBase === false) {
565
+ throw new Error('invalid increment argument: identifier is empty')
566
+ }
567
+ // Avoid an invalid semver results
568
+ if (identifier) {
569
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
570
+ if (!match || match[1] !== identifier) {
571
+ throw new Error(`invalid identifier: ${identifier}`)
572
+ }
573
+ }
574
+ }
575
+
576
+ switch (release) {
577
+ case 'premajor':
578
+ this.prerelease.length = 0;
579
+ this.patch = 0;
580
+ this.minor = 0;
581
+ this.major++;
582
+ this.inc('pre', identifier, identifierBase);
583
+ break
584
+ case 'preminor':
585
+ this.prerelease.length = 0;
586
+ this.patch = 0;
587
+ this.minor++;
588
+ this.inc('pre', identifier, identifierBase);
589
+ break
590
+ case 'prepatch':
591
+ // If this is already a prerelease, it will bump to the next version
592
+ // drop any prereleases that might already exist, since they are not
593
+ // relevant at this point.
594
+ this.prerelease.length = 0;
595
+ this.inc('patch', identifier, identifierBase);
596
+ this.inc('pre', identifier, identifierBase);
597
+ break
598
+ // If the input is a non-prerelease version, this acts the same as
599
+ // prepatch.
600
+ case 'prerelease':
601
+ if (this.prerelease.length === 0) {
602
+ this.inc('patch', identifier, identifierBase);
603
+ }
604
+ this.inc('pre', identifier, identifierBase);
605
+ break
606
+ case 'release':
607
+ if (this.prerelease.length === 0) {
608
+ throw new Error(`version ${this.raw} is not a prerelease`)
609
+ }
610
+ this.prerelease.length = 0;
611
+ break
612
+
613
+ case 'major':
614
+ // If this is a pre-major version, bump up to the same major version.
615
+ // Otherwise increment major.
616
+ // 1.0.0-5 bumps to 1.0.0
617
+ // 1.1.0 bumps to 2.0.0
618
+ if (
619
+ this.minor !== 0 ||
620
+ this.patch !== 0 ||
621
+ this.prerelease.length === 0
622
+ ) {
623
+ this.major++;
624
+ }
625
+ this.minor = 0;
626
+ this.patch = 0;
627
+ this.prerelease = [];
628
+ break
629
+ case 'minor':
630
+ // If this is a pre-minor version, bump up to the same minor version.
631
+ // Otherwise increment minor.
632
+ // 1.2.0-5 bumps to 1.2.0
633
+ // 1.2.1 bumps to 1.3.0
634
+ if (this.patch !== 0 || this.prerelease.length === 0) {
635
+ this.minor++;
636
+ }
637
+ this.patch = 0;
638
+ this.prerelease = [];
639
+ break
640
+ case 'patch':
641
+ // If this is not a pre-release version, it will increment the patch.
642
+ // If it is a pre-release it will bump up to the same patch version.
643
+ // 1.2.0-5 patches to 1.2.0
644
+ // 1.2.0 patches to 1.2.1
645
+ if (this.prerelease.length === 0) {
646
+ this.patch++;
647
+ }
648
+ this.prerelease = [];
649
+ break
650
+ // This probably shouldn't be used publicly.
651
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
652
+ case 'pre': {
653
+ const base = Number(identifierBase) ? 1 : 0;
654
+
655
+ if (this.prerelease.length === 0) {
656
+ this.prerelease = [base];
657
+ } else {
658
+ let i = this.prerelease.length;
659
+ while (--i >= 0) {
660
+ if (typeof this.prerelease[i] === 'number') {
661
+ this.prerelease[i]++;
662
+ i = -2;
663
+ }
664
+ }
665
+ if (i === -1) {
666
+ // didn't increment anything
667
+ if (identifier === this.prerelease.join('.') && identifierBase === false) {
668
+ throw new Error('invalid increment argument: identifier already exists')
669
+ }
670
+ this.prerelease.push(base);
671
+ }
672
+ }
673
+ if (identifier) {
674
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
675
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
676
+ let prerelease = [identifier, base];
677
+ if (identifierBase === false) {
678
+ prerelease = [identifier];
679
+ }
680
+ if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
681
+ if (isNaN(this.prerelease[1])) {
682
+ this.prerelease = prerelease;
683
+ }
684
+ } else {
685
+ this.prerelease = prerelease;
686
+ }
687
+ }
688
+ break
689
+ }
690
+ default:
691
+ throw new Error(`invalid increment argument: ${release}`)
692
+ }
693
+ this.raw = this.format();
694
+ if (this.build.length) {
695
+ this.raw += `+${this.build.join('.')}`;
696
+ }
697
+ return this
698
+ }
699
+ }
700
+
701
+ semver$1 = SemVer;
702
+ return semver$1;
703
+ }
704
+
705
+ var parse_1;
706
+ var hasRequiredParse;
707
+
708
+ function requireParse () {
709
+ if (hasRequiredParse) return parse_1;
710
+ hasRequiredParse = 1;
711
+
712
+ const SemVer = requireSemver$1();
713
+ const parse = (version, options, throwErrors = false) => {
714
+ if (version instanceof SemVer) {
715
+ return version
716
+ }
717
+ try {
718
+ return new SemVer(version, options)
719
+ } catch (er) {
720
+ if (!throwErrors) {
721
+ return null
722
+ }
723
+ throw er
724
+ }
725
+ };
726
+
727
+ parse_1 = parse;
728
+ return parse_1;
729
+ }
730
+
731
+ var valid_1;
732
+ var hasRequiredValid$1;
733
+
734
+ function requireValid$1 () {
735
+ if (hasRequiredValid$1) return valid_1;
736
+ hasRequiredValid$1 = 1;
737
+
738
+ const parse = requireParse();
739
+ const valid = (version, options) => {
740
+ const v = parse(version, options);
741
+ return v ? v.version : null
742
+ };
743
+ valid_1 = valid;
744
+ return valid_1;
745
+ }
746
+
747
+ var clean_1;
748
+ var hasRequiredClean;
749
+
750
+ function requireClean () {
751
+ if (hasRequiredClean) return clean_1;
752
+ hasRequiredClean = 1;
753
+
754
+ const parse = requireParse();
755
+ const clean = (version, options) => {
756
+ const s = parse(version.trim().replace(/^[=v]+/, ''), options);
757
+ return s ? s.version : null
758
+ };
759
+ clean_1 = clean;
760
+ return clean_1;
761
+ }
762
+
763
+ var inc_1;
764
+ var hasRequiredInc;
765
+
766
+ function requireInc () {
767
+ if (hasRequiredInc) return inc_1;
768
+ hasRequiredInc = 1;
769
+
770
+ const SemVer = requireSemver$1();
771
+
772
+ const inc = (version, release, options, identifier, identifierBase) => {
773
+ if (typeof (options) === 'string') {
774
+ identifierBase = identifier;
775
+ identifier = options;
776
+ options = undefined;
777
+ }
778
+
779
+ try {
780
+ return new SemVer(
781
+ version instanceof SemVer ? version.version : version,
782
+ options
783
+ ).inc(release, identifier, identifierBase).version
784
+ } catch (er) {
785
+ return null
786
+ }
787
+ };
788
+ inc_1 = inc;
789
+ return inc_1;
790
+ }
791
+
792
+ var diff_1;
793
+ var hasRequiredDiff;
794
+
795
+ function requireDiff () {
796
+ if (hasRequiredDiff) return diff_1;
797
+ hasRequiredDiff = 1;
798
+
799
+ const parse = requireParse();
800
+
801
+ const diff = (version1, version2) => {
802
+ const v1 = parse(version1, null, true);
803
+ const v2 = parse(version2, null, true);
804
+ const comparison = v1.compare(v2);
805
+
806
+ if (comparison === 0) {
807
+ return null
808
+ }
809
+
810
+ const v1Higher = comparison > 0;
811
+ const highVersion = v1Higher ? v1 : v2;
812
+ const lowVersion = v1Higher ? v2 : v1;
813
+ const highHasPre = !!highVersion.prerelease.length;
814
+ const lowHasPre = !!lowVersion.prerelease.length;
815
+
816
+ if (lowHasPre && !highHasPre) {
817
+ // Going from prerelease -> no prerelease requires some special casing
818
+
819
+ // If the low version has only a major, then it will always be a major
820
+ // Some examples:
821
+ // 1.0.0-1 -> 1.0.0
822
+ // 1.0.0-1 -> 1.1.1
823
+ // 1.0.0-1 -> 2.0.0
824
+ if (!lowVersion.patch && !lowVersion.minor) {
825
+ return 'major'
826
+ }
827
+
828
+ // If the main part has no difference
829
+ if (lowVersion.compareMain(highVersion) === 0) {
830
+ if (lowVersion.minor && !lowVersion.patch) {
831
+ return 'minor'
832
+ }
833
+ return 'patch'
834
+ }
835
+ }
836
+
837
+ // add the `pre` prefix if we are going to a prerelease version
838
+ const prefix = highHasPre ? 'pre' : '';
839
+
840
+ if (v1.major !== v2.major) {
841
+ return prefix + 'major'
842
+ }
843
+
844
+ if (v1.minor !== v2.minor) {
845
+ return prefix + 'minor'
846
+ }
847
+
848
+ if (v1.patch !== v2.patch) {
849
+ return prefix + 'patch'
850
+ }
851
+
852
+ // high and low are prereleases
853
+ return 'prerelease'
854
+ };
855
+
856
+ diff_1 = diff;
857
+ return diff_1;
858
+ }
859
+
860
+ var major_1;
861
+ var hasRequiredMajor;
862
+
863
+ function requireMajor () {
864
+ if (hasRequiredMajor) return major_1;
865
+ hasRequiredMajor = 1;
866
+
867
+ const SemVer = requireSemver$1();
868
+ const major = (a, loose) => new SemVer(a, loose).major;
869
+ major_1 = major;
870
+ return major_1;
871
+ }
872
+
873
+ var minor_1;
874
+ var hasRequiredMinor;
875
+
876
+ function requireMinor () {
877
+ if (hasRequiredMinor) return minor_1;
878
+ hasRequiredMinor = 1;
879
+
880
+ const SemVer = requireSemver$1();
881
+ const minor = (a, loose) => new SemVer(a, loose).minor;
882
+ minor_1 = minor;
883
+ return minor_1;
884
+ }
885
+
886
+ var patch_1;
887
+ var hasRequiredPatch;
888
+
889
+ function requirePatch () {
890
+ if (hasRequiredPatch) return patch_1;
891
+ hasRequiredPatch = 1;
892
+
893
+ const SemVer = requireSemver$1();
894
+ const patch = (a, loose) => new SemVer(a, loose).patch;
895
+ patch_1 = patch;
896
+ return patch_1;
897
+ }
898
+
899
+ var prerelease_1;
900
+ var hasRequiredPrerelease;
901
+
902
+ function requirePrerelease () {
903
+ if (hasRequiredPrerelease) return prerelease_1;
904
+ hasRequiredPrerelease = 1;
905
+
906
+ const parse = requireParse();
907
+ const prerelease = (version, options) => {
908
+ const parsed = parse(version, options);
909
+ return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
910
+ };
911
+ prerelease_1 = prerelease;
912
+ return prerelease_1;
913
+ }
914
+
915
+ var compare_1;
916
+ var hasRequiredCompare;
917
+
918
+ function requireCompare () {
919
+ if (hasRequiredCompare) return compare_1;
920
+ hasRequiredCompare = 1;
921
+
922
+ const SemVer = requireSemver$1();
923
+ const compare = (a, b, loose) =>
924
+ new SemVer(a, loose).compare(new SemVer(b, loose));
925
+
926
+ compare_1 = compare;
927
+ return compare_1;
928
+ }
929
+
930
+ var rcompare_1;
931
+ var hasRequiredRcompare;
932
+
933
+ function requireRcompare () {
934
+ if (hasRequiredRcompare) return rcompare_1;
935
+ hasRequiredRcompare = 1;
936
+
937
+ const compare = requireCompare();
938
+ const rcompare = (a, b, loose) => compare(b, a, loose);
939
+ rcompare_1 = rcompare;
940
+ return rcompare_1;
941
+ }
942
+
943
+ var compareLoose_1;
944
+ var hasRequiredCompareLoose;
945
+
946
+ function requireCompareLoose () {
947
+ if (hasRequiredCompareLoose) return compareLoose_1;
948
+ hasRequiredCompareLoose = 1;
949
+
950
+ const compare = requireCompare();
951
+ const compareLoose = (a, b) => compare(a, b, true);
952
+ compareLoose_1 = compareLoose;
953
+ return compareLoose_1;
954
+ }
955
+
956
+ var compareBuild_1;
957
+ var hasRequiredCompareBuild;
958
+
959
+ function requireCompareBuild () {
960
+ if (hasRequiredCompareBuild) return compareBuild_1;
961
+ hasRequiredCompareBuild = 1;
962
+
963
+ const SemVer = requireSemver$1();
964
+ const compareBuild = (a, b, loose) => {
965
+ const versionA = new SemVer(a, loose);
966
+ const versionB = new SemVer(b, loose);
967
+ return versionA.compare(versionB) || versionA.compareBuild(versionB)
968
+ };
969
+ compareBuild_1 = compareBuild;
970
+ return compareBuild_1;
971
+ }
972
+
973
+ var sort_1;
974
+ var hasRequiredSort;
975
+
976
+ function requireSort () {
977
+ if (hasRequiredSort) return sort_1;
978
+ hasRequiredSort = 1;
979
+
980
+ const compareBuild = requireCompareBuild();
981
+ const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
982
+ sort_1 = sort;
983
+ return sort_1;
984
+ }
985
+
986
+ var rsort_1;
987
+ var hasRequiredRsort;
988
+
989
+ function requireRsort () {
990
+ if (hasRequiredRsort) return rsort_1;
991
+ hasRequiredRsort = 1;
992
+
993
+ const compareBuild = requireCompareBuild();
994
+ const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
995
+ rsort_1 = rsort;
996
+ return rsort_1;
997
+ }
998
+
999
+ var gt_1;
1000
+ var hasRequiredGt;
1001
+
1002
+ function requireGt () {
1003
+ if (hasRequiredGt) return gt_1;
1004
+ hasRequiredGt = 1;
1005
+
1006
+ const compare = requireCompare();
1007
+ const gt = (a, b, loose) => compare(a, b, loose) > 0;
1008
+ gt_1 = gt;
1009
+ return gt_1;
1010
+ }
1011
+
1012
+ var lt_1;
1013
+ var hasRequiredLt;
1014
+
1015
+ function requireLt () {
1016
+ if (hasRequiredLt) return lt_1;
1017
+ hasRequiredLt = 1;
1018
+
1019
+ const compare = requireCompare();
1020
+ const lt = (a, b, loose) => compare(a, b, loose) < 0;
1021
+ lt_1 = lt;
1022
+ return lt_1;
1023
+ }
1024
+
1025
+ var eq_1;
1026
+ var hasRequiredEq;
1027
+
1028
+ function requireEq () {
1029
+ if (hasRequiredEq) return eq_1;
1030
+ hasRequiredEq = 1;
1031
+
1032
+ const compare = requireCompare();
1033
+ const eq = (a, b, loose) => compare(a, b, loose) === 0;
1034
+ eq_1 = eq;
1035
+ return eq_1;
1036
+ }
1037
+
1038
+ var neq_1;
1039
+ var hasRequiredNeq;
1040
+
1041
+ function requireNeq () {
1042
+ if (hasRequiredNeq) return neq_1;
1043
+ hasRequiredNeq = 1;
1044
+
1045
+ const compare = requireCompare();
1046
+ const neq = (a, b, loose) => compare(a, b, loose) !== 0;
1047
+ neq_1 = neq;
1048
+ return neq_1;
1049
+ }
1050
+
1051
+ var gte_1;
1052
+ var hasRequiredGte;
1053
+
1054
+ function requireGte () {
1055
+ if (hasRequiredGte) return gte_1;
1056
+ hasRequiredGte = 1;
1057
+
1058
+ const compare = requireCompare();
1059
+ const gte = (a, b, loose) => compare(a, b, loose) >= 0;
1060
+ gte_1 = gte;
1061
+ return gte_1;
1062
+ }
1063
+
1064
+ var lte_1;
1065
+ var hasRequiredLte;
1066
+
1067
+ function requireLte () {
1068
+ if (hasRequiredLte) return lte_1;
1069
+ hasRequiredLte = 1;
1070
+
1071
+ const compare = requireCompare();
1072
+ const lte = (a, b, loose) => compare(a, b, loose) <= 0;
1073
+ lte_1 = lte;
1074
+ return lte_1;
1075
+ }
1076
+
1077
+ var cmp_1;
1078
+ var hasRequiredCmp;
1079
+
1080
+ function requireCmp () {
1081
+ if (hasRequiredCmp) return cmp_1;
1082
+ hasRequiredCmp = 1;
1083
+
1084
+ const eq = requireEq();
1085
+ const neq = requireNeq();
1086
+ const gt = requireGt();
1087
+ const gte = requireGte();
1088
+ const lt = requireLt();
1089
+ const lte = requireLte();
1090
+
1091
+ const cmp = (a, op, b, loose) => {
1092
+ switch (op) {
1093
+ case '===':
1094
+ if (typeof a === 'object') {
1095
+ a = a.version;
1096
+ }
1097
+ if (typeof b === 'object') {
1098
+ b = b.version;
1099
+ }
1100
+ return a === b
1101
+
1102
+ case '!==':
1103
+ if (typeof a === 'object') {
1104
+ a = a.version;
1105
+ }
1106
+ if (typeof b === 'object') {
1107
+ b = b.version;
1108
+ }
1109
+ return a !== b
1110
+
1111
+ case '':
1112
+ case '=':
1113
+ case '==':
1114
+ return eq(a, b, loose)
1115
+
1116
+ case '!=':
1117
+ return neq(a, b, loose)
1118
+
1119
+ case '>':
1120
+ return gt(a, b, loose)
1121
+
1122
+ case '>=':
1123
+ return gte(a, b, loose)
1124
+
1125
+ case '<':
1126
+ return lt(a, b, loose)
1127
+
1128
+ case '<=':
1129
+ return lte(a, b, loose)
1130
+
1131
+ default:
1132
+ throw new TypeError(`Invalid operator: ${op}`)
1133
+ }
1134
+ };
1135
+ cmp_1 = cmp;
1136
+ return cmp_1;
1137
+ }
1138
+
1139
+ var coerce_1;
1140
+ var hasRequiredCoerce;
1141
+
1142
+ function requireCoerce () {
1143
+ if (hasRequiredCoerce) return coerce_1;
1144
+ hasRequiredCoerce = 1;
1145
+
1146
+ const SemVer = requireSemver$1();
1147
+ const parse = requireParse();
1148
+ const { safeRe: re, t } = requireRe();
1149
+
1150
+ const coerce = (version, options) => {
1151
+ if (version instanceof SemVer) {
1152
+ return version
1153
+ }
1154
+
1155
+ if (typeof version === 'number') {
1156
+ version = String(version);
1157
+ }
1158
+
1159
+ if (typeof version !== 'string') {
1160
+ return null
1161
+ }
1162
+
1163
+ options = options || {};
1164
+
1165
+ let match = null;
1166
+ if (!options.rtl) {
1167
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
1168
+ } else {
1169
+ // Find the right-most coercible string that does not share
1170
+ // a terminus with a more left-ward coercible string.
1171
+ // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
1172
+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
1173
+ //
1174
+ // Walk through the string checking with a /g regexp
1175
+ // Manually set the index so as to pick up overlapping matches.
1176
+ // Stop when we get a match that ends at the string end, since no
1177
+ // coercible string can be more right-ward without the same terminus.
1178
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
1179
+ let next;
1180
+ while ((next = coerceRtlRegex.exec(version)) &&
1181
+ (!match || match.index + match[0].length !== version.length)
1182
+ ) {
1183
+ if (!match ||
1184
+ next.index + next[0].length !== match.index + match[0].length) {
1185
+ match = next;
1186
+ }
1187
+ coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
1188
+ }
1189
+ // leave it in a clean state
1190
+ coerceRtlRegex.lastIndex = -1;
1191
+ }
1192
+
1193
+ if (match === null) {
1194
+ return null
1195
+ }
1196
+
1197
+ const major = match[2];
1198
+ const minor = match[3] || '0';
1199
+ const patch = match[4] || '0';
1200
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
1201
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
1202
+
1203
+ return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
1204
+ };
1205
+ coerce_1 = coerce;
1206
+ return coerce_1;
1207
+ }
1208
+
1209
+ var truncate_1;
1210
+ var hasRequiredTruncate;
1211
+
1212
+ function requireTruncate () {
1213
+ if (hasRequiredTruncate) return truncate_1;
1214
+ hasRequiredTruncate = 1;
1215
+
1216
+ const parse = requireParse();
1217
+ const constants = requireConstants();
1218
+ const SemVer = requireSemver$1();
1219
+
1220
+ const truncate = (version, truncation, options) => {
1221
+ if (!constants.RELEASE_TYPES.includes(truncation)) {
1222
+ return null
1223
+ }
1224
+
1225
+ const clonedVersion = cloneInputVersion(version, options);
1226
+ return clonedVersion && doTruncation(clonedVersion, truncation)
1227
+ };
1228
+
1229
+ const cloneInputVersion = (version, options) => {
1230
+ const versionStringToParse = (
1231
+ version instanceof SemVer ? version.version : version
1232
+ );
1233
+
1234
+ return parse(versionStringToParse, options)
1235
+ };
1236
+
1237
+ const doTruncation = (version, truncation) => {
1238
+ if (isPrerelease(truncation)) {
1239
+ return version.version
1240
+ }
1241
+
1242
+ version.prerelease = [];
1243
+
1244
+ switch (truncation) {
1245
+ case 'major':
1246
+ version.minor = 0;
1247
+ version.patch = 0;
1248
+ break
1249
+ case 'minor':
1250
+ version.patch = 0;
1251
+ break
1252
+ }
1253
+
1254
+ return version.format()
1255
+ };
1256
+
1257
+ const isPrerelease = (type) => {
1258
+ return type.startsWith('pre')
1259
+ };
1260
+
1261
+ truncate_1 = truncate;
1262
+ return truncate_1;
1263
+ }
1264
+
1265
+ var lrucache;
1266
+ var hasRequiredLrucache;
1267
+
1268
+ function requireLrucache () {
1269
+ if (hasRequiredLrucache) return lrucache;
1270
+ hasRequiredLrucache = 1;
1271
+
1272
+ class LRUCache {
1273
+ constructor () {
1274
+ this.max = 1000;
1275
+ this.map = new Map();
1276
+ }
1277
+
1278
+ get (key) {
1279
+ const value = this.map.get(key);
1280
+ if (value === undefined) {
1281
+ return undefined
1282
+ } else {
1283
+ // Remove the key from the map and add it to the end
1284
+ this.map.delete(key);
1285
+ this.map.set(key, value);
1286
+ return value
1287
+ }
1288
+ }
1289
+
1290
+ delete (key) {
1291
+ return this.map.delete(key)
1292
+ }
1293
+
1294
+ set (key, value) {
1295
+ const deleted = this.delete(key);
1296
+
1297
+ if (!deleted && value !== undefined) {
1298
+ // If cache is full, delete the least recently used item
1299
+ if (this.map.size >= this.max) {
1300
+ const firstKey = this.map.keys().next().value;
1301
+ this.delete(firstKey);
1302
+ }
1303
+
1304
+ this.map.set(key, value);
1305
+ }
1306
+
1307
+ return this
1308
+ }
1309
+ }
1310
+
1311
+ lrucache = LRUCache;
1312
+ return lrucache;
1313
+ }
1314
+
1315
+ var range;
1316
+ var hasRequiredRange;
1317
+
1318
+ function requireRange () {
1319
+ if (hasRequiredRange) return range;
1320
+ hasRequiredRange = 1;
1321
+
1322
+ const SPACE_CHARACTERS = /\s+/g;
1323
+
1324
+ // hoisted class for cyclic dependency
1325
+ class Range {
1326
+ constructor (range, options) {
1327
+ options = parseOptions(options);
1328
+
1329
+ if (range instanceof Range) {
1330
+ if (
1331
+ range.loose === !!options.loose &&
1332
+ range.includePrerelease === !!options.includePrerelease
1333
+ ) {
1334
+ return range
1335
+ } else {
1336
+ return new Range(range.raw, options)
1337
+ }
1338
+ }
1339
+
1340
+ if (range instanceof Comparator) {
1341
+ // just put it in the set and return
1342
+ this.raw = range.value;
1343
+ this.set = [[range]];
1344
+ this.formatted = undefined;
1345
+ return this
1346
+ }
1347
+
1348
+ this.options = options;
1349
+ this.loose = !!options.loose;
1350
+ this.includePrerelease = !!options.includePrerelease;
1351
+
1352
+ // First reduce all whitespace as much as possible so we do not have to rely
1353
+ // on potentially slow regexes like \s*. This is then stored and used for
1354
+ // future error messages as well.
1355
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
1356
+
1357
+ // First, split on ||
1358
+ this.set = this.raw
1359
+ .split('||')
1360
+ // map the range to a 2d array of comparators
1361
+ .map(r => this.parseRange(r.trim()))
1362
+ // throw out any comparator lists that are empty
1363
+ // this generally means that it was not a valid range, which is allowed
1364
+ // in loose mode, but will still throw if the WHOLE range is invalid.
1365
+ .filter(c => c.length);
1366
+
1367
+ if (!this.set.length) {
1368
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
1369
+ }
1370
+
1371
+ // if we have any that are not the null set, throw out null sets.
1372
+ if (this.set.length > 1) {
1373
+ // keep the first one, in case they're all null sets
1374
+ const first = this.set[0];
1375
+ this.set = this.set.filter(c => !isNullSet(c[0]));
1376
+ if (this.set.length === 0) {
1377
+ this.set = [first];
1378
+ } else if (this.set.length > 1) {
1379
+ // if we have any that are *, then the range is just *
1380
+ for (const c of this.set) {
1381
+ if (c.length === 1 && isAny(c[0])) {
1382
+ this.set = [c];
1383
+ break
1384
+ }
1385
+ }
1386
+ }
1387
+ }
1388
+
1389
+ this.formatted = undefined;
1390
+ }
1391
+
1392
+ get range () {
1393
+ if (this.formatted === undefined) {
1394
+ this.formatted = '';
1395
+ for (let i = 0; i < this.set.length; i++) {
1396
+ if (i > 0) {
1397
+ this.formatted += '||';
1398
+ }
1399
+ const comps = this.set[i];
1400
+ for (let k = 0; k < comps.length; k++) {
1401
+ if (k > 0) {
1402
+ this.formatted += ' ';
1403
+ }
1404
+ this.formatted += comps[k].toString().trim();
1405
+ }
1406
+ }
1407
+ }
1408
+ return this.formatted
1409
+ }
1410
+
1411
+ format () {
1412
+ return this.range
1413
+ }
1414
+
1415
+ toString () {
1416
+ return this.range
1417
+ }
1418
+
1419
+ parseRange (range) {
1420
+ // strip build metadata so it can't bleed into the version
1421
+ range = range.replace(BUILDSTRIPRE, '');
1422
+
1423
+ // memoize range parsing for performance.
1424
+ // this is a very hot path, and fully deterministic.
1425
+ const memoOpts =
1426
+ (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
1427
+ (this.options.loose && FLAG_LOOSE);
1428
+ const memoKey = memoOpts + ':' + range;
1429
+ const cached = cache.get(memoKey);
1430
+ if (cached) {
1431
+ return cached
1432
+ }
1433
+
1434
+ const loose = this.options.loose;
1435
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
1436
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
1437
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
1438
+ debug('hyphen replace', range);
1439
+
1440
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
1441
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
1442
+ debug('comparator trim', range);
1443
+
1444
+ // `~ 1.2.3` => `~1.2.3`
1445
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
1446
+ debug('tilde trim', range);
1447
+
1448
+ // `^ 1.2.3` => `^1.2.3`
1449
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
1450
+ debug('caret trim', range);
1451
+
1452
+ // At this point, the range is completely trimmed and
1453
+ // ready to be split into comparators.
1454
+
1455
+ let rangeList = range
1456
+ .split(' ')
1457
+ .map(comp => parseComparator(comp, this.options))
1458
+ .join(' ')
1459
+ .split(/\s+/)
1460
+ // >=0.0.0 is equivalent to *
1461
+ .map(comp => replaceGTE0(comp, this.options));
1462
+
1463
+ if (loose) {
1464
+ // in loose mode, throw out any that are not valid comparators
1465
+ rangeList = rangeList.filter(comp => {
1466
+ debug('loose invalid filter', comp, this.options);
1467
+ return !!comp.match(re[t.COMPARATORLOOSE])
1468
+ });
1469
+ }
1470
+ debug('range list', rangeList);
1471
+
1472
+ // if any comparators are the null set, then replace with JUST null set
1473
+ // if more than one comparator, remove any * comparators
1474
+ // also, don't include the same comparator more than once
1475
+ const rangeMap = new Map();
1476
+ const comparators = rangeList.map(comp => new Comparator(comp, this.options));
1477
+ for (const comp of comparators) {
1478
+ if (isNullSet(comp)) {
1479
+ return [comp]
1480
+ }
1481
+ rangeMap.set(comp.value, comp);
1482
+ }
1483
+ if (rangeMap.size > 1 && rangeMap.has('')) {
1484
+ rangeMap.delete('');
1485
+ }
1486
+
1487
+ const result = [...rangeMap.values()];
1488
+ cache.set(memoKey, result);
1489
+ return result
1490
+ }
1491
+
1492
+ intersects (range, options) {
1493
+ if (!(range instanceof Range)) {
1494
+ throw new TypeError('a Range is required')
1495
+ }
1496
+
1497
+ return this.set.some((thisComparators) => {
1498
+ return (
1499
+ isSatisfiable(thisComparators, options) &&
1500
+ range.set.some((rangeComparators) => {
1501
+ return (
1502
+ isSatisfiable(rangeComparators, options) &&
1503
+ thisComparators.every((thisComparator) => {
1504
+ return rangeComparators.every((rangeComparator) => {
1505
+ return thisComparator.intersects(rangeComparator, options)
1506
+ })
1507
+ })
1508
+ )
1509
+ })
1510
+ )
1511
+ })
1512
+ }
1513
+
1514
+ // if ANY of the sets match ALL of its comparators, then pass
1515
+ test (version) {
1516
+ if (!version) {
1517
+ return false
1518
+ }
1519
+
1520
+ if (typeof version === 'string') {
1521
+ try {
1522
+ version = new SemVer(version, this.options);
1523
+ } catch (er) {
1524
+ return false
1525
+ }
1526
+ }
1527
+
1528
+ for (let i = 0; i < this.set.length; i++) {
1529
+ if (testSet(this.set[i], version, this.options)) {
1530
+ return true
1531
+ }
1532
+ }
1533
+ return false
1534
+ }
1535
+ }
1536
+
1537
+ range = Range;
1538
+
1539
+ const LRU = requireLrucache();
1540
+ const cache = new LRU();
1541
+
1542
+ const parseOptions = requireParseOptions();
1543
+ const Comparator = requireComparator();
1544
+ const debug = requireDebug();
1545
+ const SemVer = requireSemver$1();
1546
+ const {
1547
+ safeRe: re,
1548
+ src,
1549
+ t,
1550
+ comparatorTrimReplace,
1551
+ tildeTrimReplace,
1552
+ caretTrimReplace,
1553
+ } = requireRe();
1554
+ const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = requireConstants();
1555
+
1556
+ // unbounded global build-metadata stripper used by parseRange
1557
+ const BUILDSTRIPRE = new RegExp(src[t.BUILD], 'g');
1558
+
1559
+ const isNullSet = c => c.value === '<0.0.0-0';
1560
+ const isAny = c => c.value === '';
1561
+
1562
+ // take a set of comparators and determine whether there
1563
+ // exists a version which can satisfy it
1564
+ const isSatisfiable = (comparators, options) => {
1565
+ let result = true;
1566
+ const remainingComparators = comparators.slice();
1567
+ let testComparator = remainingComparators.pop();
1568
+
1569
+ while (result && remainingComparators.length) {
1570
+ result = remainingComparators.every((otherComparator) => {
1571
+ return testComparator.intersects(otherComparator, options)
1572
+ });
1573
+
1574
+ testComparator = remainingComparators.pop();
1575
+ }
1576
+
1577
+ return result
1578
+ };
1579
+
1580
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
1581
+ // already replaced the hyphen ranges
1582
+ // turn into a set of JUST comparators.
1583
+ const parseComparator = (comp, options) => {
1584
+ comp = comp.replace(re[t.BUILD], '');
1585
+ debug('comp', comp, options);
1586
+ comp = replaceCarets(comp, options);
1587
+ debug('caret', comp);
1588
+ comp = replaceTildes(comp, options);
1589
+ debug('tildes', comp);
1590
+ comp = replaceXRanges(comp, options);
1591
+ debug('xrange', comp);
1592
+ comp = replaceStars(comp, options);
1593
+ debug('stars', comp);
1594
+ return comp
1595
+ };
1596
+
1597
+ const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
1598
+
1599
+ // ~, ~> --> * (any, kinda silly)
1600
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
1601
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
1602
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
1603
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
1604
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
1605
+ // ~0.0.1 --> >=0.0.1 <0.1.0-0
1606
+ const replaceTildes = (comp, options) => {
1607
+ return comp
1608
+ .trim()
1609
+ .split(/\s+/)
1610
+ .map((c) => replaceTilde(c, options))
1611
+ .join(' ')
1612
+ };
1613
+
1614
+ const replaceTilde = (comp, options) => {
1615
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
1616
+ return comp.replace(r, (_, M, m, p, pr) => {
1617
+ debug('tilde', comp, _, M, m, p, pr);
1618
+ let ret;
1619
+
1620
+ if (isX(M)) {
1621
+ ret = '';
1622
+ } else if (isX(m)) {
1623
+ ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
1624
+ } else if (isX(p)) {
1625
+ // ~1.2 == >=1.2.0 <1.3.0-0
1626
+ ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
1627
+ } else if (pr) {
1628
+ debug('replaceTilde pr', pr);
1629
+ ret = `>=${M}.${m}.${p}-${pr
1630
+ } <${M}.${+m + 1}.0-0`;
1631
+ } else {
1632
+ // ~1.2.3 == >=1.2.3 <1.3.0-0
1633
+ ret = `>=${M}.${m}.${p
1634
+ } <${M}.${+m + 1}.0-0`;
1635
+ }
1636
+
1637
+ debug('tilde return', ret);
1638
+ return ret
1639
+ })
1640
+ };
1641
+
1642
+ // ^ --> * (any, kinda silly)
1643
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
1644
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
1645
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
1646
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
1647
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
1648
+ // ^0.0.1 --> >=0.0.1 <0.0.2-0
1649
+ // ^0.1.0 --> >=0.1.0 <0.2.0-0
1650
+ const replaceCarets = (comp, options) => {
1651
+ return comp
1652
+ .trim()
1653
+ .split(/\s+/)
1654
+ .map((c) => replaceCaret(c, options))
1655
+ .join(' ')
1656
+ };
1657
+
1658
+ const replaceCaret = (comp, options) => {
1659
+ debug('caret', comp, options);
1660
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
1661
+ const z = options.includePrerelease ? '-0' : '';
1662
+ return comp.replace(r, (_, M, m, p, pr) => {
1663
+ debug('caret', comp, _, M, m, p, pr);
1664
+ let ret;
1665
+
1666
+ if (isX(M)) {
1667
+ ret = '';
1668
+ } else if (isX(m)) {
1669
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1670
+ } else if (isX(p)) {
1671
+ if (M === '0') {
1672
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1673
+ } else {
1674
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
1675
+ }
1676
+ } else if (pr) {
1677
+ debug('replaceCaret pr', pr);
1678
+ if (M === '0') {
1679
+ if (m === '0') {
1680
+ ret = `>=${M}.${m}.${p}-${pr
1681
+ } <${M}.${m}.${+p + 1}-0`;
1682
+ } else {
1683
+ ret = `>=${M}.${m}.${p}-${pr
1684
+ } <${M}.${+m + 1}.0-0`;
1685
+ }
1686
+ } else {
1687
+ ret = `>=${M}.${m}.${p}-${pr
1688
+ } <${+M + 1}.0.0-0`;
1689
+ }
1690
+ } else {
1691
+ debug('no pr');
1692
+ if (M === '0') {
1693
+ if (m === '0') {
1694
+ ret = `>=${M}.${m}.${p
1695
+ }${z} <${M}.${m}.${+p + 1}-0`;
1696
+ } else {
1697
+ ret = `>=${M}.${m}.${p
1698
+ }${z} <${M}.${+m + 1}.0-0`;
1699
+ }
1700
+ } else {
1701
+ ret = `>=${M}.${m}.${p
1702
+ } <${+M + 1}.0.0-0`;
1703
+ }
1704
+ }
1705
+
1706
+ debug('caret return', ret);
1707
+ return ret
1708
+ })
1709
+ };
1710
+
1711
+ const replaceXRanges = (comp, options) => {
1712
+ debug('replaceXRanges', comp, options);
1713
+ return comp
1714
+ .split(/\s+/)
1715
+ .map((c) => replaceXRange(c, options))
1716
+ .join(' ')
1717
+ };
1718
+
1719
+ const replaceXRange = (comp, options) => {
1720
+ comp = comp.trim();
1721
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
1722
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
1723
+ debug('xRange', comp, ret, gtlt, M, m, p, pr);
1724
+ const xM = isX(M);
1725
+ const xm = xM || isX(m);
1726
+ const xp = xm || isX(p);
1727
+ const anyX = xp;
1728
+
1729
+ if (gtlt === '=' && anyX) {
1730
+ gtlt = '';
1731
+ }
1732
+
1733
+ // if we're including prereleases in the match, then we need
1734
+ // to fix this to -0, the lowest possible prerelease value
1735
+ pr = options.includePrerelease ? '-0' : '';
1736
+
1737
+ if (xM) {
1738
+ if (gtlt === '>' || gtlt === '<') {
1739
+ // nothing is allowed
1740
+ ret = '<0.0.0-0';
1741
+ } else {
1742
+ // nothing is forbidden
1743
+ ret = '*';
1744
+ }
1745
+ } else if (gtlt && anyX) {
1746
+ // we know patch is an x, because we have any x at all.
1747
+ // replace X with 0
1748
+ if (xm) {
1749
+ m = 0;
1750
+ }
1751
+ p = 0;
1752
+
1753
+ if (gtlt === '>') {
1754
+ // >1 => >=2.0.0
1755
+ // >1.2 => >=1.3.0
1756
+ gtlt = '>=';
1757
+ if (xm) {
1758
+ M = +M + 1;
1759
+ m = 0;
1760
+ p = 0;
1761
+ } else {
1762
+ m = +m + 1;
1763
+ p = 0;
1764
+ }
1765
+ } else if (gtlt === '<=') {
1766
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
1767
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
1768
+ gtlt = '<';
1769
+ if (xm) {
1770
+ M = +M + 1;
1771
+ } else {
1772
+ m = +m + 1;
1773
+ }
1774
+ }
1775
+
1776
+ if (gtlt === '<') {
1777
+ pr = '-0';
1778
+ }
1779
+
1780
+ ret = `${gtlt + M}.${m}.${p}${pr}`;
1781
+ } else if (xm) {
1782
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
1783
+ } else if (xp) {
1784
+ ret = `>=${M}.${m}.0${pr
1785
+ } <${M}.${+m + 1}.0-0`;
1786
+ }
1787
+
1788
+ debug('xRange return', ret);
1789
+
1790
+ return ret
1791
+ })
1792
+ };
1793
+
1794
+ // Because * is AND-ed with everything else in the comparator,
1795
+ // and '' means "any version", just remove the *s entirely.
1796
+ const replaceStars = (comp, options) => {
1797
+ debug('replaceStars', comp, options);
1798
+ // Looseness is ignored here. star is always as loose as it gets!
1799
+ return comp
1800
+ .trim()
1801
+ .replace(re[t.STAR], '')
1802
+ };
1803
+
1804
+ const replaceGTE0 = (comp, options) => {
1805
+ debug('replaceGTE0', comp, options);
1806
+ return comp
1807
+ .trim()
1808
+ .replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
1809
+ };
1810
+
1811
+ // This function is passed to string.replace(re[t.HYPHENRANGE])
1812
+ // M, m, patch, prerelease, build
1813
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
1814
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
1815
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0-0
1816
+ // TODO build?
1817
+ const hyphenReplace = incPr => ($0,
1818
+ from, fM, fm, fp, fpr, fb,
1819
+ to, tM, tm, tp, tpr) => {
1820
+ if (isX(fM)) {
1821
+ from = '';
1822
+ } else if (isX(fm)) {
1823
+ from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
1824
+ } else if (isX(fp)) {
1825
+ from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
1826
+ } else if (fpr) {
1827
+ from = `>=${from}`;
1828
+ } else {
1829
+ from = `>=${from}${incPr ? '-0' : ''}`;
1830
+ }
1831
+
1832
+ if (isX(tM)) {
1833
+ to = '';
1834
+ } else if (isX(tm)) {
1835
+ to = `<${+tM + 1}.0.0-0`;
1836
+ } else if (isX(tp)) {
1837
+ to = `<${tM}.${+tm + 1}.0-0`;
1838
+ } else if (tpr) {
1839
+ to = `<=${tM}.${tm}.${tp}-${tpr}`;
1840
+ } else if (incPr) {
1841
+ to = `<${tM}.${tm}.${+tp + 1}-0`;
1842
+ } else {
1843
+ to = `<=${to}`;
1844
+ }
1845
+
1846
+ return `${from} ${to}`.trim()
1847
+ };
1848
+
1849
+ const testSet = (set, version, options) => {
1850
+ for (let i = 0; i < set.length; i++) {
1851
+ if (!set[i].test(version)) {
1852
+ return false
1853
+ }
1854
+ }
1855
+
1856
+ if (version.prerelease.length && !options.includePrerelease) {
1857
+ // Find the set of versions that are allowed to have prereleases
1858
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
1859
+ // That should allow `1.2.3-pr.2` to pass.
1860
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
1861
+ // even though it's within the range set by the comparators.
1862
+ for (let i = 0; i < set.length; i++) {
1863
+ debug(set[i].semver);
1864
+ if (set[i].semver === Comparator.ANY) {
1865
+ continue
1866
+ }
1867
+
1868
+ if (set[i].semver.prerelease.length > 0) {
1869
+ const allowed = set[i].semver;
1870
+ if (allowed.major === version.major &&
1871
+ allowed.minor === version.minor &&
1872
+ allowed.patch === version.patch) {
1873
+ return true
1874
+ }
1875
+ }
1876
+ }
1877
+
1878
+ // Version has a -pre, but it's not one of the ones we like.
1879
+ return false
1880
+ }
1881
+
1882
+ return true
1883
+ };
1884
+ return range;
1885
+ }
1886
+
1887
+ var comparator;
1888
+ var hasRequiredComparator;
1889
+
1890
+ function requireComparator () {
1891
+ if (hasRequiredComparator) return comparator;
1892
+ hasRequiredComparator = 1;
1893
+
1894
+ const ANY = Symbol('SemVer ANY');
1895
+ // hoisted class for cyclic dependency
1896
+ class Comparator {
1897
+ static get ANY () {
1898
+ return ANY
1899
+ }
1900
+
1901
+ constructor (comp, options) {
1902
+ options = parseOptions(options);
1903
+
1904
+ if (comp instanceof Comparator) {
1905
+ if (comp.loose === !!options.loose) {
1906
+ return comp
1907
+ } else {
1908
+ comp = comp.value;
1909
+ }
1910
+ }
1911
+
1912
+ comp = comp.trim().split(/\s+/).join(' ');
1913
+ debug('comparator', comp, options);
1914
+ this.options = options;
1915
+ this.loose = !!options.loose;
1916
+ this.parse(comp);
1917
+
1918
+ if (this.semver === ANY) {
1919
+ this.value = '';
1920
+ } else {
1921
+ this.value = this.operator + this.semver.version;
1922
+ }
1923
+
1924
+ debug('comp', this);
1925
+ }
1926
+
1927
+ parse (comp) {
1928
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
1929
+ const m = comp.match(r);
1930
+
1931
+ if (!m) {
1932
+ throw new TypeError(`Invalid comparator: ${comp}`)
1933
+ }
1934
+
1935
+ this.operator = m[1] !== undefined ? m[1] : '';
1936
+ if (this.operator === '=') {
1937
+ this.operator = '';
1938
+ }
1939
+
1940
+ // if it literally is just '>' or '' then allow anything.
1941
+ if (!m[2]) {
1942
+ this.semver = ANY;
1943
+ } else {
1944
+ this.semver = new SemVer(m[2], this.options.loose);
1945
+ }
1946
+ }
1947
+
1948
+ toString () {
1949
+ return this.value
1950
+ }
1951
+
1952
+ test (version) {
1953
+ debug('Comparator.test', version, this.options.loose);
1954
+
1955
+ if (this.semver === ANY || version === ANY) {
1956
+ return true
1957
+ }
1958
+
1959
+ if (typeof version === 'string') {
1960
+ try {
1961
+ version = new SemVer(version, this.options);
1962
+ } catch (er) {
1963
+ return false
1964
+ }
1965
+ }
1966
+
1967
+ return cmp(version, this.operator, this.semver, this.options)
1968
+ }
1969
+
1970
+ intersects (comp, options) {
1971
+ if (!(comp instanceof Comparator)) {
1972
+ throw new TypeError('a Comparator is required')
1973
+ }
1974
+
1975
+ if (this.operator === '') {
1976
+ if (this.value === '') {
1977
+ return true
1978
+ }
1979
+ return new Range(comp.value, options).test(this.value)
1980
+ } else if (comp.operator === '') {
1981
+ if (comp.value === '') {
1982
+ return true
1983
+ }
1984
+ return new Range(this.value, options).test(comp.semver)
1985
+ }
1986
+
1987
+ options = parseOptions(options);
1988
+
1989
+ // Special cases where nothing can possibly be lower
1990
+ if (options.includePrerelease &&
1991
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
1992
+ return false
1993
+ }
1994
+ if (!options.includePrerelease &&
1995
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
1996
+ return false
1997
+ }
1998
+
1999
+ // Same direction increasing (> or >=)
2000
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
2001
+ return true
2002
+ }
2003
+ // Same direction decreasing (< or <=)
2004
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
2005
+ return true
2006
+ }
2007
+ // same SemVer and both sides are inclusive (<= or >=)
2008
+ if (
2009
+ (this.semver.version === comp.semver.version) &&
2010
+ this.operator.includes('=') && comp.operator.includes('=')) {
2011
+ return true
2012
+ }
2013
+ // opposite directions less than
2014
+ if (cmp(this.semver, '<', comp.semver, options) &&
2015
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
2016
+ return true
2017
+ }
2018
+ // opposite directions greater than
2019
+ if (cmp(this.semver, '>', comp.semver, options) &&
2020
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
2021
+ return true
2022
+ }
2023
+ return false
2024
+ }
2025
+ }
2026
+
2027
+ comparator = Comparator;
2028
+
2029
+ const parseOptions = requireParseOptions();
2030
+ const { safeRe: re, t } = requireRe();
2031
+ const cmp = requireCmp();
2032
+ const debug = requireDebug();
2033
+ const SemVer = requireSemver$1();
2034
+ const Range = requireRange();
2035
+ return comparator;
2036
+ }
2037
+
2038
+ var satisfies_1;
2039
+ var hasRequiredSatisfies;
2040
+
2041
+ function requireSatisfies () {
2042
+ if (hasRequiredSatisfies) return satisfies_1;
2043
+ hasRequiredSatisfies = 1;
2044
+
2045
+ const Range = requireRange();
2046
+ const satisfies = (version, range, options) => {
2047
+ try {
2048
+ range = new Range(range, options);
2049
+ } catch (er) {
2050
+ return false
2051
+ }
2052
+ return range.test(version)
2053
+ };
2054
+ satisfies_1 = satisfies;
2055
+ return satisfies_1;
2056
+ }
2057
+
2058
+ var toComparators_1;
2059
+ var hasRequiredToComparators;
2060
+
2061
+ function requireToComparators () {
2062
+ if (hasRequiredToComparators) return toComparators_1;
2063
+ hasRequiredToComparators = 1;
2064
+
2065
+ const Range = requireRange();
2066
+
2067
+ // Mostly just for testing and legacy API reasons
2068
+ const toComparators = (range, options) =>
2069
+ new Range(range, options).set
2070
+ .map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
2071
+
2072
+ toComparators_1 = toComparators;
2073
+ return toComparators_1;
2074
+ }
2075
+
2076
+ var maxSatisfying_1;
2077
+ var hasRequiredMaxSatisfying;
2078
+
2079
+ function requireMaxSatisfying () {
2080
+ if (hasRequiredMaxSatisfying) return maxSatisfying_1;
2081
+ hasRequiredMaxSatisfying = 1;
2082
+
2083
+ const SemVer = requireSemver$1();
2084
+ const Range = requireRange();
2085
+
2086
+ const maxSatisfying = (versions, range, options) => {
2087
+ let max = null;
2088
+ let maxSV = null;
2089
+ let rangeObj = null;
2090
+ try {
2091
+ rangeObj = new Range(range, options);
2092
+ } catch (er) {
2093
+ return null
2094
+ }
2095
+ versions.forEach((v) => {
2096
+ if (rangeObj.test(v)) {
2097
+ // satisfies(v, range, options)
2098
+ if (!max || maxSV.compare(v) === -1) {
2099
+ // compare(max, v, true)
2100
+ max = v;
2101
+ maxSV = new SemVer(max, options);
2102
+ }
2103
+ }
2104
+ });
2105
+ return max
2106
+ };
2107
+ maxSatisfying_1 = maxSatisfying;
2108
+ return maxSatisfying_1;
2109
+ }
2110
+
2111
+ var minSatisfying_1;
2112
+ var hasRequiredMinSatisfying;
2113
+
2114
+ function requireMinSatisfying () {
2115
+ if (hasRequiredMinSatisfying) return minSatisfying_1;
2116
+ hasRequiredMinSatisfying = 1;
2117
+
2118
+ const SemVer = requireSemver$1();
2119
+ const Range = requireRange();
2120
+ const minSatisfying = (versions, range, options) => {
2121
+ let min = null;
2122
+ let minSV = null;
2123
+ let rangeObj = null;
2124
+ try {
2125
+ rangeObj = new Range(range, options);
2126
+ } catch (er) {
2127
+ return null
2128
+ }
2129
+ versions.forEach((v) => {
2130
+ if (rangeObj.test(v)) {
2131
+ // satisfies(v, range, options)
2132
+ if (!min || minSV.compare(v) === 1) {
2133
+ // compare(min, v, true)
2134
+ min = v;
2135
+ minSV = new SemVer(min, options);
2136
+ }
2137
+ }
2138
+ });
2139
+ return min
2140
+ };
2141
+ minSatisfying_1 = minSatisfying;
2142
+ return minSatisfying_1;
2143
+ }
2144
+
2145
+ var minVersion_1;
2146
+ var hasRequiredMinVersion;
2147
+
2148
+ function requireMinVersion () {
2149
+ if (hasRequiredMinVersion) return minVersion_1;
2150
+ hasRequiredMinVersion = 1;
2151
+
2152
+ const SemVer = requireSemver$1();
2153
+ const Range = requireRange();
2154
+ const gt = requireGt();
2155
+
2156
+ const minVersion = (range, loose) => {
2157
+ range = new Range(range, loose);
2158
+
2159
+ let minver = new SemVer('0.0.0');
2160
+ if (range.test(minver)) {
2161
+ return minver
2162
+ }
2163
+
2164
+ minver = new SemVer('0.0.0-0');
2165
+ if (range.test(minver)) {
2166
+ return minver
2167
+ }
2168
+
2169
+ minver = null;
2170
+ for (let i = 0; i < range.set.length; ++i) {
2171
+ const comparators = range.set[i];
2172
+
2173
+ let setMin = null;
2174
+ comparators.forEach((comparator) => {
2175
+ // Clone to avoid manipulating the comparator's semver object.
2176
+ const compver = new SemVer(comparator.semver.version);
2177
+ switch (comparator.operator) {
2178
+ case '>':
2179
+ if (compver.prerelease.length === 0) {
2180
+ compver.patch++;
2181
+ } else {
2182
+ compver.prerelease.push(0);
2183
+ }
2184
+ compver.raw = compver.format();
2185
+ /* fallthrough */
2186
+ case '':
2187
+ case '>=':
2188
+ if (!setMin || gt(compver, setMin)) {
2189
+ setMin = compver;
2190
+ }
2191
+ break
2192
+ case '<':
2193
+ case '<=':
2194
+ /* Ignore maximum versions */
2195
+ break
2196
+ /* istanbul ignore next */
2197
+ default:
2198
+ throw new Error(`Unexpected operation: ${comparator.operator}`)
2199
+ }
2200
+ });
2201
+ if (setMin && (!minver || gt(minver, setMin))) {
2202
+ minver = setMin;
2203
+ }
2204
+ }
2205
+
2206
+ if (minver && range.test(minver)) {
2207
+ return minver
2208
+ }
2209
+
2210
+ return null
2211
+ };
2212
+ minVersion_1 = minVersion;
2213
+ return minVersion_1;
2214
+ }
2215
+
2216
+ var valid;
2217
+ var hasRequiredValid;
2218
+
2219
+ function requireValid () {
2220
+ if (hasRequiredValid) return valid;
2221
+ hasRequiredValid = 1;
2222
+
2223
+ const Range = requireRange();
2224
+ const validRange = (range, options) => {
2225
+ try {
2226
+ // Return '*' instead of '' so that truthiness works.
2227
+ // This will throw if it's invalid anyway
2228
+ return new Range(range, options).range || '*'
2229
+ } catch (er) {
2230
+ return null
2231
+ }
2232
+ };
2233
+ valid = validRange;
2234
+ return valid;
2235
+ }
2236
+
2237
+ var outside_1;
2238
+ var hasRequiredOutside;
2239
+
2240
+ function requireOutside () {
2241
+ if (hasRequiredOutside) return outside_1;
2242
+ hasRequiredOutside = 1;
2243
+
2244
+ const SemVer = requireSemver$1();
2245
+ const Comparator = requireComparator();
2246
+ const { ANY } = Comparator;
2247
+ const Range = requireRange();
2248
+ const satisfies = requireSatisfies();
2249
+ const gt = requireGt();
2250
+ const lt = requireLt();
2251
+ const lte = requireLte();
2252
+ const gte = requireGte();
2253
+
2254
+ const outside = (version, range, hilo, options) => {
2255
+ version = new SemVer(version, options);
2256
+ range = new Range(range, options);
2257
+
2258
+ let gtfn, ltefn, ltfn, comp, ecomp;
2259
+ switch (hilo) {
2260
+ case '>':
2261
+ gtfn = gt;
2262
+ ltefn = lte;
2263
+ ltfn = lt;
2264
+ comp = '>';
2265
+ ecomp = '>=';
2266
+ break
2267
+ case '<':
2268
+ gtfn = lt;
2269
+ ltefn = gte;
2270
+ ltfn = gt;
2271
+ comp = '<';
2272
+ ecomp = '<=';
2273
+ break
2274
+ default:
2275
+ throw new TypeError('Must provide a hilo val of "<" or ">"')
2276
+ }
2277
+
2278
+ // If it satisfies the range it is not outside
2279
+ if (satisfies(version, range, options)) {
2280
+ return false
2281
+ }
2282
+
2283
+ // From now on, variable terms are as if we're in "gtr" mode.
2284
+ // but note that everything is flipped for the "ltr" function.
2285
+
2286
+ for (let i = 0; i < range.set.length; ++i) {
2287
+ const comparators = range.set[i];
2288
+
2289
+ let high = null;
2290
+ let low = null;
2291
+
2292
+ comparators.forEach((comparator) => {
2293
+ if (comparator.semver === ANY) {
2294
+ comparator = new Comparator('>=0.0.0');
2295
+ }
2296
+ high = high || comparator;
2297
+ low = low || comparator;
2298
+ if (gtfn(comparator.semver, high.semver, options)) {
2299
+ high = comparator;
2300
+ } else if (ltfn(comparator.semver, low.semver, options)) {
2301
+ low = comparator;
2302
+ }
2303
+ });
2304
+
2305
+ // If the edge version comparator has a operator then our version
2306
+ // isn't outside it
2307
+ if (high.operator === comp || high.operator === ecomp) {
2308
+ return false
2309
+ }
2310
+
2311
+ // If the lowest version comparator has an operator and our version
2312
+ // is less than it then it isn't higher than the range
2313
+ if ((!low.operator || low.operator === comp) &&
2314
+ ltefn(version, low.semver)) {
2315
+ return false
2316
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
2317
+ return false
2318
+ }
2319
+ }
2320
+ return true
2321
+ };
2322
+
2323
+ outside_1 = outside;
2324
+ return outside_1;
2325
+ }
2326
+
2327
+ var gtr_1;
2328
+ var hasRequiredGtr;
2329
+
2330
+ function requireGtr () {
2331
+ if (hasRequiredGtr) return gtr_1;
2332
+ hasRequiredGtr = 1;
2333
+
2334
+ // Determine if version is greater than all the versions possible in the range.
2335
+ const outside = requireOutside();
2336
+ const gtr = (version, range, options) => outside(version, range, '>', options);
2337
+ gtr_1 = gtr;
2338
+ return gtr_1;
2339
+ }
2340
+
2341
+ var ltr_1;
2342
+ var hasRequiredLtr;
2343
+
2344
+ function requireLtr () {
2345
+ if (hasRequiredLtr) return ltr_1;
2346
+ hasRequiredLtr = 1;
2347
+
2348
+ const outside = requireOutside();
2349
+ // Determine if version is less than all the versions possible in the range
2350
+ const ltr = (version, range, options) => outside(version, range, '<', options);
2351
+ ltr_1 = ltr;
2352
+ return ltr_1;
2353
+ }
2354
+
2355
+ var intersects_1;
2356
+ var hasRequiredIntersects;
2357
+
2358
+ function requireIntersects () {
2359
+ if (hasRequiredIntersects) return intersects_1;
2360
+ hasRequiredIntersects = 1;
2361
+
2362
+ const Range = requireRange();
2363
+ const intersects = (r1, r2, options) => {
2364
+ r1 = new Range(r1, options);
2365
+ r2 = new Range(r2, options);
2366
+ return r1.intersects(r2, options)
2367
+ };
2368
+ intersects_1 = intersects;
2369
+ return intersects_1;
2370
+ }
2371
+
2372
+ var simplify;
2373
+ var hasRequiredSimplify;
2374
+
2375
+ function requireSimplify () {
2376
+ if (hasRequiredSimplify) return simplify;
2377
+ hasRequiredSimplify = 1;
2378
+
2379
+ // given a set of versions and a range, create a "simplified" range
2380
+ // that includes the same versions that the original range does
2381
+ // If the original range is shorter than the simplified one, return that.
2382
+ const satisfies = requireSatisfies();
2383
+ const compare = requireCompare();
2384
+ simplify = (versions, range, options) => {
2385
+ const set = [];
2386
+ let first = null;
2387
+ let prev = null;
2388
+ const v = versions.sort((a, b) => compare(a, b, options));
2389
+ for (const version of v) {
2390
+ const included = satisfies(version, range, options);
2391
+ if (included) {
2392
+ prev = version;
2393
+ if (!first) {
2394
+ first = version;
2395
+ }
2396
+ } else {
2397
+ if (prev) {
2398
+ set.push([first, prev]);
2399
+ }
2400
+ prev = null;
2401
+ first = null;
2402
+ }
2403
+ }
2404
+ if (first) {
2405
+ set.push([first, null]);
2406
+ }
2407
+
2408
+ const ranges = [];
2409
+ for (const [min, max] of set) {
2410
+ if (min === max) {
2411
+ ranges.push(min);
2412
+ } else if (!max && min === v[0]) {
2413
+ ranges.push('*');
2414
+ } else if (!max) {
2415
+ ranges.push(`>=${min}`);
2416
+ } else if (min === v[0]) {
2417
+ ranges.push(`<=${max}`);
2418
+ } else {
2419
+ ranges.push(`${min} - ${max}`);
2420
+ }
2421
+ }
2422
+ const simplified = ranges.join(' || ');
2423
+ const original = typeof range.raw === 'string' ? range.raw : String(range);
2424
+ return simplified.length < original.length ? simplified : range
2425
+ };
2426
+ return simplify;
2427
+ }
2428
+
2429
+ var subset_1;
2430
+ var hasRequiredSubset;
2431
+
2432
+ function requireSubset () {
2433
+ if (hasRequiredSubset) return subset_1;
2434
+ hasRequiredSubset = 1;
2435
+
2436
+ const Range = requireRange();
2437
+ const Comparator = requireComparator();
2438
+ const { ANY } = Comparator;
2439
+ const satisfies = requireSatisfies();
2440
+ const compare = requireCompare();
2441
+
2442
+ // Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
2443
+ // - Every simple range `r1, r2, ...` is a null set, OR
2444
+ // - Every simple range `r1, r2, ...` which is not a null set is a subset of
2445
+ // some `R1, R2, ...`
2446
+ //
2447
+ // Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
2448
+ // - If c is only the ANY comparator
2449
+ // - If C is only the ANY comparator, return true
2450
+ // - Else if in prerelease mode, return false
2451
+ // - else replace c with `[>=0.0.0]`
2452
+ // - If C is only the ANY comparator
2453
+ // - if in prerelease mode, return true
2454
+ // - else replace C with `[>=0.0.0]`
2455
+ // - Let EQ be the set of = comparators in c
2456
+ // - If EQ is more than one, return true (null set)
2457
+ // - Let GT be the highest > or >= comparator in c
2458
+ // - Let LT be the lowest < or <= comparator in c
2459
+ // - If GT and LT, and GT.semver > LT.semver, return true (null set)
2460
+ // - If any C is a = range, and GT or LT are set, return false
2461
+ // - If EQ
2462
+ // - If GT, and EQ does not satisfy GT, return true (null set)
2463
+ // - If LT, and EQ does not satisfy LT, return true (null set)
2464
+ // - If EQ satisfies every C, return true
2465
+ // - Else return false
2466
+ // - If GT
2467
+ // - If GT.semver is lower than any > or >= comp in C, return false
2468
+ // - If GT is >=, and GT.semver does not satisfy every C, return false
2469
+ // - If GT.semver has a prerelease, and not in prerelease mode
2470
+ // - If no C has a prerelease and the GT.semver tuple, return false
2471
+ // - If LT
2472
+ // - If LT.semver is greater than any < or <= comp in C, return false
2473
+ // - If LT is <=, and LT.semver does not satisfy every C, return false
2474
+ // - If LT.semver has a prerelease, and not in prerelease mode
2475
+ // - If no C has a prerelease and the LT.semver tuple, return false
2476
+ // - Else return true
2477
+
2478
+ const subset = (sub, dom, options = {}) => {
2479
+ if (sub === dom) {
2480
+ return true
2481
+ }
2482
+
2483
+ sub = new Range(sub, options);
2484
+ dom = new Range(dom, options);
2485
+ let sawNonNull = false;
2486
+
2487
+ OUTER: for (const simpleSub of sub.set) {
2488
+ for (const simpleDom of dom.set) {
2489
+ const isSub = simpleSubset(simpleSub, simpleDom, options);
2490
+ sawNonNull = sawNonNull || isSub !== null;
2491
+ if (isSub) {
2492
+ continue OUTER
2493
+ }
2494
+ }
2495
+ // the null set is a subset of everything, but null simple ranges in
2496
+ // a complex range should be ignored. so if we saw a non-null range,
2497
+ // then we know this isn't a subset, but if EVERY simple range was null,
2498
+ // then it is a subset.
2499
+ if (sawNonNull) {
2500
+ return false
2501
+ }
2502
+ }
2503
+ return true
2504
+ };
2505
+
2506
+ const minimumVersionWithPreRelease = [new Comparator('>=0.0.0-0')];
2507
+ const minimumVersion = [new Comparator('>=0.0.0')];
2508
+
2509
+ const simpleSubset = (sub, dom, options) => {
2510
+ if (sub === dom) {
2511
+ return true
2512
+ }
2513
+
2514
+ if (sub.length === 1 && sub[0].semver === ANY) {
2515
+ if (dom.length === 1 && dom[0].semver === ANY) {
2516
+ return true
2517
+ } else if (options.includePrerelease) {
2518
+ sub = minimumVersionWithPreRelease;
2519
+ } else {
2520
+ sub = minimumVersion;
2521
+ }
2522
+ }
2523
+
2524
+ if (dom.length === 1 && dom[0].semver === ANY) {
2525
+ if (options.includePrerelease) {
2526
+ return true
2527
+ } else {
2528
+ dom = minimumVersion;
2529
+ }
2530
+ }
2531
+
2532
+ const eqSet = new Set();
2533
+ let gt, lt;
2534
+ for (const c of sub) {
2535
+ if (c.operator === '>' || c.operator === '>=') {
2536
+ gt = higherGT(gt, c, options);
2537
+ } else if (c.operator === '<' || c.operator === '<=') {
2538
+ lt = lowerLT(lt, c, options);
2539
+ } else {
2540
+ eqSet.add(c.semver);
2541
+ }
2542
+ }
2543
+
2544
+ if (eqSet.size > 1) {
2545
+ return null
2546
+ }
2547
+
2548
+ let gtltComp;
2549
+ if (gt && lt) {
2550
+ gtltComp = compare(gt.semver, lt.semver, options);
2551
+ if (gtltComp > 0) {
2552
+ return null
2553
+ } else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
2554
+ return null
2555
+ }
2556
+ }
2557
+
2558
+ // will iterate one or zero times
2559
+ for (const eq of eqSet) {
2560
+ if (gt && !satisfies(eq, String(gt), options)) {
2561
+ return null
2562
+ }
2563
+
2564
+ if (lt && !satisfies(eq, String(lt), options)) {
2565
+ return null
2566
+ }
2567
+
2568
+ for (const c of dom) {
2569
+ if (!satisfies(eq, String(c), options)) {
2570
+ return false
2571
+ }
2572
+ }
2573
+
2574
+ return true
2575
+ }
2576
+
2577
+ let higher, lower;
2578
+ let hasDomLT, hasDomGT;
2579
+ // if the subset has a prerelease, we need a comparator in the superset
2580
+ // with the same tuple and a prerelease, or it's not a subset
2581
+ let needDomLTPre = lt &&
2582
+ !options.includePrerelease &&
2583
+ lt.semver.prerelease.length ? lt.semver : false;
2584
+ let needDomGTPre = gt &&
2585
+ !options.includePrerelease &&
2586
+ gt.semver.prerelease.length ? gt.semver : false;
2587
+ // exception: <1.2.3-0 is the same as <1.2.3
2588
+ if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
2589
+ lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
2590
+ needDomLTPre = false;
2591
+ }
2592
+
2593
+ for (const c of dom) {
2594
+ hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
2595
+ hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
2596
+ if (gt) {
2597
+ if (needDomGTPre) {
2598
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2599
+ c.semver.major === needDomGTPre.major &&
2600
+ c.semver.minor === needDomGTPre.minor &&
2601
+ c.semver.patch === needDomGTPre.patch) {
2602
+ needDomGTPre = false;
2603
+ }
2604
+ }
2605
+ if (c.operator === '>' || c.operator === '>=') {
2606
+ higher = higherGT(gt, c, options);
2607
+ if (higher === c && higher !== gt) {
2608
+ return false
2609
+ }
2610
+ } else if (gt.operator === '>=' && !c.test(gt.semver)) {
2611
+ return false
2612
+ }
2613
+ }
2614
+ if (lt) {
2615
+ if (needDomLTPre) {
2616
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2617
+ c.semver.major === needDomLTPre.major &&
2618
+ c.semver.minor === needDomLTPre.minor &&
2619
+ c.semver.patch === needDomLTPre.patch) {
2620
+ needDomLTPre = false;
2621
+ }
2622
+ }
2623
+ if (c.operator === '<' || c.operator === '<=') {
2624
+ lower = lowerLT(lt, c, options);
2625
+ if (lower === c && lower !== lt) {
2626
+ return false
2627
+ }
2628
+ } else if (lt.operator === '<=' && !c.test(lt.semver)) {
2629
+ return false
2630
+ }
2631
+ }
2632
+ if (!c.operator && (lt || gt) && gtltComp !== 0) {
2633
+ return false
2634
+ }
2635
+ }
2636
+
2637
+ // if there was a < or >, and nothing in the dom, then must be false
2638
+ // UNLESS it was limited by another range in the other direction.
2639
+ // Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
2640
+ if (gt && hasDomLT && !lt && gtltComp !== 0) {
2641
+ return false
2642
+ }
2643
+
2644
+ if (lt && hasDomGT && !gt && gtltComp !== 0) {
2645
+ return false
2646
+ }
2647
+
2648
+ // we needed a prerelease range in a specific tuple, but didn't get one
2649
+ // then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
2650
+ // because it includes prereleases in the 1.2.3 tuple
2651
+ if (needDomGTPre || needDomLTPre) {
2652
+ return false
2653
+ }
2654
+
2655
+ return true
2656
+ };
2657
+
2658
+ // >=1.2.3 is lower than >1.2.3
2659
+ const higherGT = (a, b, options) => {
2660
+ if (!a) {
2661
+ return b
2662
+ }
2663
+ const comp = compare(a.semver, b.semver, options);
2664
+ return comp > 0 ? a
2665
+ : comp < 0 ? b
2666
+ : b.operator === '>' && a.operator === '>=' ? b
2667
+ : a
2668
+ };
2669
+
2670
+ // <=1.2.3 is higher than <1.2.3
2671
+ const lowerLT = (a, b, options) => {
2672
+ if (!a) {
2673
+ return b
2674
+ }
2675
+ const comp = compare(a.semver, b.semver, options);
2676
+ return comp < 0 ? a
2677
+ : comp > 0 ? b
2678
+ : b.operator === '<' && a.operator === '<=' ? b
2679
+ : a
2680
+ };
2681
+
2682
+ subset_1 = subset;
2683
+ return subset_1;
2684
+ }
2685
+
2686
+ var semver;
2687
+ var hasRequiredSemver;
2688
+
2689
+ function requireSemver () {
2690
+ if (hasRequiredSemver) return semver;
2691
+ hasRequiredSemver = 1;
2692
+
2693
+ // just pre-load all the stuff that index.js lazily exports
2694
+ const internalRe = requireRe();
2695
+ const constants = requireConstants();
2696
+ const SemVer = requireSemver$1();
2697
+ const identifiers = requireIdentifiers();
2698
+ const parse = requireParse();
2699
+ const valid = requireValid$1();
2700
+ const clean = requireClean();
2701
+ const inc = requireInc();
2702
+ const diff = requireDiff();
2703
+ const major = requireMajor();
2704
+ const minor = requireMinor();
2705
+ const patch = requirePatch();
2706
+ const prerelease = requirePrerelease();
2707
+ const compare = requireCompare();
2708
+ const rcompare = requireRcompare();
2709
+ const compareLoose = requireCompareLoose();
2710
+ const compareBuild = requireCompareBuild();
2711
+ const sort = requireSort();
2712
+ const rsort = requireRsort();
2713
+ const gt = requireGt();
2714
+ const lt = requireLt();
2715
+ const eq = requireEq();
2716
+ const neq = requireNeq();
2717
+ const gte = requireGte();
2718
+ const lte = requireLte();
2719
+ const cmp = requireCmp();
2720
+ const coerce = requireCoerce();
2721
+ const truncate = requireTruncate();
2722
+ const Comparator = requireComparator();
2723
+ const Range = requireRange();
2724
+ const satisfies = requireSatisfies();
2725
+ const toComparators = requireToComparators();
2726
+ const maxSatisfying = requireMaxSatisfying();
2727
+ const minSatisfying = requireMinSatisfying();
2728
+ const minVersion = requireMinVersion();
2729
+ const validRange = requireValid();
2730
+ const outside = requireOutside();
2731
+ const gtr = requireGtr();
2732
+ const ltr = requireLtr();
2733
+ const intersects = requireIntersects();
2734
+ const simplifyRange = requireSimplify();
2735
+ const subset = requireSubset();
2736
+ semver = {
2737
+ parse,
2738
+ valid,
2739
+ clean,
2740
+ inc,
2741
+ diff,
2742
+ major,
2743
+ minor,
2744
+ patch,
2745
+ prerelease,
2746
+ compare,
2747
+ rcompare,
2748
+ compareLoose,
2749
+ compareBuild,
2750
+ sort,
2751
+ rsort,
2752
+ gt,
2753
+ lt,
2754
+ eq,
2755
+ neq,
2756
+ gte,
2757
+ lte,
2758
+ cmp,
2759
+ coerce,
2760
+ truncate,
2761
+ Comparator,
2762
+ Range,
2763
+ satisfies,
2764
+ toComparators,
2765
+ maxSatisfying,
2766
+ minSatisfying,
2767
+ minVersion,
2768
+ validRange,
2769
+ outside,
2770
+ gtr,
2771
+ ltr,
2772
+ intersects,
2773
+ simplifyRange,
2774
+ subset,
2775
+ SemVer,
2776
+ re: internalRe.re,
2777
+ src: internalRe.src,
2778
+ tokens: internalRe.t,
2779
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
2780
+ RELEASE_TYPES: constants.RELEASE_TYPES,
2781
+ compareIdentifiers: identifiers.compareIdentifiers,
2782
+ rcompareIdentifiers: identifiers.rcompareIdentifiers,
2783
+ };
2784
+ return semver;
2785
+ }
2786
+
2787
+ var semverExports = requireSemver();
2788
+
2789
+ function validateMiniappPackageVersionForBuild(version) {
2790
+ return validateMiniappManifestVersion(version, 'package.json.version');
2791
+ }
2792
+ function validateMiniappManifestVersion(version, sourceLabel = 'manifest.version') {
2793
+ const error = getMiniappManifestVersionError(version);
2794
+ if (error) {
2795
+ throw new Error(`${sourceLabel} ${error}`);
12
2796
  }
13
- return undefined;
2797
+ return String(version).trim();
14
2798
  }
15
2799
  function renderMiniappManifest(manifest) {
16
2800
  return `${JSON.stringify({ version: manifest.version }, null, 2)}\n`;
17
2801
  }
2802
+ function getMiniappManifestVersionError(version) {
2803
+ if (typeof version !== 'string' || version.trim() === '') {
2804
+ return `必须是合法 SemVer:${String(version)}`;
2805
+ }
2806
+ const normalized = version.trim();
2807
+ const parsed = semverExports.parse(normalized);
2808
+ if (!parsed) {
2809
+ return `必须是合法 SemVer:${normalized}`;
2810
+ }
2811
+ if (parsed.build.length > 0) {
2812
+ return `不能包含 build metadata:${normalized}`;
2813
+ }
2814
+ if (parsed.version !== normalized) {
2815
+ return `必须是合法 SemVer:${normalized}`;
2816
+ }
2817
+ if (parsed.major === 0 && parsed.minor === 0 && parsed.patch === 0) {
2818
+ return '不能是模板默认版本 0.0.0';
2819
+ }
2820
+ return undefined;
2821
+ }
18
2822
 
19
2823
  function findNearestPackageJsonPath(startDir) {
20
2824
  let current = path.resolve(startDir);
@@ -69,11 +2873,7 @@ function miniappManifest() {
69
2873
  outDir = resolved.build.outDir;
70
2874
  },
71
2875
  writeBundle() {
72
- const version = readMiniappVersionFromPackageJson(root);
73
- const warning = getMiniappManifestBuildWarning(version);
74
- if (warning) {
75
- this.warn(warning);
76
- }
2876
+ const version = validateMiniappPackageVersionForBuild(readMiniappVersionFromPackageJson(root));
77
2877
  const manifestPath = path.resolve(root, outDir, 'manifest.json');
78
2878
  mkdirSync(path.dirname(manifestPath), { recursive: true });
79
2879
  writeFileSync(manifestPath, renderMiniappManifest({ version }));