@bundlekit/service 0.0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,3468 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var path = require('path');
5
+ var jiti = require('jiti');
6
+ var sharedUtils = require('@bundlekit/shared-utils');
7
+ var http = require('node:http');
8
+ var module$2 = require('module');
9
+
10
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n.default = e;
28
+ return Object.freeze(n);
29
+ }
30
+
31
+ var path__default = /*#__PURE__*/_interopDefault(path);
32
+ var http__default = /*#__PURE__*/_interopDefault(http);
33
+
34
+ function getDefaultExportFromCjs (x) {
35
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
36
+ }
37
+
38
+ var re$2 = {exports: {}};
39
+
40
+ // Note: this is the semver.org version of the spec that it implements
41
+ // Not necessarily the package version of this code.
42
+ const SEMVER_SPEC_VERSION = '2.0.0';
43
+
44
+ const MAX_LENGTH$1 = 256;
45
+ const MAX_SAFE_INTEGER$1 = Number.MAX_SAFE_INTEGER ||
46
+ /* istanbul ignore next */ 9007199254740991;
47
+
48
+ // Max safe segment length for coercion.
49
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
50
+
51
+ // Max safe length for a build identifier. The max length minus 6 characters for
52
+ // the shortest version with a build 0.0.0+BUILD.
53
+ const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH$1 - 6;
54
+
55
+ const RELEASE_TYPES = [
56
+ 'major',
57
+ 'premajor',
58
+ 'minor',
59
+ 'preminor',
60
+ 'patch',
61
+ 'prepatch',
62
+ 'prerelease',
63
+ ];
64
+
65
+ var constants$2 = {
66
+ MAX_LENGTH: MAX_LENGTH$1,
67
+ MAX_SAFE_COMPONENT_LENGTH,
68
+ MAX_SAFE_BUILD_LENGTH,
69
+ MAX_SAFE_INTEGER: MAX_SAFE_INTEGER$1,
70
+ RELEASE_TYPES,
71
+ SEMVER_SPEC_VERSION,
72
+ FLAG_INCLUDE_PRERELEASE: 0b001,
73
+ FLAG_LOOSE: 0b010,
74
+ };
75
+
76
+ const debug$1 = (
77
+ typeof process === 'object' &&
78
+ process.env &&
79
+ process.env.NODE_DEBUG &&
80
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)
81
+ ) ? (...args) => console.error('SEMVER', ...args)
82
+ : () => {};
83
+
84
+ var debug_1 = debug$1;
85
+
86
+ (function (module, exports) {
87
+
88
+ const {
89
+ MAX_SAFE_COMPONENT_LENGTH,
90
+ MAX_SAFE_BUILD_LENGTH,
91
+ MAX_LENGTH,
92
+ } = constants$2;
93
+ const debug = debug_1;
94
+ exports = module.exports = {};
95
+
96
+ // The actual regexps go on exports.re
97
+ const re = exports.re = [];
98
+ const safeRe = exports.safeRe = [];
99
+ const src = exports.src = [];
100
+ const safeSrc = exports.safeSrc = [];
101
+ const t = exports.t = {};
102
+ let R = 0;
103
+
104
+ const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
105
+
106
+ // Replace some greedy regex tokens to prevent regex dos issues. These regex are
107
+ // used internally via the safeRe object since all inputs in this library get
108
+ // normalized first to trim and collapse all extra whitespace. The original
109
+ // regexes are exported for userland consumption and lower level usage. A
110
+ // future breaking change could export the safer regex only with a note that
111
+ // all input should have extra whitespace removed.
112
+ const safeRegexReplacements = [
113
+ ['\\s', 1],
114
+ ['\\d', MAX_LENGTH],
115
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
116
+ ];
117
+
118
+ const makeSafeRegex = (value) => {
119
+ for (const [token, max] of safeRegexReplacements) {
120
+ value = value
121
+ .split(`${token}*`).join(`${token}{0,${max}}`)
122
+ .split(`${token}+`).join(`${token}{1,${max}}`);
123
+ }
124
+ return value
125
+ };
126
+
127
+ const createToken = (name, value, isGlobal) => {
128
+ const safe = makeSafeRegex(value);
129
+ const index = R++;
130
+ debug(name, index, value);
131
+ t[name] = index;
132
+ src[index] = value;
133
+ safeSrc[index] = safe;
134
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
135
+ safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
136
+ };
137
+
138
+ // The following Regular Expressions can be used for tokenizing,
139
+ // validating, and parsing SemVer version strings.
140
+
141
+ // ## Numeric Identifier
142
+ // A single `0`, or a non-zero digit followed by zero or more digits.
143
+
144
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
145
+ createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
146
+
147
+ // ## Non-numeric Identifier
148
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
149
+ // more letters, digits, or hyphens.
150
+
151
+ createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
152
+
153
+ // ## Main Version
154
+ // Three dot-separated numeric identifiers.
155
+
156
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
157
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
158
+ `(${src[t.NUMERICIDENTIFIER]})`);
159
+
160
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
161
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
162
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
163
+
164
+ // ## Pre-release Version Identifier
165
+ // A numeric identifier, or a non-numeric identifier.
166
+ // Non-numeric identifiers include numeric identifiers but can be longer.
167
+ // Therefore non-numeric identifiers must go first.
168
+
169
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
170
+ }|${src[t.NUMERICIDENTIFIER]})`);
171
+
172
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
173
+ }|${src[t.NUMERICIDENTIFIERLOOSE]})`);
174
+
175
+ // ## Pre-release Version
176
+ // Hyphen, followed by one or more dot-separated pre-release version
177
+ // identifiers.
178
+
179
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
180
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
181
+
182
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
183
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
184
+
185
+ // ## Build Metadata Identifier
186
+ // Any combination of digits, letters, or hyphens.
187
+
188
+ createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
189
+
190
+ // ## Build Metadata
191
+ // Plus sign, followed by one or more period-separated build metadata
192
+ // identifiers.
193
+
194
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
195
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
196
+
197
+ // ## Full Version String
198
+ // A main version, followed optionally by a pre-release version and
199
+ // build metadata.
200
+
201
+ // Note that the only major, minor, patch, and pre-release sections of
202
+ // the version string are capturing groups. The build metadata is not a
203
+ // capturing group, because it should not ever be used in version
204
+ // comparison.
205
+
206
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
207
+ }${src[t.PRERELEASE]}?${
208
+ src[t.BUILD]}?`);
209
+
210
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`);
211
+
212
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
213
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
214
+ // common in the npm registry.
215
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
216
+ }${src[t.PRERELEASELOOSE]}?${
217
+ src[t.BUILD]}?`);
218
+
219
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
220
+
221
+ createToken('GTLT', '((?:<|>)?=?)');
222
+
223
+ // Something like "2.*" or "1.2.x".
224
+ // Note that "x.x" is a valid xRange identifier, meaning "any version"
225
+ // Only the first item is strictly required.
226
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
227
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
228
+
229
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
230
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
231
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
232
+ `(?:${src[t.PRERELEASE]})?${
233
+ src[t.BUILD]}?` +
234
+ `)?)?`);
235
+
236
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
237
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
238
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
239
+ `(?:${src[t.PRERELEASELOOSE]})?${
240
+ src[t.BUILD]}?` +
241
+ `)?)?`);
242
+
243
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
244
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
245
+
246
+ // Coercion.
247
+ // Extract anything that could conceivably be a part of a valid semver
248
+ createToken('COERCEPLAIN', `${'(^|[^\\d])' +
249
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
250
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
251
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
252
+ createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
253
+ createToken('COERCEFULL', src[t.COERCEPLAIN] +
254
+ `(?:${src[t.PRERELEASE]})?` +
255
+ `(?:${src[t.BUILD]})?` +
256
+ `(?:$|[^\\d])`);
257
+ createToken('COERCERTL', src[t.COERCE], true);
258
+ createToken('COERCERTLFULL', src[t.COERCEFULL], true);
259
+
260
+ // Tilde ranges.
261
+ // Meaning is "reasonably at or greater than"
262
+ createToken('LONETILDE', '(?:~>?)');
263
+
264
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
265
+ exports.tildeTrimReplace = '$1~';
266
+
267
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
268
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
269
+
270
+ // Caret ranges.
271
+ // Meaning is "at least and backwards compatible with"
272
+ createToken('LONECARET', '(?:\\^)');
273
+
274
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
275
+ exports.caretTrimReplace = '$1^';
276
+
277
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
278
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
279
+
280
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
281
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
282
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
283
+
284
+ // An expression to strip any whitespace between the gtlt and the thing
285
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
286
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
287
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
288
+ exports.comparatorTrimReplace = '$1$2$3';
289
+
290
+ // Something like `1.2.3 - 1.2.4`
291
+ // Note that these all use the loose form, because they'll be
292
+ // checked against either the strict or loose comparator form
293
+ // later.
294
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
295
+ `\\s+-\\s+` +
296
+ `(${src[t.XRANGEPLAIN]})` +
297
+ `\\s*$`);
298
+
299
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
300
+ `\\s+-\\s+` +
301
+ `(${src[t.XRANGEPLAINLOOSE]})` +
302
+ `\\s*$`);
303
+
304
+ // Star ranges basically just allow anything at all.
305
+ createToken('STAR', '(<|>)?=?\\s*\\*');
306
+ // >=0.0.0 is like a star
307
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
308
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
309
+ } (re$2, re$2.exports));
310
+
311
+ var reExports = re$2.exports;
312
+
313
+ // parse out just the options we care about
314
+ const looseOption = Object.freeze({ loose: true });
315
+ const emptyOpts = Object.freeze({ });
316
+ const parseOptions$1 = options => {
317
+ if (!options) {
318
+ return emptyOpts
319
+ }
320
+
321
+ if (typeof options !== 'object') {
322
+ return looseOption
323
+ }
324
+
325
+ return options
326
+ };
327
+ var parseOptions_1 = parseOptions$1;
328
+
329
+ const numeric = /^[0-9]+$/;
330
+ const compareIdentifiers$1 = (a, b) => {
331
+ if (typeof a === 'number' && typeof b === 'number') {
332
+ return a === b ? 0 : a < b ? -1 : 1
333
+ }
334
+
335
+ const anum = numeric.test(a);
336
+ const bnum = numeric.test(b);
337
+
338
+ if (anum && bnum) {
339
+ a = +a;
340
+ b = +b;
341
+ }
342
+
343
+ return a === b ? 0
344
+ : (anum && !bnum) ? -1
345
+ : (bnum && !anum) ? 1
346
+ : a < b ? -1
347
+ : 1
348
+ };
349
+
350
+ const rcompareIdentifiers = (a, b) => compareIdentifiers$1(b, a);
351
+
352
+ var identifiers$1 = {
353
+ compareIdentifiers: compareIdentifiers$1,
354
+ rcompareIdentifiers,
355
+ };
356
+
357
+ const debug = debug_1;
358
+ const { MAX_LENGTH, MAX_SAFE_INTEGER } = constants$2;
359
+ const { safeRe: re$1, t: t$1 } = reExports;
360
+
361
+ const parseOptions = parseOptions_1;
362
+ const { compareIdentifiers } = identifiers$1;
363
+ let SemVer$e = class SemVer {
364
+ constructor (version, options) {
365
+ options = parseOptions(options);
366
+
367
+ if (version instanceof SemVer) {
368
+ if (version.loose === !!options.loose &&
369
+ version.includePrerelease === !!options.includePrerelease) {
370
+ return version
371
+ } else {
372
+ version = version.version;
373
+ }
374
+ } else if (typeof version !== 'string') {
375
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
376
+ }
377
+
378
+ if (version.length > MAX_LENGTH) {
379
+ throw new TypeError(
380
+ `version is longer than ${MAX_LENGTH} characters`
381
+ )
382
+ }
383
+
384
+ debug('SemVer', version, options);
385
+ this.options = options;
386
+ this.loose = !!options.loose;
387
+ // this isn't actually relevant for versions, but keep it so that we
388
+ // don't run into trouble passing this.options around.
389
+ this.includePrerelease = !!options.includePrerelease;
390
+
391
+ const m = version.trim().match(options.loose ? re$1[t$1.LOOSE] : re$1[t$1.FULL]);
392
+
393
+ if (!m) {
394
+ throw new TypeError(`Invalid Version: ${version}`)
395
+ }
396
+
397
+ this.raw = version;
398
+
399
+ // these are actually numbers
400
+ this.major = +m[1];
401
+ this.minor = +m[2];
402
+ this.patch = +m[3];
403
+
404
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
405
+ throw new TypeError('Invalid major version')
406
+ }
407
+
408
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
409
+ throw new TypeError('Invalid minor version')
410
+ }
411
+
412
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
413
+ throw new TypeError('Invalid patch version')
414
+ }
415
+
416
+ // numberify any prerelease numeric ids
417
+ if (!m[4]) {
418
+ this.prerelease = [];
419
+ } else {
420
+ this.prerelease = m[4].split('.').map((id) => {
421
+ if (/^[0-9]+$/.test(id)) {
422
+ const num = +id;
423
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
424
+ return num
425
+ }
426
+ }
427
+ return id
428
+ });
429
+ }
430
+
431
+ this.build = m[5] ? m[5].split('.') : [];
432
+ this.format();
433
+ }
434
+
435
+ format () {
436
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
437
+ if (this.prerelease.length) {
438
+ this.version += `-${this.prerelease.join('.')}`;
439
+ }
440
+ return this.version
441
+ }
442
+
443
+ toString () {
444
+ return this.version
445
+ }
446
+
447
+ compare (other) {
448
+ debug('SemVer.compare', this.version, this.options, other);
449
+ if (!(other instanceof SemVer)) {
450
+ if (typeof other === 'string' && other === this.version) {
451
+ return 0
452
+ }
453
+ other = new SemVer(other, this.options);
454
+ }
455
+
456
+ if (other.version === this.version) {
457
+ return 0
458
+ }
459
+
460
+ return this.compareMain(other) || this.comparePre(other)
461
+ }
462
+
463
+ compareMain (other) {
464
+ if (!(other instanceof SemVer)) {
465
+ other = new SemVer(other, this.options);
466
+ }
467
+
468
+ if (this.major < other.major) {
469
+ return -1
470
+ }
471
+ if (this.major > other.major) {
472
+ return 1
473
+ }
474
+ if (this.minor < other.minor) {
475
+ return -1
476
+ }
477
+ if (this.minor > other.minor) {
478
+ return 1
479
+ }
480
+ if (this.patch < other.patch) {
481
+ return -1
482
+ }
483
+ if (this.patch > other.patch) {
484
+ return 1
485
+ }
486
+ return 0
487
+ }
488
+
489
+ comparePre (other) {
490
+ if (!(other instanceof SemVer)) {
491
+ other = new SemVer(other, this.options);
492
+ }
493
+
494
+ // NOT having a prerelease is > having one
495
+ if (this.prerelease.length && !other.prerelease.length) {
496
+ return -1
497
+ } else if (!this.prerelease.length && other.prerelease.length) {
498
+ return 1
499
+ } else if (!this.prerelease.length && !other.prerelease.length) {
500
+ return 0
501
+ }
502
+
503
+ let i = 0;
504
+ do {
505
+ const a = this.prerelease[i];
506
+ const b = other.prerelease[i];
507
+ debug('prerelease compare', i, a, b);
508
+ if (a === undefined && b === undefined) {
509
+ return 0
510
+ } else if (b === undefined) {
511
+ return 1
512
+ } else if (a === undefined) {
513
+ return -1
514
+ } else if (a === b) {
515
+ continue
516
+ } else {
517
+ return compareIdentifiers(a, b)
518
+ }
519
+ } while (++i)
520
+ }
521
+
522
+ compareBuild (other) {
523
+ if (!(other instanceof SemVer)) {
524
+ other = new SemVer(other, this.options);
525
+ }
526
+
527
+ let i = 0;
528
+ do {
529
+ const a = this.build[i];
530
+ const b = other.build[i];
531
+ debug('build compare', i, a, b);
532
+ if (a === undefined && b === undefined) {
533
+ return 0
534
+ } else if (b === undefined) {
535
+ return 1
536
+ } else if (a === undefined) {
537
+ return -1
538
+ } else if (a === b) {
539
+ continue
540
+ } else {
541
+ return compareIdentifiers(a, b)
542
+ }
543
+ } while (++i)
544
+ }
545
+
546
+ // preminor will bump the version up to the next minor release, and immediately
547
+ // down to pre-release. premajor and prepatch work the same way.
548
+ inc (release, identifier, identifierBase) {
549
+ if (release.startsWith('pre')) {
550
+ if (!identifier && identifierBase === false) {
551
+ throw new Error('invalid increment argument: identifier is empty')
552
+ }
553
+ // Avoid an invalid semver results
554
+ if (identifier) {
555
+ const match = `-${identifier}`.match(this.options.loose ? re$1[t$1.PRERELEASELOOSE] : re$1[t$1.PRERELEASE]);
556
+ if (!match || match[1] !== identifier) {
557
+ throw new Error(`invalid identifier: ${identifier}`)
558
+ }
559
+ }
560
+ }
561
+
562
+ switch (release) {
563
+ case 'premajor':
564
+ this.prerelease.length = 0;
565
+ this.patch = 0;
566
+ this.minor = 0;
567
+ this.major++;
568
+ this.inc('pre', identifier, identifierBase);
569
+ break
570
+ case 'preminor':
571
+ this.prerelease.length = 0;
572
+ this.patch = 0;
573
+ this.minor++;
574
+ this.inc('pre', identifier, identifierBase);
575
+ break
576
+ case 'prepatch':
577
+ // If this is already a prerelease, it will bump to the next version
578
+ // drop any prereleases that might already exist, since they are not
579
+ // relevant at this point.
580
+ this.prerelease.length = 0;
581
+ this.inc('patch', identifier, identifierBase);
582
+ this.inc('pre', identifier, identifierBase);
583
+ break
584
+ // If the input is a non-prerelease version, this acts the same as
585
+ // prepatch.
586
+ case 'prerelease':
587
+ if (this.prerelease.length === 0) {
588
+ this.inc('patch', identifier, identifierBase);
589
+ }
590
+ this.inc('pre', identifier, identifierBase);
591
+ break
592
+ case 'release':
593
+ if (this.prerelease.length === 0) {
594
+ throw new Error(`version ${this.raw} is not a prerelease`)
595
+ }
596
+ this.prerelease.length = 0;
597
+ break
598
+
599
+ case 'major':
600
+ // If this is a pre-major version, bump up to the same major version.
601
+ // Otherwise increment major.
602
+ // 1.0.0-5 bumps to 1.0.0
603
+ // 1.1.0 bumps to 2.0.0
604
+ if (
605
+ this.minor !== 0 ||
606
+ this.patch !== 0 ||
607
+ this.prerelease.length === 0
608
+ ) {
609
+ this.major++;
610
+ }
611
+ this.minor = 0;
612
+ this.patch = 0;
613
+ this.prerelease = [];
614
+ break
615
+ case 'minor':
616
+ // If this is a pre-minor version, bump up to the same minor version.
617
+ // Otherwise increment minor.
618
+ // 1.2.0-5 bumps to 1.2.0
619
+ // 1.2.1 bumps to 1.3.0
620
+ if (this.patch !== 0 || this.prerelease.length === 0) {
621
+ this.minor++;
622
+ }
623
+ this.patch = 0;
624
+ this.prerelease = [];
625
+ break
626
+ case 'patch':
627
+ // If this is not a pre-release version, it will increment the patch.
628
+ // If it is a pre-release it will bump up to the same patch version.
629
+ // 1.2.0-5 patches to 1.2.0
630
+ // 1.2.0 patches to 1.2.1
631
+ if (this.prerelease.length === 0) {
632
+ this.patch++;
633
+ }
634
+ this.prerelease = [];
635
+ break
636
+ // This probably shouldn't be used publicly.
637
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
638
+ case 'pre': {
639
+ const base = Number(identifierBase) ? 1 : 0;
640
+
641
+ if (this.prerelease.length === 0) {
642
+ this.prerelease = [base];
643
+ } else {
644
+ let i = this.prerelease.length;
645
+ while (--i >= 0) {
646
+ if (typeof this.prerelease[i] === 'number') {
647
+ this.prerelease[i]++;
648
+ i = -2;
649
+ }
650
+ }
651
+ if (i === -1) {
652
+ // didn't increment anything
653
+ if (identifier === this.prerelease.join('.') && identifierBase === false) {
654
+ throw new Error('invalid increment argument: identifier already exists')
655
+ }
656
+ this.prerelease.push(base);
657
+ }
658
+ }
659
+ if (identifier) {
660
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
661
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
662
+ let prerelease = [identifier, base];
663
+ if (identifierBase === false) {
664
+ prerelease = [identifier];
665
+ }
666
+ if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
667
+ if (isNaN(this.prerelease[1])) {
668
+ this.prerelease = prerelease;
669
+ }
670
+ } else {
671
+ this.prerelease = prerelease;
672
+ }
673
+ }
674
+ break
675
+ }
676
+ default:
677
+ throw new Error(`invalid increment argument: ${release}`)
678
+ }
679
+ this.raw = this.format();
680
+ if (this.build.length) {
681
+ this.raw += `+${this.build.join('.')}`;
682
+ }
683
+ return this
684
+ }
685
+ };
686
+
687
+ var semver$2 = SemVer$e;
688
+
689
+ const SemVer$d = semver$2;
690
+ const parse$7 = (version, options, throwErrors = false) => {
691
+ if (version instanceof SemVer$d) {
692
+ return version
693
+ }
694
+ try {
695
+ return new SemVer$d(version, options)
696
+ } catch (er) {
697
+ if (!throwErrors) {
698
+ return null
699
+ }
700
+ throw er
701
+ }
702
+ };
703
+
704
+ var parse_1 = parse$7;
705
+
706
+ const parse$6 = parse_1;
707
+ const valid$2 = (version, options) => {
708
+ const v = parse$6(version, options);
709
+ return v ? v.version : null
710
+ };
711
+ var valid_1 = valid$2;
712
+
713
+ const parse$5 = parse_1;
714
+ const clean$1 = (version, options) => {
715
+ const s = parse$5(version.trim().replace(/^[=v]+/, ''), options);
716
+ return s ? s.version : null
717
+ };
718
+ var clean_1 = clean$1;
719
+
720
+ const SemVer$c = semver$2;
721
+
722
+ const inc$1 = (version, release, options, identifier, identifierBase) => {
723
+ if (typeof (options) === 'string') {
724
+ identifierBase = identifier;
725
+ identifier = options;
726
+ options = undefined;
727
+ }
728
+
729
+ try {
730
+ return new SemVer$c(
731
+ version instanceof SemVer$c ? version.version : version,
732
+ options
733
+ ).inc(release, identifier, identifierBase).version
734
+ } catch (er) {
735
+ return null
736
+ }
737
+ };
738
+ var inc_1 = inc$1;
739
+
740
+ const parse$4 = parse_1;
741
+
742
+ const diff$1 = (version1, version2) => {
743
+ const v1 = parse$4(version1, null, true);
744
+ const v2 = parse$4(version2, null, true);
745
+ const comparison = v1.compare(v2);
746
+
747
+ if (comparison === 0) {
748
+ return null
749
+ }
750
+
751
+ const v1Higher = comparison > 0;
752
+ const highVersion = v1Higher ? v1 : v2;
753
+ const lowVersion = v1Higher ? v2 : v1;
754
+ const highHasPre = !!highVersion.prerelease.length;
755
+ const lowHasPre = !!lowVersion.prerelease.length;
756
+
757
+ if (lowHasPre && !highHasPre) {
758
+ // Going from prerelease -> no prerelease requires some special casing
759
+
760
+ // If the low version has only a major, then it will always be a major
761
+ // Some examples:
762
+ // 1.0.0-1 -> 1.0.0
763
+ // 1.0.0-1 -> 1.1.1
764
+ // 1.0.0-1 -> 2.0.0
765
+ if (!lowVersion.patch && !lowVersion.minor) {
766
+ return 'major'
767
+ }
768
+
769
+ // If the main part has no difference
770
+ if (lowVersion.compareMain(highVersion) === 0) {
771
+ if (lowVersion.minor && !lowVersion.patch) {
772
+ return 'minor'
773
+ }
774
+ return 'patch'
775
+ }
776
+ }
777
+
778
+ // add the `pre` prefix if we are going to a prerelease version
779
+ const prefix = highHasPre ? 'pre' : '';
780
+
781
+ if (v1.major !== v2.major) {
782
+ return prefix + 'major'
783
+ }
784
+
785
+ if (v1.minor !== v2.minor) {
786
+ return prefix + 'minor'
787
+ }
788
+
789
+ if (v1.patch !== v2.patch) {
790
+ return prefix + 'patch'
791
+ }
792
+
793
+ // high and low are prereleases
794
+ return 'prerelease'
795
+ };
796
+
797
+ var diff_1 = diff$1;
798
+
799
+ const SemVer$b = semver$2;
800
+ const major$1 = (a, loose) => new SemVer$b(a, loose).major;
801
+ var major_1 = major$1;
802
+
803
+ const SemVer$a = semver$2;
804
+ const minor$1 = (a, loose) => new SemVer$a(a, loose).minor;
805
+ var minor_1 = minor$1;
806
+
807
+ const SemVer$9 = semver$2;
808
+ const patch$1 = (a, loose) => new SemVer$9(a, loose).patch;
809
+ var patch_1 = patch$1;
810
+
811
+ const parse$3 = parse_1;
812
+ const prerelease$1 = (version, options) => {
813
+ const parsed = parse$3(version, options);
814
+ return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
815
+ };
816
+ var prerelease_1 = prerelease$1;
817
+
818
+ const SemVer$8 = semver$2;
819
+ const compare$b = (a, b, loose) =>
820
+ new SemVer$8(a, loose).compare(new SemVer$8(b, loose));
821
+
822
+ var compare_1 = compare$b;
823
+
824
+ const compare$a = compare_1;
825
+ const rcompare$1 = (a, b, loose) => compare$a(b, a, loose);
826
+ var rcompare_1 = rcompare$1;
827
+
828
+ const compare$9 = compare_1;
829
+ const compareLoose$1 = (a, b) => compare$9(a, b, true);
830
+ var compareLoose_1 = compareLoose$1;
831
+
832
+ const SemVer$7 = semver$2;
833
+ const compareBuild$3 = (a, b, loose) => {
834
+ const versionA = new SemVer$7(a, loose);
835
+ const versionB = new SemVer$7(b, loose);
836
+ return versionA.compare(versionB) || versionA.compareBuild(versionB)
837
+ };
838
+ var compareBuild_1 = compareBuild$3;
839
+
840
+ const compareBuild$2 = compareBuild_1;
841
+ const sort$1 = (list, loose) => list.sort((a, b) => compareBuild$2(a, b, loose));
842
+ var sort_1 = sort$1;
843
+
844
+ const compareBuild$1 = compareBuild_1;
845
+ const rsort$1 = (list, loose) => list.sort((a, b) => compareBuild$1(b, a, loose));
846
+ var rsort_1 = rsort$1;
847
+
848
+ const compare$8 = compare_1;
849
+ const gt$4 = (a, b, loose) => compare$8(a, b, loose) > 0;
850
+ var gt_1 = gt$4;
851
+
852
+ const compare$7 = compare_1;
853
+ const lt$3 = (a, b, loose) => compare$7(a, b, loose) < 0;
854
+ var lt_1 = lt$3;
855
+
856
+ const compare$6 = compare_1;
857
+ const eq$2 = (a, b, loose) => compare$6(a, b, loose) === 0;
858
+ var eq_1 = eq$2;
859
+
860
+ const compare$5 = compare_1;
861
+ const neq$2 = (a, b, loose) => compare$5(a, b, loose) !== 0;
862
+ var neq_1 = neq$2;
863
+
864
+ const compare$4 = compare_1;
865
+ const gte$3 = (a, b, loose) => compare$4(a, b, loose) >= 0;
866
+ var gte_1 = gte$3;
867
+
868
+ const compare$3 = compare_1;
869
+ const lte$3 = (a, b, loose) => compare$3(a, b, loose) <= 0;
870
+ var lte_1 = lte$3;
871
+
872
+ const eq$1 = eq_1;
873
+ const neq$1 = neq_1;
874
+ const gt$3 = gt_1;
875
+ const gte$2 = gte_1;
876
+ const lt$2 = lt_1;
877
+ const lte$2 = lte_1;
878
+
879
+ const cmp$1 = (a, op, b, loose) => {
880
+ switch (op) {
881
+ case '===':
882
+ if (typeof a === 'object') {
883
+ a = a.version;
884
+ }
885
+ if (typeof b === 'object') {
886
+ b = b.version;
887
+ }
888
+ return a === b
889
+
890
+ case '!==':
891
+ if (typeof a === 'object') {
892
+ a = a.version;
893
+ }
894
+ if (typeof b === 'object') {
895
+ b = b.version;
896
+ }
897
+ return a !== b
898
+
899
+ case '':
900
+ case '=':
901
+ case '==':
902
+ return eq$1(a, b, loose)
903
+
904
+ case '!=':
905
+ return neq$1(a, b, loose)
906
+
907
+ case '>':
908
+ return gt$3(a, b, loose)
909
+
910
+ case '>=':
911
+ return gte$2(a, b, loose)
912
+
913
+ case '<':
914
+ return lt$2(a, b, loose)
915
+
916
+ case '<=':
917
+ return lte$2(a, b, loose)
918
+
919
+ default:
920
+ throw new TypeError(`Invalid operator: ${op}`)
921
+ }
922
+ };
923
+ var cmp_1 = cmp$1;
924
+
925
+ const SemVer$6 = semver$2;
926
+ const parse$2 = parse_1;
927
+ const { safeRe: re, t } = reExports;
928
+
929
+ const coerce$1 = (version, options) => {
930
+ if (version instanceof SemVer$6) {
931
+ return version
932
+ }
933
+
934
+ if (typeof version === 'number') {
935
+ version = String(version);
936
+ }
937
+
938
+ if (typeof version !== 'string') {
939
+ return null
940
+ }
941
+
942
+ options = options || {};
943
+
944
+ let match = null;
945
+ if (!options.rtl) {
946
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
947
+ } else {
948
+ // Find the right-most coercible string that does not share
949
+ // a terminus with a more left-ward coercible string.
950
+ // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
951
+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
952
+ //
953
+ // Walk through the string checking with a /g regexp
954
+ // Manually set the index so as to pick up overlapping matches.
955
+ // Stop when we get a match that ends at the string end, since no
956
+ // coercible string can be more right-ward without the same terminus.
957
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
958
+ let next;
959
+ while ((next = coerceRtlRegex.exec(version)) &&
960
+ (!match || match.index + match[0].length !== version.length)
961
+ ) {
962
+ if (!match ||
963
+ next.index + next[0].length !== match.index + match[0].length) {
964
+ match = next;
965
+ }
966
+ coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
967
+ }
968
+ // leave it in a clean state
969
+ coerceRtlRegex.lastIndex = -1;
970
+ }
971
+
972
+ if (match === null) {
973
+ return null
974
+ }
975
+
976
+ const major = match[2];
977
+ const minor = match[3] || '0';
978
+ const patch = match[4] || '0';
979
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
980
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
981
+
982
+ return parse$2(`${major}.${minor}.${patch}${prerelease}${build}`, options)
983
+ };
984
+ var coerce_1 = coerce$1;
985
+
986
+ const parse$1 = parse_1;
987
+ const constants$1 = constants$2;
988
+ const SemVer$5 = semver$2;
989
+
990
+ const truncate$1 = (version, truncation, options) => {
991
+ if (!constants$1.RELEASE_TYPES.includes(truncation)) {
992
+ return null
993
+ }
994
+
995
+ const clonedVersion = cloneInputVersion(version, options);
996
+ return clonedVersion && doTruncation(clonedVersion, truncation)
997
+ };
998
+
999
+ const cloneInputVersion = (version, options) => {
1000
+ const versionStringToParse = (
1001
+ version instanceof SemVer$5 ? version.version : version
1002
+ );
1003
+
1004
+ return parse$1(versionStringToParse, options)
1005
+ };
1006
+
1007
+ const doTruncation = (version, truncation) => {
1008
+ if (isPrerelease(truncation)) {
1009
+ return version.version
1010
+ }
1011
+
1012
+ version.prerelease = [];
1013
+
1014
+ switch (truncation) {
1015
+ case 'major':
1016
+ version.minor = 0;
1017
+ version.patch = 0;
1018
+ break
1019
+ case 'minor':
1020
+ version.patch = 0;
1021
+ break
1022
+ }
1023
+
1024
+ return version.format()
1025
+ };
1026
+
1027
+ const isPrerelease = (type) => {
1028
+ return type.startsWith('pre')
1029
+ };
1030
+
1031
+ var truncate_1 = truncate$1;
1032
+
1033
+ class LRUCache {
1034
+ constructor () {
1035
+ this.max = 1000;
1036
+ this.map = new Map();
1037
+ }
1038
+
1039
+ get (key) {
1040
+ const value = this.map.get(key);
1041
+ if (value === undefined) {
1042
+ return undefined
1043
+ } else {
1044
+ // Remove the key from the map and add it to the end
1045
+ this.map.delete(key);
1046
+ this.map.set(key, value);
1047
+ return value
1048
+ }
1049
+ }
1050
+
1051
+ delete (key) {
1052
+ return this.map.delete(key)
1053
+ }
1054
+
1055
+ set (key, value) {
1056
+ const deleted = this.delete(key);
1057
+
1058
+ if (!deleted && value !== undefined) {
1059
+ // If cache is full, delete the least recently used item
1060
+ if (this.map.size >= this.max) {
1061
+ const firstKey = this.map.keys().next().value;
1062
+ this.delete(firstKey);
1063
+ }
1064
+
1065
+ this.map.set(key, value);
1066
+ }
1067
+
1068
+ return this
1069
+ }
1070
+ }
1071
+
1072
+ var lrucache = LRUCache;
1073
+
1074
+ var range;
1075
+ var hasRequiredRange;
1076
+
1077
+ function requireRange () {
1078
+ if (hasRequiredRange) return range;
1079
+ hasRequiredRange = 1;
1080
+
1081
+ const SPACE_CHARACTERS = /\s+/g;
1082
+
1083
+ // hoisted class for cyclic dependency
1084
+ class Range {
1085
+ constructor (range, options) {
1086
+ options = parseOptions(options);
1087
+
1088
+ if (range instanceof Range) {
1089
+ if (
1090
+ range.loose === !!options.loose &&
1091
+ range.includePrerelease === !!options.includePrerelease
1092
+ ) {
1093
+ return range
1094
+ } else {
1095
+ return new Range(range.raw, options)
1096
+ }
1097
+ }
1098
+
1099
+ if (range instanceof Comparator) {
1100
+ // just put it in the set and return
1101
+ this.raw = range.value;
1102
+ this.set = [[range]];
1103
+ this.formatted = undefined;
1104
+ return this
1105
+ }
1106
+
1107
+ this.options = options;
1108
+ this.loose = !!options.loose;
1109
+ this.includePrerelease = !!options.includePrerelease;
1110
+
1111
+ // First reduce all whitespace as much as possible so we do not have to rely
1112
+ // on potentially slow regexes like \s*. This is then stored and used for
1113
+ // future error messages as well.
1114
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
1115
+
1116
+ // First, split on ||
1117
+ this.set = this.raw
1118
+ .split('||')
1119
+ // map the range to a 2d array of comparators
1120
+ .map(r => this.parseRange(r.trim()))
1121
+ // throw out any comparator lists that are empty
1122
+ // this generally means that it was not a valid range, which is allowed
1123
+ // in loose mode, but will still throw if the WHOLE range is invalid.
1124
+ .filter(c => c.length);
1125
+
1126
+ if (!this.set.length) {
1127
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
1128
+ }
1129
+
1130
+ // if we have any that are not the null set, throw out null sets.
1131
+ if (this.set.length > 1) {
1132
+ // keep the first one, in case they're all null sets
1133
+ const first = this.set[0];
1134
+ this.set = this.set.filter(c => !isNullSet(c[0]));
1135
+ if (this.set.length === 0) {
1136
+ this.set = [first];
1137
+ } else if (this.set.length > 1) {
1138
+ // if we have any that are *, then the range is just *
1139
+ for (const c of this.set) {
1140
+ if (c.length === 1 && isAny(c[0])) {
1141
+ this.set = [c];
1142
+ break
1143
+ }
1144
+ }
1145
+ }
1146
+ }
1147
+
1148
+ this.formatted = undefined;
1149
+ }
1150
+
1151
+ get range () {
1152
+ if (this.formatted === undefined) {
1153
+ this.formatted = '';
1154
+ for (let i = 0; i < this.set.length; i++) {
1155
+ if (i > 0) {
1156
+ this.formatted += '||';
1157
+ }
1158
+ const comps = this.set[i];
1159
+ for (let k = 0; k < comps.length; k++) {
1160
+ if (k > 0) {
1161
+ this.formatted += ' ';
1162
+ }
1163
+ this.formatted += comps[k].toString().trim();
1164
+ }
1165
+ }
1166
+ }
1167
+ return this.formatted
1168
+ }
1169
+
1170
+ format () {
1171
+ return this.range
1172
+ }
1173
+
1174
+ toString () {
1175
+ return this.range
1176
+ }
1177
+
1178
+ parseRange (range) {
1179
+ // memoize range parsing for performance.
1180
+ // this is a very hot path, and fully deterministic.
1181
+ const memoOpts =
1182
+ (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
1183
+ (this.options.loose && FLAG_LOOSE);
1184
+ const memoKey = memoOpts + ':' + range;
1185
+ const cached = cache.get(memoKey);
1186
+ if (cached) {
1187
+ return cached
1188
+ }
1189
+
1190
+ const loose = this.options.loose;
1191
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
1192
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
1193
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
1194
+ debug('hyphen replace', range);
1195
+
1196
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
1197
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
1198
+ debug('comparator trim', range);
1199
+
1200
+ // `~ 1.2.3` => `~1.2.3`
1201
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
1202
+ debug('tilde trim', range);
1203
+
1204
+ // `^ 1.2.3` => `^1.2.3`
1205
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
1206
+ debug('caret trim', range);
1207
+
1208
+ // At this point, the range is completely trimmed and
1209
+ // ready to be split into comparators.
1210
+
1211
+ let rangeList = range
1212
+ .split(' ')
1213
+ .map(comp => parseComparator(comp, this.options))
1214
+ .join(' ')
1215
+ .split(/\s+/)
1216
+ // >=0.0.0 is equivalent to *
1217
+ .map(comp => replaceGTE0(comp, this.options));
1218
+
1219
+ if (loose) {
1220
+ // in loose mode, throw out any that are not valid comparators
1221
+ rangeList = rangeList.filter(comp => {
1222
+ debug('loose invalid filter', comp, this.options);
1223
+ return !!comp.match(re[t.COMPARATORLOOSE])
1224
+ });
1225
+ }
1226
+ debug('range list', rangeList);
1227
+
1228
+ // if any comparators are the null set, then replace with JUST null set
1229
+ // if more than one comparator, remove any * comparators
1230
+ // also, don't include the same comparator more than once
1231
+ const rangeMap = new Map();
1232
+ const comparators = rangeList.map(comp => new Comparator(comp, this.options));
1233
+ for (const comp of comparators) {
1234
+ if (isNullSet(comp)) {
1235
+ return [comp]
1236
+ }
1237
+ rangeMap.set(comp.value, comp);
1238
+ }
1239
+ if (rangeMap.size > 1 && rangeMap.has('')) {
1240
+ rangeMap.delete('');
1241
+ }
1242
+
1243
+ const result = [...rangeMap.values()];
1244
+ cache.set(memoKey, result);
1245
+ return result
1246
+ }
1247
+
1248
+ intersects (range, options) {
1249
+ if (!(range instanceof Range)) {
1250
+ throw new TypeError('a Range is required')
1251
+ }
1252
+
1253
+ return this.set.some((thisComparators) => {
1254
+ return (
1255
+ isSatisfiable(thisComparators, options) &&
1256
+ range.set.some((rangeComparators) => {
1257
+ return (
1258
+ isSatisfiable(rangeComparators, options) &&
1259
+ thisComparators.every((thisComparator) => {
1260
+ return rangeComparators.every((rangeComparator) => {
1261
+ return thisComparator.intersects(rangeComparator, options)
1262
+ })
1263
+ })
1264
+ )
1265
+ })
1266
+ )
1267
+ })
1268
+ }
1269
+
1270
+ // if ANY of the sets match ALL of its comparators, then pass
1271
+ test (version) {
1272
+ if (!version) {
1273
+ return false
1274
+ }
1275
+
1276
+ if (typeof version === 'string') {
1277
+ try {
1278
+ version = new SemVer(version, this.options);
1279
+ } catch (er) {
1280
+ return false
1281
+ }
1282
+ }
1283
+
1284
+ for (let i = 0; i < this.set.length; i++) {
1285
+ if (testSet(this.set[i], version, this.options)) {
1286
+ return true
1287
+ }
1288
+ }
1289
+ return false
1290
+ }
1291
+ }
1292
+
1293
+ range = Range;
1294
+
1295
+ const LRU = lrucache;
1296
+ const cache = new LRU();
1297
+
1298
+ const parseOptions = parseOptions_1;
1299
+ const Comparator = requireComparator();
1300
+ const debug = debug_1;
1301
+ const SemVer = semver$2;
1302
+ const {
1303
+ safeRe: re,
1304
+ t,
1305
+ comparatorTrimReplace,
1306
+ tildeTrimReplace,
1307
+ caretTrimReplace,
1308
+ } = reExports;
1309
+ const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = constants$2;
1310
+
1311
+ const isNullSet = c => c.value === '<0.0.0-0';
1312
+ const isAny = c => c.value === '';
1313
+
1314
+ // take a set of comparators and determine whether there
1315
+ // exists a version which can satisfy it
1316
+ const isSatisfiable = (comparators, options) => {
1317
+ let result = true;
1318
+ const remainingComparators = comparators.slice();
1319
+ let testComparator = remainingComparators.pop();
1320
+
1321
+ while (result && remainingComparators.length) {
1322
+ result = remainingComparators.every((otherComparator) => {
1323
+ return testComparator.intersects(otherComparator, options)
1324
+ });
1325
+
1326
+ testComparator = remainingComparators.pop();
1327
+ }
1328
+
1329
+ return result
1330
+ };
1331
+
1332
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
1333
+ // already replaced the hyphen ranges
1334
+ // turn into a set of JUST comparators.
1335
+ const parseComparator = (comp, options) => {
1336
+ comp = comp.replace(re[t.BUILD], '');
1337
+ debug('comp', comp, options);
1338
+ comp = replaceCarets(comp, options);
1339
+ debug('caret', comp);
1340
+ comp = replaceTildes(comp, options);
1341
+ debug('tildes', comp);
1342
+ comp = replaceXRanges(comp, options);
1343
+ debug('xrange', comp);
1344
+ comp = replaceStars(comp, options);
1345
+ debug('stars', comp);
1346
+ return comp
1347
+ };
1348
+
1349
+ const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
1350
+
1351
+ // ~, ~> --> * (any, kinda silly)
1352
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
1353
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
1354
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
1355
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
1356
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
1357
+ // ~0.0.1 --> >=0.0.1 <0.1.0-0
1358
+ const replaceTildes = (comp, options) => {
1359
+ return comp
1360
+ .trim()
1361
+ .split(/\s+/)
1362
+ .map((c) => replaceTilde(c, options))
1363
+ .join(' ')
1364
+ };
1365
+
1366
+ const replaceTilde = (comp, options) => {
1367
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
1368
+ return comp.replace(r, (_, M, m, p, pr) => {
1369
+ debug('tilde', comp, _, M, m, p, pr);
1370
+ let ret;
1371
+
1372
+ if (isX(M)) {
1373
+ ret = '';
1374
+ } else if (isX(m)) {
1375
+ ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
1376
+ } else if (isX(p)) {
1377
+ // ~1.2 == >=1.2.0 <1.3.0-0
1378
+ ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
1379
+ } else if (pr) {
1380
+ debug('replaceTilde pr', pr);
1381
+ ret = `>=${M}.${m}.${p}-${pr
1382
+ } <${M}.${+m + 1}.0-0`;
1383
+ } else {
1384
+ // ~1.2.3 == >=1.2.3 <1.3.0-0
1385
+ ret = `>=${M}.${m}.${p
1386
+ } <${M}.${+m + 1}.0-0`;
1387
+ }
1388
+
1389
+ debug('tilde return', ret);
1390
+ return ret
1391
+ })
1392
+ };
1393
+
1394
+ // ^ --> * (any, kinda silly)
1395
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
1396
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
1397
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
1398
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
1399
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
1400
+ // ^0.0.1 --> >=0.0.1 <0.0.2-0
1401
+ // ^0.1.0 --> >=0.1.0 <0.2.0-0
1402
+ const replaceCarets = (comp, options) => {
1403
+ return comp
1404
+ .trim()
1405
+ .split(/\s+/)
1406
+ .map((c) => replaceCaret(c, options))
1407
+ .join(' ')
1408
+ };
1409
+
1410
+ const replaceCaret = (comp, options) => {
1411
+ debug('caret', comp, options);
1412
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
1413
+ const z = options.includePrerelease ? '-0' : '';
1414
+ return comp.replace(r, (_, M, m, p, pr) => {
1415
+ debug('caret', comp, _, M, m, p, pr);
1416
+ let ret;
1417
+
1418
+ if (isX(M)) {
1419
+ ret = '';
1420
+ } else if (isX(m)) {
1421
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1422
+ } else if (isX(p)) {
1423
+ if (M === '0') {
1424
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1425
+ } else {
1426
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
1427
+ }
1428
+ } else if (pr) {
1429
+ debug('replaceCaret pr', pr);
1430
+ if (M === '0') {
1431
+ if (m === '0') {
1432
+ ret = `>=${M}.${m}.${p}-${pr
1433
+ } <${M}.${m}.${+p + 1}-0`;
1434
+ } else {
1435
+ ret = `>=${M}.${m}.${p}-${pr
1436
+ } <${M}.${+m + 1}.0-0`;
1437
+ }
1438
+ } else {
1439
+ ret = `>=${M}.${m}.${p}-${pr
1440
+ } <${+M + 1}.0.0-0`;
1441
+ }
1442
+ } else {
1443
+ debug('no pr');
1444
+ if (M === '0') {
1445
+ if (m === '0') {
1446
+ ret = `>=${M}.${m}.${p
1447
+ }${z} <${M}.${m}.${+p + 1}-0`;
1448
+ } else {
1449
+ ret = `>=${M}.${m}.${p
1450
+ }${z} <${M}.${+m + 1}.0-0`;
1451
+ }
1452
+ } else {
1453
+ ret = `>=${M}.${m}.${p
1454
+ } <${+M + 1}.0.0-0`;
1455
+ }
1456
+ }
1457
+
1458
+ debug('caret return', ret);
1459
+ return ret
1460
+ })
1461
+ };
1462
+
1463
+ const replaceXRanges = (comp, options) => {
1464
+ debug('replaceXRanges', comp, options);
1465
+ return comp
1466
+ .split(/\s+/)
1467
+ .map((c) => replaceXRange(c, options))
1468
+ .join(' ')
1469
+ };
1470
+
1471
+ const replaceXRange = (comp, options) => {
1472
+ comp = comp.trim();
1473
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
1474
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
1475
+ debug('xRange', comp, ret, gtlt, M, m, p, pr);
1476
+ const xM = isX(M);
1477
+ const xm = xM || isX(m);
1478
+ const xp = xm || isX(p);
1479
+ const anyX = xp;
1480
+
1481
+ if (gtlt === '=' && anyX) {
1482
+ gtlt = '';
1483
+ }
1484
+
1485
+ // if we're including prereleases in the match, then we need
1486
+ // to fix this to -0, the lowest possible prerelease value
1487
+ pr = options.includePrerelease ? '-0' : '';
1488
+
1489
+ if (xM) {
1490
+ if (gtlt === '>' || gtlt === '<') {
1491
+ // nothing is allowed
1492
+ ret = '<0.0.0-0';
1493
+ } else {
1494
+ // nothing is forbidden
1495
+ ret = '*';
1496
+ }
1497
+ } else if (gtlt && anyX) {
1498
+ // we know patch is an x, because we have any x at all.
1499
+ // replace X with 0
1500
+ if (xm) {
1501
+ m = 0;
1502
+ }
1503
+ p = 0;
1504
+
1505
+ if (gtlt === '>') {
1506
+ // >1 => >=2.0.0
1507
+ // >1.2 => >=1.3.0
1508
+ gtlt = '>=';
1509
+ if (xm) {
1510
+ M = +M + 1;
1511
+ m = 0;
1512
+ p = 0;
1513
+ } else {
1514
+ m = +m + 1;
1515
+ p = 0;
1516
+ }
1517
+ } else if (gtlt === '<=') {
1518
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
1519
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
1520
+ gtlt = '<';
1521
+ if (xm) {
1522
+ M = +M + 1;
1523
+ } else {
1524
+ m = +m + 1;
1525
+ }
1526
+ }
1527
+
1528
+ if (gtlt === '<') {
1529
+ pr = '-0';
1530
+ }
1531
+
1532
+ ret = `${gtlt + M}.${m}.${p}${pr}`;
1533
+ } else if (xm) {
1534
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
1535
+ } else if (xp) {
1536
+ ret = `>=${M}.${m}.0${pr
1537
+ } <${M}.${+m + 1}.0-0`;
1538
+ }
1539
+
1540
+ debug('xRange return', ret);
1541
+
1542
+ return ret
1543
+ })
1544
+ };
1545
+
1546
+ // Because * is AND-ed with everything else in the comparator,
1547
+ // and '' means "any version", just remove the *s entirely.
1548
+ const replaceStars = (comp, options) => {
1549
+ debug('replaceStars', comp, options);
1550
+ // Looseness is ignored here. star is always as loose as it gets!
1551
+ return comp
1552
+ .trim()
1553
+ .replace(re[t.STAR], '')
1554
+ };
1555
+
1556
+ const replaceGTE0 = (comp, options) => {
1557
+ debug('replaceGTE0', comp, options);
1558
+ return comp
1559
+ .trim()
1560
+ .replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
1561
+ };
1562
+
1563
+ // This function is passed to string.replace(re[t.HYPHENRANGE])
1564
+ // M, m, patch, prerelease, build
1565
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
1566
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
1567
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0-0
1568
+ // TODO build?
1569
+ const hyphenReplace = incPr => ($0,
1570
+ from, fM, fm, fp, fpr, fb,
1571
+ to, tM, tm, tp, tpr) => {
1572
+ if (isX(fM)) {
1573
+ from = '';
1574
+ } else if (isX(fm)) {
1575
+ from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
1576
+ } else if (isX(fp)) {
1577
+ from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
1578
+ } else if (fpr) {
1579
+ from = `>=${from}`;
1580
+ } else {
1581
+ from = `>=${from}${incPr ? '-0' : ''}`;
1582
+ }
1583
+
1584
+ if (isX(tM)) {
1585
+ to = '';
1586
+ } else if (isX(tm)) {
1587
+ to = `<${+tM + 1}.0.0-0`;
1588
+ } else if (isX(tp)) {
1589
+ to = `<${tM}.${+tm + 1}.0-0`;
1590
+ } else if (tpr) {
1591
+ to = `<=${tM}.${tm}.${tp}-${tpr}`;
1592
+ } else if (incPr) {
1593
+ to = `<${tM}.${tm}.${+tp + 1}-0`;
1594
+ } else {
1595
+ to = `<=${to}`;
1596
+ }
1597
+
1598
+ return `${from} ${to}`.trim()
1599
+ };
1600
+
1601
+ const testSet = (set, version, options) => {
1602
+ for (let i = 0; i < set.length; i++) {
1603
+ if (!set[i].test(version)) {
1604
+ return false
1605
+ }
1606
+ }
1607
+
1608
+ if (version.prerelease.length && !options.includePrerelease) {
1609
+ // Find the set of versions that are allowed to have prereleases
1610
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
1611
+ // That should allow `1.2.3-pr.2` to pass.
1612
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
1613
+ // even though it's within the range set by the comparators.
1614
+ for (let i = 0; i < set.length; i++) {
1615
+ debug(set[i].semver);
1616
+ if (set[i].semver === Comparator.ANY) {
1617
+ continue
1618
+ }
1619
+
1620
+ if (set[i].semver.prerelease.length > 0) {
1621
+ const allowed = set[i].semver;
1622
+ if (allowed.major === version.major &&
1623
+ allowed.minor === version.minor &&
1624
+ allowed.patch === version.patch) {
1625
+ return true
1626
+ }
1627
+ }
1628
+ }
1629
+
1630
+ // Version has a -pre, but it's not one of the ones we like.
1631
+ return false
1632
+ }
1633
+
1634
+ return true
1635
+ };
1636
+ return range;
1637
+ }
1638
+
1639
+ var comparator;
1640
+ var hasRequiredComparator;
1641
+
1642
+ function requireComparator () {
1643
+ if (hasRequiredComparator) return comparator;
1644
+ hasRequiredComparator = 1;
1645
+
1646
+ const ANY = Symbol('SemVer ANY');
1647
+ // hoisted class for cyclic dependency
1648
+ class Comparator {
1649
+ static get ANY () {
1650
+ return ANY
1651
+ }
1652
+
1653
+ constructor (comp, options) {
1654
+ options = parseOptions(options);
1655
+
1656
+ if (comp instanceof Comparator) {
1657
+ if (comp.loose === !!options.loose) {
1658
+ return comp
1659
+ } else {
1660
+ comp = comp.value;
1661
+ }
1662
+ }
1663
+
1664
+ comp = comp.trim().split(/\s+/).join(' ');
1665
+ debug('comparator', comp, options);
1666
+ this.options = options;
1667
+ this.loose = !!options.loose;
1668
+ this.parse(comp);
1669
+
1670
+ if (this.semver === ANY) {
1671
+ this.value = '';
1672
+ } else {
1673
+ this.value = this.operator + this.semver.version;
1674
+ }
1675
+
1676
+ debug('comp', this);
1677
+ }
1678
+
1679
+ parse (comp) {
1680
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
1681
+ const m = comp.match(r);
1682
+
1683
+ if (!m) {
1684
+ throw new TypeError(`Invalid comparator: ${comp}`)
1685
+ }
1686
+
1687
+ this.operator = m[1] !== undefined ? m[1] : '';
1688
+ if (this.operator === '=') {
1689
+ this.operator = '';
1690
+ }
1691
+
1692
+ // if it literally is just '>' or '' then allow anything.
1693
+ if (!m[2]) {
1694
+ this.semver = ANY;
1695
+ } else {
1696
+ this.semver = new SemVer(m[2], this.options.loose);
1697
+ }
1698
+ }
1699
+
1700
+ toString () {
1701
+ return this.value
1702
+ }
1703
+
1704
+ test (version) {
1705
+ debug('Comparator.test', version, this.options.loose);
1706
+
1707
+ if (this.semver === ANY || version === ANY) {
1708
+ return true
1709
+ }
1710
+
1711
+ if (typeof version === 'string') {
1712
+ try {
1713
+ version = new SemVer(version, this.options);
1714
+ } catch (er) {
1715
+ return false
1716
+ }
1717
+ }
1718
+
1719
+ return cmp(version, this.operator, this.semver, this.options)
1720
+ }
1721
+
1722
+ intersects (comp, options) {
1723
+ if (!(comp instanceof Comparator)) {
1724
+ throw new TypeError('a Comparator is required')
1725
+ }
1726
+
1727
+ if (this.operator === '') {
1728
+ if (this.value === '') {
1729
+ return true
1730
+ }
1731
+ return new Range(comp.value, options).test(this.value)
1732
+ } else if (comp.operator === '') {
1733
+ if (comp.value === '') {
1734
+ return true
1735
+ }
1736
+ return new Range(this.value, options).test(comp.semver)
1737
+ }
1738
+
1739
+ options = parseOptions(options);
1740
+
1741
+ // Special cases where nothing can possibly be lower
1742
+ if (options.includePrerelease &&
1743
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
1744
+ return false
1745
+ }
1746
+ if (!options.includePrerelease &&
1747
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
1748
+ return false
1749
+ }
1750
+
1751
+ // Same direction increasing (> or >=)
1752
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
1753
+ return true
1754
+ }
1755
+ // Same direction decreasing (< or <=)
1756
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
1757
+ return true
1758
+ }
1759
+ // same SemVer and both sides are inclusive (<= or >=)
1760
+ if (
1761
+ (this.semver.version === comp.semver.version) &&
1762
+ this.operator.includes('=') && comp.operator.includes('=')) {
1763
+ return true
1764
+ }
1765
+ // opposite directions less than
1766
+ if (cmp(this.semver, '<', comp.semver, options) &&
1767
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
1768
+ return true
1769
+ }
1770
+ // opposite directions greater than
1771
+ if (cmp(this.semver, '>', comp.semver, options) &&
1772
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
1773
+ return true
1774
+ }
1775
+ return false
1776
+ }
1777
+ }
1778
+
1779
+ comparator = Comparator;
1780
+
1781
+ const parseOptions = parseOptions_1;
1782
+ const { safeRe: re, t } = reExports;
1783
+ const cmp = cmp_1;
1784
+ const debug = debug_1;
1785
+ const SemVer = semver$2;
1786
+ const Range = requireRange();
1787
+ return comparator;
1788
+ }
1789
+
1790
+ const Range$9 = requireRange();
1791
+ const satisfies$4 = (version, range, options) => {
1792
+ try {
1793
+ range = new Range$9(range, options);
1794
+ } catch (er) {
1795
+ return false
1796
+ }
1797
+ return range.test(version)
1798
+ };
1799
+ var satisfies_1 = satisfies$4;
1800
+
1801
+ const Range$8 = requireRange();
1802
+
1803
+ // Mostly just for testing and legacy API reasons
1804
+ const toComparators$1 = (range, options) =>
1805
+ new Range$8(range, options).set
1806
+ .map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
1807
+
1808
+ var toComparators_1 = toComparators$1;
1809
+
1810
+ const SemVer$4 = semver$2;
1811
+ const Range$7 = requireRange();
1812
+
1813
+ const maxSatisfying$1 = (versions, range, options) => {
1814
+ let max = null;
1815
+ let maxSV = null;
1816
+ let rangeObj = null;
1817
+ try {
1818
+ rangeObj = new Range$7(range, options);
1819
+ } catch (er) {
1820
+ return null
1821
+ }
1822
+ versions.forEach((v) => {
1823
+ if (rangeObj.test(v)) {
1824
+ // satisfies(v, range, options)
1825
+ if (!max || maxSV.compare(v) === -1) {
1826
+ // compare(max, v, true)
1827
+ max = v;
1828
+ maxSV = new SemVer$4(max, options);
1829
+ }
1830
+ }
1831
+ });
1832
+ return max
1833
+ };
1834
+ var maxSatisfying_1 = maxSatisfying$1;
1835
+
1836
+ const SemVer$3 = semver$2;
1837
+ const Range$6 = requireRange();
1838
+ const minSatisfying$1 = (versions, range, options) => {
1839
+ let min = null;
1840
+ let minSV = null;
1841
+ let rangeObj = null;
1842
+ try {
1843
+ rangeObj = new Range$6(range, options);
1844
+ } catch (er) {
1845
+ return null
1846
+ }
1847
+ versions.forEach((v) => {
1848
+ if (rangeObj.test(v)) {
1849
+ // satisfies(v, range, options)
1850
+ if (!min || minSV.compare(v) === 1) {
1851
+ // compare(min, v, true)
1852
+ min = v;
1853
+ minSV = new SemVer$3(min, options);
1854
+ }
1855
+ }
1856
+ });
1857
+ return min
1858
+ };
1859
+ var minSatisfying_1 = minSatisfying$1;
1860
+
1861
+ const SemVer$2 = semver$2;
1862
+ const Range$5 = requireRange();
1863
+ const gt$2 = gt_1;
1864
+
1865
+ const minVersion$1 = (range, loose) => {
1866
+ range = new Range$5(range, loose);
1867
+
1868
+ let minver = new SemVer$2('0.0.0');
1869
+ if (range.test(minver)) {
1870
+ return minver
1871
+ }
1872
+
1873
+ minver = new SemVer$2('0.0.0-0');
1874
+ if (range.test(minver)) {
1875
+ return minver
1876
+ }
1877
+
1878
+ minver = null;
1879
+ for (let i = 0; i < range.set.length; ++i) {
1880
+ const comparators = range.set[i];
1881
+
1882
+ let setMin = null;
1883
+ comparators.forEach((comparator) => {
1884
+ // Clone to avoid manipulating the comparator's semver object.
1885
+ const compver = new SemVer$2(comparator.semver.version);
1886
+ switch (comparator.operator) {
1887
+ case '>':
1888
+ if (compver.prerelease.length === 0) {
1889
+ compver.patch++;
1890
+ } else {
1891
+ compver.prerelease.push(0);
1892
+ }
1893
+ compver.raw = compver.format();
1894
+ /* fallthrough */
1895
+ case '':
1896
+ case '>=':
1897
+ if (!setMin || gt$2(compver, setMin)) {
1898
+ setMin = compver;
1899
+ }
1900
+ break
1901
+ case '<':
1902
+ case '<=':
1903
+ /* Ignore maximum versions */
1904
+ break
1905
+ /* istanbul ignore next */
1906
+ default:
1907
+ throw new Error(`Unexpected operation: ${comparator.operator}`)
1908
+ }
1909
+ });
1910
+ if (setMin && (!minver || gt$2(minver, setMin))) {
1911
+ minver = setMin;
1912
+ }
1913
+ }
1914
+
1915
+ if (minver && range.test(minver)) {
1916
+ return minver
1917
+ }
1918
+
1919
+ return null
1920
+ };
1921
+ var minVersion_1 = minVersion$1;
1922
+
1923
+ const Range$4 = requireRange();
1924
+ const validRange$1 = (range, options) => {
1925
+ try {
1926
+ // Return '*' instead of '' so that truthiness works.
1927
+ // This will throw if it's invalid anyway
1928
+ return new Range$4(range, options).range || '*'
1929
+ } catch (er) {
1930
+ return null
1931
+ }
1932
+ };
1933
+ var valid$1 = validRange$1;
1934
+
1935
+ const SemVer$1 = semver$2;
1936
+ const Comparator$2 = requireComparator();
1937
+ const { ANY: ANY$1 } = Comparator$2;
1938
+ const Range$3 = requireRange();
1939
+ const satisfies$3 = satisfies_1;
1940
+ const gt$1 = gt_1;
1941
+ const lt$1 = lt_1;
1942
+ const lte$1 = lte_1;
1943
+ const gte$1 = gte_1;
1944
+
1945
+ const outside$3 = (version, range, hilo, options) => {
1946
+ version = new SemVer$1(version, options);
1947
+ range = new Range$3(range, options);
1948
+
1949
+ let gtfn, ltefn, ltfn, comp, ecomp;
1950
+ switch (hilo) {
1951
+ case '>':
1952
+ gtfn = gt$1;
1953
+ ltefn = lte$1;
1954
+ ltfn = lt$1;
1955
+ comp = '>';
1956
+ ecomp = '>=';
1957
+ break
1958
+ case '<':
1959
+ gtfn = lt$1;
1960
+ ltefn = gte$1;
1961
+ ltfn = gt$1;
1962
+ comp = '<';
1963
+ ecomp = '<=';
1964
+ break
1965
+ default:
1966
+ throw new TypeError('Must provide a hilo val of "<" or ">"')
1967
+ }
1968
+
1969
+ // If it satisfies the range it is not outside
1970
+ if (satisfies$3(version, range, options)) {
1971
+ return false
1972
+ }
1973
+
1974
+ // From now on, variable terms are as if we're in "gtr" mode.
1975
+ // but note that everything is flipped for the "ltr" function.
1976
+
1977
+ for (let i = 0; i < range.set.length; ++i) {
1978
+ const comparators = range.set[i];
1979
+
1980
+ let high = null;
1981
+ let low = null;
1982
+
1983
+ comparators.forEach((comparator) => {
1984
+ if (comparator.semver === ANY$1) {
1985
+ comparator = new Comparator$2('>=0.0.0');
1986
+ }
1987
+ high = high || comparator;
1988
+ low = low || comparator;
1989
+ if (gtfn(comparator.semver, high.semver, options)) {
1990
+ high = comparator;
1991
+ } else if (ltfn(comparator.semver, low.semver, options)) {
1992
+ low = comparator;
1993
+ }
1994
+ });
1995
+
1996
+ // If the edge version comparator has a operator then our version
1997
+ // isn't outside it
1998
+ if (high.operator === comp || high.operator === ecomp) {
1999
+ return false
2000
+ }
2001
+
2002
+ // If the lowest version comparator has an operator and our version
2003
+ // is less than it then it isn't higher than the range
2004
+ if ((!low.operator || low.operator === comp) &&
2005
+ ltefn(version, low.semver)) {
2006
+ return false
2007
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
2008
+ return false
2009
+ }
2010
+ }
2011
+ return true
2012
+ };
2013
+
2014
+ var outside_1 = outside$3;
2015
+
2016
+ // Determine if version is greater than all the versions possible in the range.
2017
+ const outside$2 = outside_1;
2018
+ const gtr$1 = (version, range, options) => outside$2(version, range, '>', options);
2019
+ var gtr_1 = gtr$1;
2020
+
2021
+ const outside$1 = outside_1;
2022
+ // Determine if version is less than all the versions possible in the range
2023
+ const ltr$1 = (version, range, options) => outside$1(version, range, '<', options);
2024
+ var ltr_1 = ltr$1;
2025
+
2026
+ const Range$2 = requireRange();
2027
+ const intersects$1 = (r1, r2, options) => {
2028
+ r1 = new Range$2(r1, options);
2029
+ r2 = new Range$2(r2, options);
2030
+ return r1.intersects(r2, options)
2031
+ };
2032
+ var intersects_1 = intersects$1;
2033
+
2034
+ // given a set of versions and a range, create a "simplified" range
2035
+ // that includes the same versions that the original range does
2036
+ // If the original range is shorter than the simplified one, return that.
2037
+ const satisfies$2 = satisfies_1;
2038
+ const compare$2 = compare_1;
2039
+ var simplify = (versions, range, options) => {
2040
+ const set = [];
2041
+ let first = null;
2042
+ let prev = null;
2043
+ const v = versions.sort((a, b) => compare$2(a, b, options));
2044
+ for (const version of v) {
2045
+ const included = satisfies$2(version, range, options);
2046
+ if (included) {
2047
+ prev = version;
2048
+ if (!first) {
2049
+ first = version;
2050
+ }
2051
+ } else {
2052
+ if (prev) {
2053
+ set.push([first, prev]);
2054
+ }
2055
+ prev = null;
2056
+ first = null;
2057
+ }
2058
+ }
2059
+ if (first) {
2060
+ set.push([first, null]);
2061
+ }
2062
+
2063
+ const ranges = [];
2064
+ for (const [min, max] of set) {
2065
+ if (min === max) {
2066
+ ranges.push(min);
2067
+ } else if (!max && min === v[0]) {
2068
+ ranges.push('*');
2069
+ } else if (!max) {
2070
+ ranges.push(`>=${min}`);
2071
+ } else if (min === v[0]) {
2072
+ ranges.push(`<=${max}`);
2073
+ } else {
2074
+ ranges.push(`${min} - ${max}`);
2075
+ }
2076
+ }
2077
+ const simplified = ranges.join(' || ');
2078
+ const original = typeof range.raw === 'string' ? range.raw : String(range);
2079
+ return simplified.length < original.length ? simplified : range
2080
+ };
2081
+
2082
+ const Range$1 = requireRange();
2083
+ const Comparator$1 = requireComparator();
2084
+ const { ANY } = Comparator$1;
2085
+ const satisfies$1 = satisfies_1;
2086
+ const compare$1 = compare_1;
2087
+
2088
+ // Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
2089
+ // - Every simple range `r1, r2, ...` is a null set, OR
2090
+ // - Every simple range `r1, r2, ...` which is not a null set is a subset of
2091
+ // some `R1, R2, ...`
2092
+ //
2093
+ // Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
2094
+ // - If c is only the ANY comparator
2095
+ // - If C is only the ANY comparator, return true
2096
+ // - Else if in prerelease mode, return false
2097
+ // - else replace c with `[>=0.0.0]`
2098
+ // - If C is only the ANY comparator
2099
+ // - if in prerelease mode, return true
2100
+ // - else replace C with `[>=0.0.0]`
2101
+ // - Let EQ be the set of = comparators in c
2102
+ // - If EQ is more than one, return true (null set)
2103
+ // - Let GT be the highest > or >= comparator in c
2104
+ // - Let LT be the lowest < or <= comparator in c
2105
+ // - If GT and LT, and GT.semver > LT.semver, return true (null set)
2106
+ // - If any C is a = range, and GT or LT are set, return false
2107
+ // - If EQ
2108
+ // - If GT, and EQ does not satisfy GT, return true (null set)
2109
+ // - If LT, and EQ does not satisfy LT, return true (null set)
2110
+ // - If EQ satisfies every C, return true
2111
+ // - Else return false
2112
+ // - If GT
2113
+ // - If GT.semver is lower than any > or >= comp in C, return false
2114
+ // - If GT is >=, and GT.semver does not satisfy every C, return false
2115
+ // - If GT.semver has a prerelease, and not in prerelease mode
2116
+ // - If no C has a prerelease and the GT.semver tuple, return false
2117
+ // - If LT
2118
+ // - If LT.semver is greater than any < or <= comp in C, return false
2119
+ // - If LT is <=, and LT.semver does not satisfy every C, return false
2120
+ // - If LT.semver has a prerelease, and not in prerelease mode
2121
+ // - If no C has a prerelease and the LT.semver tuple, return false
2122
+ // - Else return true
2123
+
2124
+ const subset$1 = (sub, dom, options = {}) => {
2125
+ if (sub === dom) {
2126
+ return true
2127
+ }
2128
+
2129
+ sub = new Range$1(sub, options);
2130
+ dom = new Range$1(dom, options);
2131
+ let sawNonNull = false;
2132
+
2133
+ OUTER: for (const simpleSub of sub.set) {
2134
+ for (const simpleDom of dom.set) {
2135
+ const isSub = simpleSubset(simpleSub, simpleDom, options);
2136
+ sawNonNull = sawNonNull || isSub !== null;
2137
+ if (isSub) {
2138
+ continue OUTER
2139
+ }
2140
+ }
2141
+ // the null set is a subset of everything, but null simple ranges in
2142
+ // a complex range should be ignored. so if we saw a non-null range,
2143
+ // then we know this isn't a subset, but if EVERY simple range was null,
2144
+ // then it is a subset.
2145
+ if (sawNonNull) {
2146
+ return false
2147
+ }
2148
+ }
2149
+ return true
2150
+ };
2151
+
2152
+ const minimumVersionWithPreRelease = [new Comparator$1('>=0.0.0-0')];
2153
+ const minimumVersion = [new Comparator$1('>=0.0.0')];
2154
+
2155
+ const simpleSubset = (sub, dom, options) => {
2156
+ if (sub === dom) {
2157
+ return true
2158
+ }
2159
+
2160
+ if (sub.length === 1 && sub[0].semver === ANY) {
2161
+ if (dom.length === 1 && dom[0].semver === ANY) {
2162
+ return true
2163
+ } else if (options.includePrerelease) {
2164
+ sub = minimumVersionWithPreRelease;
2165
+ } else {
2166
+ sub = minimumVersion;
2167
+ }
2168
+ }
2169
+
2170
+ if (dom.length === 1 && dom[0].semver === ANY) {
2171
+ if (options.includePrerelease) {
2172
+ return true
2173
+ } else {
2174
+ dom = minimumVersion;
2175
+ }
2176
+ }
2177
+
2178
+ const eqSet = new Set();
2179
+ let gt, lt;
2180
+ for (const c of sub) {
2181
+ if (c.operator === '>' || c.operator === '>=') {
2182
+ gt = higherGT(gt, c, options);
2183
+ } else if (c.operator === '<' || c.operator === '<=') {
2184
+ lt = lowerLT(lt, c, options);
2185
+ } else {
2186
+ eqSet.add(c.semver);
2187
+ }
2188
+ }
2189
+
2190
+ if (eqSet.size > 1) {
2191
+ return null
2192
+ }
2193
+
2194
+ let gtltComp;
2195
+ if (gt && lt) {
2196
+ gtltComp = compare$1(gt.semver, lt.semver, options);
2197
+ if (gtltComp > 0) {
2198
+ return null
2199
+ } else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
2200
+ return null
2201
+ }
2202
+ }
2203
+
2204
+ // will iterate one or zero times
2205
+ for (const eq of eqSet) {
2206
+ if (gt && !satisfies$1(eq, String(gt), options)) {
2207
+ return null
2208
+ }
2209
+
2210
+ if (lt && !satisfies$1(eq, String(lt), options)) {
2211
+ return null
2212
+ }
2213
+
2214
+ for (const c of dom) {
2215
+ if (!satisfies$1(eq, String(c), options)) {
2216
+ return false
2217
+ }
2218
+ }
2219
+
2220
+ return true
2221
+ }
2222
+
2223
+ let higher, lower;
2224
+ let hasDomLT, hasDomGT;
2225
+ // if the subset has a prerelease, we need a comparator in the superset
2226
+ // with the same tuple and a prerelease, or it's not a subset
2227
+ let needDomLTPre = lt &&
2228
+ !options.includePrerelease &&
2229
+ lt.semver.prerelease.length ? lt.semver : false;
2230
+ let needDomGTPre = gt &&
2231
+ !options.includePrerelease &&
2232
+ gt.semver.prerelease.length ? gt.semver : false;
2233
+ // exception: <1.2.3-0 is the same as <1.2.3
2234
+ if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
2235
+ lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
2236
+ needDomLTPre = false;
2237
+ }
2238
+
2239
+ for (const c of dom) {
2240
+ hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
2241
+ hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
2242
+ if (gt) {
2243
+ if (needDomGTPre) {
2244
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2245
+ c.semver.major === needDomGTPre.major &&
2246
+ c.semver.minor === needDomGTPre.minor &&
2247
+ c.semver.patch === needDomGTPre.patch) {
2248
+ needDomGTPre = false;
2249
+ }
2250
+ }
2251
+ if (c.operator === '>' || c.operator === '>=') {
2252
+ higher = higherGT(gt, c, options);
2253
+ if (higher === c && higher !== gt) {
2254
+ return false
2255
+ }
2256
+ } else if (gt.operator === '>=' && !satisfies$1(gt.semver, String(c), options)) {
2257
+ return false
2258
+ }
2259
+ }
2260
+ if (lt) {
2261
+ if (needDomLTPre) {
2262
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2263
+ c.semver.major === needDomLTPre.major &&
2264
+ c.semver.minor === needDomLTPre.minor &&
2265
+ c.semver.patch === needDomLTPre.patch) {
2266
+ needDomLTPre = false;
2267
+ }
2268
+ }
2269
+ if (c.operator === '<' || c.operator === '<=') {
2270
+ lower = lowerLT(lt, c, options);
2271
+ if (lower === c && lower !== lt) {
2272
+ return false
2273
+ }
2274
+ } else if (lt.operator === '<=' && !satisfies$1(lt.semver, String(c), options)) {
2275
+ return false
2276
+ }
2277
+ }
2278
+ if (!c.operator && (lt || gt) && gtltComp !== 0) {
2279
+ return false
2280
+ }
2281
+ }
2282
+
2283
+ // if there was a < or >, and nothing in the dom, then must be false
2284
+ // UNLESS it was limited by another range in the other direction.
2285
+ // Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
2286
+ if (gt && hasDomLT && !lt && gtltComp !== 0) {
2287
+ return false
2288
+ }
2289
+
2290
+ if (lt && hasDomGT && !gt && gtltComp !== 0) {
2291
+ return false
2292
+ }
2293
+
2294
+ // we needed a prerelease range in a specific tuple, but didn't get one
2295
+ // then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
2296
+ // because it includes prereleases in the 1.2.3 tuple
2297
+ if (needDomGTPre || needDomLTPre) {
2298
+ return false
2299
+ }
2300
+
2301
+ return true
2302
+ };
2303
+
2304
+ // >=1.2.3 is lower than >1.2.3
2305
+ const higherGT = (a, b, options) => {
2306
+ if (!a) {
2307
+ return b
2308
+ }
2309
+ const comp = compare$1(a.semver, b.semver, options);
2310
+ return comp > 0 ? a
2311
+ : comp < 0 ? b
2312
+ : b.operator === '>' && a.operator === '>=' ? b
2313
+ : a
2314
+ };
2315
+
2316
+ // <=1.2.3 is higher than <1.2.3
2317
+ const lowerLT = (a, b, options) => {
2318
+ if (!a) {
2319
+ return b
2320
+ }
2321
+ const comp = compare$1(a.semver, b.semver, options);
2322
+ return comp < 0 ? a
2323
+ : comp > 0 ? b
2324
+ : b.operator === '<' && a.operator === '<=' ? b
2325
+ : a
2326
+ };
2327
+
2328
+ var subset_1 = subset$1;
2329
+
2330
+ // just pre-load all the stuff that index.js lazily exports
2331
+ const internalRe = reExports;
2332
+ const constants = constants$2;
2333
+ const SemVer = semver$2;
2334
+ const identifiers = identifiers$1;
2335
+ const parse = parse_1;
2336
+ const valid = valid_1;
2337
+ const clean = clean_1;
2338
+ const inc = inc_1;
2339
+ const diff = diff_1;
2340
+ const major = major_1;
2341
+ const minor = minor_1;
2342
+ const patch = patch_1;
2343
+ const prerelease = prerelease_1;
2344
+ const compare = compare_1;
2345
+ const rcompare = rcompare_1;
2346
+ const compareLoose = compareLoose_1;
2347
+ const compareBuild = compareBuild_1;
2348
+ const sort = sort_1;
2349
+ const rsort = rsort_1;
2350
+ const gt = gt_1;
2351
+ const lt = lt_1;
2352
+ const eq = eq_1;
2353
+ const neq = neq_1;
2354
+ const gte = gte_1;
2355
+ const lte = lte_1;
2356
+ const cmp = cmp_1;
2357
+ const coerce = coerce_1;
2358
+ const truncate = truncate_1;
2359
+ const Comparator = requireComparator();
2360
+ const Range = requireRange();
2361
+ const satisfies = satisfies_1;
2362
+ const toComparators = toComparators_1;
2363
+ const maxSatisfying = maxSatisfying_1;
2364
+ const minSatisfying = minSatisfying_1;
2365
+ const minVersion = minVersion_1;
2366
+ const validRange = valid$1;
2367
+ const outside = outside_1;
2368
+ const gtr = gtr_1;
2369
+ const ltr = ltr_1;
2370
+ const intersects = intersects_1;
2371
+ const simplifyRange = simplify;
2372
+ const subset = subset_1;
2373
+ var semver = {
2374
+ parse,
2375
+ valid,
2376
+ clean,
2377
+ inc,
2378
+ diff,
2379
+ major,
2380
+ minor,
2381
+ patch,
2382
+ prerelease,
2383
+ compare,
2384
+ rcompare,
2385
+ compareLoose,
2386
+ compareBuild,
2387
+ sort,
2388
+ rsort,
2389
+ gt,
2390
+ lt,
2391
+ eq,
2392
+ neq,
2393
+ gte,
2394
+ lte,
2395
+ cmp,
2396
+ coerce,
2397
+ truncate,
2398
+ Comparator,
2399
+ Range,
2400
+ satisfies,
2401
+ toComparators,
2402
+ maxSatisfying,
2403
+ minSatisfying,
2404
+ minVersion,
2405
+ validRange,
2406
+ outside,
2407
+ gtr,
2408
+ ltr,
2409
+ intersects,
2410
+ simplifyRange,
2411
+ subset,
2412
+ SemVer,
2413
+ re: internalRe.re,
2414
+ src: internalRe.src,
2415
+ tokens: internalRe.t,
2416
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
2417
+ RELEASE_TYPES: constants.RELEASE_TYPES,
2418
+ compareIdentifiers: identifiers.compareIdentifiers,
2419
+ rcompareIdentifiers: identifiers.rcompareIdentifiers,
2420
+ };
2421
+
2422
+ var semver$1 = /*@__PURE__*/getDefaultExportFromCjs(semver);
2423
+
2424
+ function hasKey(obj, keys) {
2425
+ var o = obj;
2426
+ keys.slice(0, -1).forEach(function (key) {
2427
+ o = o[key] || {};
2428
+ });
2429
+
2430
+ var key = keys[keys.length - 1];
2431
+ return key in o;
2432
+ }
2433
+
2434
+ function isNumber(x) {
2435
+ if (typeof x === 'number') { return true; }
2436
+ if ((/^0x[0-9a-f]+$/i).test(x)) { return true; }
2437
+ return (/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/).test(x);
2438
+ }
2439
+
2440
+ function isConstructorOrProto(obj, key) {
2441
+ return (key === 'constructor' && typeof obj[key] === 'function') || key === '__proto__';
2442
+ }
2443
+
2444
+ var minimist = function (args, opts) {
2445
+ if (!opts) { opts = {}; }
2446
+
2447
+ var flags = {
2448
+ bools: {},
2449
+ strings: {},
2450
+ unknownFn: null,
2451
+ };
2452
+
2453
+ if (typeof opts.unknown === 'function') {
2454
+ flags.unknownFn = opts.unknown;
2455
+ }
2456
+
2457
+ if (typeof opts.boolean === 'boolean' && opts.boolean) {
2458
+ flags.allBools = true;
2459
+ } else {
2460
+ [].concat(opts.boolean).filter(Boolean).forEach(function (key) {
2461
+ flags.bools[key] = true;
2462
+ });
2463
+ }
2464
+
2465
+ var aliases = {};
2466
+
2467
+ function aliasIsBoolean(key) {
2468
+ return aliases[key].some(function (x) {
2469
+ return flags.bools[x];
2470
+ });
2471
+ }
2472
+
2473
+ Object.keys(opts.alias || {}).forEach(function (key) {
2474
+ aliases[key] = [].concat(opts.alias[key]);
2475
+ aliases[key].forEach(function (x) {
2476
+ aliases[x] = [key].concat(aliases[key].filter(function (y) {
2477
+ return x !== y;
2478
+ }));
2479
+ });
2480
+ });
2481
+
2482
+ [].concat(opts.string).filter(Boolean).forEach(function (key) {
2483
+ flags.strings[key] = true;
2484
+ if (aliases[key]) {
2485
+ [].concat(aliases[key]).forEach(function (k) {
2486
+ flags.strings[k] = true;
2487
+ });
2488
+ }
2489
+ });
2490
+
2491
+ var defaults = opts.default || {};
2492
+
2493
+ var argv = { _: [] };
2494
+
2495
+ function argDefined(key, arg) {
2496
+ return (flags.allBools && (/^--[^=]+$/).test(arg))
2497
+ || flags.strings[key]
2498
+ || flags.bools[key]
2499
+ || aliases[key];
2500
+ }
2501
+
2502
+ function setKey(obj, keys, value) {
2503
+ var o = obj;
2504
+ for (var i = 0; i < keys.length - 1; i++) {
2505
+ var key = keys[i];
2506
+ if (isConstructorOrProto(o, key)) { return; }
2507
+ if (o[key] === undefined) { o[key] = {}; }
2508
+ if (
2509
+ o[key] === Object.prototype
2510
+ || o[key] === Number.prototype
2511
+ || o[key] === String.prototype
2512
+ ) {
2513
+ o[key] = {};
2514
+ }
2515
+ if (o[key] === Array.prototype) { o[key] = []; }
2516
+ o = o[key];
2517
+ }
2518
+
2519
+ var lastKey = keys[keys.length - 1];
2520
+ if (isConstructorOrProto(o, lastKey)) { return; }
2521
+ if (
2522
+ o === Object.prototype
2523
+ || o === Number.prototype
2524
+ || o === String.prototype
2525
+ ) {
2526
+ o = {};
2527
+ }
2528
+ if (o === Array.prototype) { o = []; }
2529
+ if (o[lastKey] === undefined || flags.bools[lastKey] || typeof o[lastKey] === 'boolean') {
2530
+ o[lastKey] = value;
2531
+ } else if (Array.isArray(o[lastKey])) {
2532
+ o[lastKey].push(value);
2533
+ } else {
2534
+ o[lastKey] = [o[lastKey], value];
2535
+ }
2536
+ }
2537
+
2538
+ function setArg(key, val, arg) {
2539
+ if (arg && flags.unknownFn && !argDefined(key, arg)) {
2540
+ if (flags.unknownFn(arg) === false) { return; }
2541
+ }
2542
+
2543
+ var value = !flags.strings[key] && isNumber(val)
2544
+ ? Number(val)
2545
+ : val;
2546
+ setKey(argv, key.split('.'), value);
2547
+
2548
+ (aliases[key] || []).forEach(function (x) {
2549
+ setKey(argv, x.split('.'), value);
2550
+ });
2551
+ }
2552
+
2553
+ Object.keys(flags.bools).forEach(function (key) {
2554
+ setArg(key, defaults[key] === undefined ? false : defaults[key]);
2555
+ });
2556
+
2557
+ var notFlags = [];
2558
+
2559
+ if (args.indexOf('--') !== -1) {
2560
+ notFlags = args.slice(args.indexOf('--') + 1);
2561
+ args = args.slice(0, args.indexOf('--'));
2562
+ }
2563
+
2564
+ for (var i = 0; i < args.length; i++) {
2565
+ var arg = args[i];
2566
+ var key;
2567
+ var next;
2568
+
2569
+ if ((/^--.+=/).test(arg)) {
2570
+ // Using [\s\S] instead of . because js doesn't support the
2571
+ // 'dotall' regex modifier. See:
2572
+ // http://stackoverflow.com/a/1068308/13216
2573
+ var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
2574
+ key = m[1];
2575
+ var value = m[2];
2576
+ if (flags.bools[key]) {
2577
+ value = value !== 'false';
2578
+ }
2579
+ setArg(key, value, arg);
2580
+ } else if ((/^--no-.+/).test(arg)) {
2581
+ key = arg.match(/^--no-(.+)/)[1];
2582
+ setArg(key, false, arg);
2583
+ } else if ((/^--.+/).test(arg)) {
2584
+ key = arg.match(/^--(.+)/)[1];
2585
+ next = args[i + 1];
2586
+ if (
2587
+ next !== undefined
2588
+ && !(/^(-|--)[^-]/).test(next)
2589
+ && !flags.bools[key]
2590
+ && !flags.allBools
2591
+ && (aliases[key] ? !aliasIsBoolean(key) : true)
2592
+ ) {
2593
+ setArg(key, next, arg);
2594
+ i += 1;
2595
+ } else if ((/^(true|false)$/).test(next)) {
2596
+ setArg(key, next === 'true', arg);
2597
+ i += 1;
2598
+ } else {
2599
+ setArg(key, flags.strings[key] ? '' : true, arg);
2600
+ }
2601
+ } else if ((/^-[^-]+/).test(arg)) {
2602
+ var letters = arg.slice(1, -1).split('');
2603
+
2604
+ var broken = false;
2605
+ for (var j = 0; j < letters.length; j++) {
2606
+ next = arg.slice(j + 2);
2607
+
2608
+ if (next === '-') {
2609
+ setArg(letters[j], next, arg);
2610
+ continue;
2611
+ }
2612
+
2613
+ if ((/[A-Za-z]/).test(letters[j]) && next[0] === '=') {
2614
+ setArg(letters[j], next.slice(1), arg);
2615
+ broken = true;
2616
+ break;
2617
+ }
2618
+
2619
+ if (
2620
+ (/[A-Za-z]/).test(letters[j])
2621
+ && (/-?\d+(\.\d*)?(e-?\d+)?$/).test(next)
2622
+ ) {
2623
+ setArg(letters[j], next, arg);
2624
+ broken = true;
2625
+ break;
2626
+ }
2627
+
2628
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
2629
+ setArg(letters[j], arg.slice(j + 2), arg);
2630
+ broken = true;
2631
+ break;
2632
+ } else {
2633
+ setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
2634
+ }
2635
+ }
2636
+
2637
+ key = arg.slice(-1)[0];
2638
+ if (!broken && key !== '-') {
2639
+ if (
2640
+ args[i + 1]
2641
+ && !(/^(-|--)[^-]/).test(args[i + 1])
2642
+ && !flags.bools[key]
2643
+ && (aliases[key] ? !aliasIsBoolean(key) : true)
2644
+ ) {
2645
+ setArg(key, args[i + 1], arg);
2646
+ i += 1;
2647
+ } else if (args[i + 1] && (/^(true|false)$/).test(args[i + 1])) {
2648
+ setArg(key, args[i + 1] === 'true', arg);
2649
+ i += 1;
2650
+ } else {
2651
+ setArg(key, flags.strings[key] ? '' : true, arg);
2652
+ }
2653
+ }
2654
+ } else {
2655
+ if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
2656
+ argv._.push(flags.strings._ || !isNumber(arg) ? arg : Number(arg));
2657
+ }
2658
+ if (opts.stopEarly) {
2659
+ argv._.push.apply(argv._, args.slice(i + 1));
2660
+ break;
2661
+ }
2662
+ }
2663
+ }
2664
+
2665
+ Object.keys(defaults).forEach(function (k) {
2666
+ if (!hasKey(argv, k.split('.'))) {
2667
+ setKey(argv, k.split('.'), defaults[k]);
2668
+
2669
+ (aliases[k] || []).forEach(function (x) {
2670
+ setKey(argv, x.split('.'), defaults[k]);
2671
+ });
2672
+ }
2673
+ });
2674
+
2675
+ if (opts['--']) {
2676
+ argv['--'] = notFlags.slice();
2677
+ } else {
2678
+ notFlags.forEach(function (k) {
2679
+ argv._.push(k);
2680
+ });
2681
+ }
2682
+
2683
+ return argv;
2684
+ };
2685
+
2686
+ var minimist$1 = /*@__PURE__*/getDefaultExportFromCjs(minimist);
2687
+
2688
+ var name = "@bundlekit/service";
2689
+ var version = "0.0.1";
2690
+ var main = "./dist/index.cjs";
2691
+ var module$1 = "./dist/index.mjs";
2692
+ var cjs = "./dist/index.cjs";
2693
+ var description = "bundlekit-service is a tool for building and running applications using BundleKit plugins.";
2694
+ var bin = {
2695
+ ds: "./dist/index.mjs",
2696
+ "bundlekit-service": "./dist/index.cjs"
2697
+ };
2698
+ var exports$1 = {
2699
+ ".": {
2700
+ "import": "./dist/index.mjs",
2701
+ require: "./dist/index.cjs",
2702
+ "default": "./dist/index.cjs"
2703
+ }
2704
+ };
2705
+ var files = [
2706
+ "dist",
2707
+ "package.json",
2708
+ "README.md"
2709
+ ];
2710
+ var scripts = {
2711
+ clean: "rimraf -rf ./dist",
2712
+ debug: "tsx ./index.ts serve --bundler webpack --mode production",
2713
+ "service:build": "pnpm run clean && rollup -c ./scripts/rollup.config.js"
2714
+ };
2715
+ var dependencies = {
2716
+ "@bundlekit/shared-utils": "workspace:*",
2717
+ jiti: "^2.4.2",
2718
+ minimist: "^1.2.8",
2719
+ semver: "^7.7.1"
2720
+ };
2721
+ var peerDependencies = {
2722
+ "@bundlekit/bundler-webpack": "workspace:*",
2723
+ "@bundlekit/bundler-vite": "workspace:*",
2724
+ "@bundlekit/bundler-rspack": "workspace:*",
2725
+ "@bundlekit/bundler-rollup": "workspace:*",
2726
+ "@bundlekit/bundler-rolldown": "workspace:*"
2727
+ };
2728
+ var peerDependenciesMeta = {
2729
+ "@bundlekit/bundler-webpack": {
2730
+ optional: true
2731
+ },
2732
+ "@bundlekit/bundler-vite": {
2733
+ optional: true
2734
+ },
2735
+ "@bundlekit/bundler-rspack": {
2736
+ optional: true
2737
+ },
2738
+ "@bundlekit/bundler-rollup": {
2739
+ optional: true
2740
+ },
2741
+ "@bundlekit/bundler-rolldown": {
2742
+ optional: true
2743
+ }
2744
+ };
2745
+ var devDependencies = {
2746
+ "@rollup/plugin-commonjs": "^25.0.7",
2747
+ "@rollup/plugin-json": "^6.1.0",
2748
+ "@rollup/plugin-node-resolve": "^15.2.3",
2749
+ "@rollup/plugin-terser": "^0.4.4",
2750
+ "@rollup/plugin-typescript": "^11.1.6",
2751
+ "@types/minimist": "^1.2.5",
2752
+ "@types/semver": "^7.7.0",
2753
+ rimraf: "^5.0.1",
2754
+ rollup: "^4.13.0",
2755
+ tslib: "^2.6.2",
2756
+ tsx: "^4.19.2",
2757
+ typescript: "^5.8.2"
2758
+ };
2759
+ var keywords = [
2760
+ "bundlekit-service",
2761
+ "ds"
2762
+ ];
2763
+ var author = "harhao@163.com";
2764
+ var license = "ISC";
2765
+ var publishConfig = {
2766
+ registry: "https://registry.npmjs.org/",
2767
+ access: "public"
2768
+ };
2769
+ var engines = {
2770
+ node: ">= 18.0.0"
2771
+ };
2772
+ var pkg = {
2773
+ name: name,
2774
+ version: version,
2775
+ main: main,
2776
+ module: module$1,
2777
+ cjs: cjs,
2778
+ description: description,
2779
+ bin: bin,
2780
+ exports: exports$1,
2781
+ files: files,
2782
+ scripts: scripts,
2783
+ dependencies: dependencies,
2784
+ peerDependencies: peerDependencies,
2785
+ peerDependenciesMeta: peerDependenciesMeta,
2786
+ devDependencies: devDependencies,
2787
+ keywords: keywords,
2788
+ author: author,
2789
+ license: license,
2790
+ publishConfig: publishConfig,
2791
+ engines: engines
2792
+ };
2793
+
2794
+ class PluginAPI {
2795
+ // 插件构造函数
2796
+ constructor(config) {
2797
+ this.id = null; // 插件id名称
2798
+ this.service = null; // 主流程service实例
2799
+ const { id, service } = config;
2800
+ this.id = id;
2801
+ this.service = service;
2802
+ }
2803
+ // 获取插件名称
2804
+ get pluginName() {
2805
+ return this.id;
2806
+ }
2807
+ // 获取cli版本
2808
+ get version() {
2809
+ return pkg.version;
2810
+ }
2811
+ // 获取当前运行路径地址
2812
+ getCwd() {
2813
+ return this.service.context;
2814
+ }
2815
+ /**
2816
+ * 注册命令
2817
+ * @param command 命令名称
2818
+ * @param args 命令参数 args = { _: ['serve'| 'build'], open: true, port: 880};
2819
+ * @param rawArgs 原始命令参数 rawArgv = ['serve', '--open', '--port', '8080']
2820
+ */
2821
+ registerCommand(command, opts, fn) {
2822
+ if (typeof opts === 'function') {
2823
+ fn = opts;
2824
+ opts = null;
2825
+ }
2826
+ this.service.commands[command] = { fn, opts: (opts || {}) };
2827
+ }
2828
+ /**
2829
+ * 添加构建工具包
2830
+ * @param packageName 包名称
2831
+ */
2832
+ async addBuildPackage(packageName) {
2833
+ await this.service.packageManager.add(packageName, {
2834
+ noSave: true,
2835
+ });
2836
+ }
2837
+ /**
2838
+ * 修改构建配置
2839
+ * @param config 构建配置
2840
+ */
2841
+ modifyBuildConfig(config) {
2842
+ this.service.setBuildConfig(config);
2843
+ }
2844
+ }
2845
+
2846
+ const getDefaultConfig = (context) => ({
2847
+ mode: "development",
2848
+ bundler: "webpack",
2849
+ plugins: [],
2850
+ changeConfigure: (config) => config,
2851
+ config: {
2852
+ development: {
2853
+ target: "web",
2854
+ publicPath: "/",
2855
+ entry: "src/index",
2856
+ output: { dir: "dist", filename: "[name].js", formats: "umd" },
2857
+ alias: { "@": "src" },
2858
+ externals: [],
2859
+ js: { sourcemap: true, minify: false, splitChunks: false },
2860
+ devServer: { open: false, proxy: {}, https: false, host: "0.0.0.0", port: 3000 },
2861
+ },
2862
+ production: {
2863
+ target: "web",
2864
+ publicPath: "/",
2865
+ entry: "src/index",
2866
+ output: { dir: "dist", filename: "[name].js", formats: "umd" },
2867
+ alias: { "@": "src" },
2868
+ externals: [],
2869
+ js: { sourcemap: false, minify: true, splitChunks: true },
2870
+ devServer: { open: false, proxy: {}, https: false, host: "0.0.0.0", port: 3000 },
2871
+ },
2872
+ },
2873
+ });
2874
+
2875
+ class ConfigLoader {
2876
+ constructor(context, mode) {
2877
+ this.mode = mode;
2878
+ this.context = context || process.cwd();
2879
+ this.fileManager = new sharedUtils.FileManager(context || process.cwd());
2880
+ }
2881
+ loadDevkitFileConfig() {
2882
+ const tsConfigPath = path__default.default.resolve(this.context, ".bundlekitrc.ts");
2883
+ const jsConfigPath = path__default.default.resolve(this.context, ".bundlekitrc.js");
2884
+ const configPath = this.fileManager.isFilePathExist(tsConfigPath)
2885
+ ? tsConfigPath
2886
+ : this.fileManager.isFilePathExist(jsConfigPath)
2887
+ ? jsConfigPath
2888
+ : null;
2889
+ if (!configPath) {
2890
+ throw new Error(`未找到配置文件 .bundlekitrc.ts 或 .bundlekitrc.js,请在项目根目录 ${this.context} 下创建配置文件`);
2891
+ }
2892
+ const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)), {
2893
+ alias: { "@": path__default.default.resolve(this.context, "src") },
2894
+ });
2895
+ const userConfig = jiti$1(configPath);
2896
+ return (userConfig.default || userConfig);
2897
+ }
2898
+ deepMerge(defaults, overrides) {
2899
+ const result = { ...defaults };
2900
+ for (const key of Object.keys(overrides)) {
2901
+ const overrideVal = overrides[key];
2902
+ const defaultVal = defaults[key];
2903
+ if (overrideVal &&
2904
+ typeof overrideVal === "object" &&
2905
+ !Array.isArray(overrideVal) &&
2906
+ defaultVal &&
2907
+ typeof defaultVal === "object" &&
2908
+ !Array.isArray(defaultVal)) {
2909
+ result[key] = this.deepMerge(defaultVal, overrideVal);
2910
+ }
2911
+ else {
2912
+ result[key] = overrideVal;
2913
+ }
2914
+ }
2915
+ return result;
2916
+ }
2917
+ resolvePaths(config) {
2918
+ const resolveDir = (dir) => path__default.default.isAbsolute(dir) ? dir : path__default.default.resolve(this.context, dir);
2919
+ const resolved = { ...config, config: { ...config.config } };
2920
+ for (const env of Object.keys(resolved.config || {})) {
2921
+ const envConfig = { ...resolved.config[env] };
2922
+ if (envConfig.entry) {
2923
+ if (typeof envConfig.entry === "string") {
2924
+ envConfig.entry = resolveDir(envConfig.entry);
2925
+ }
2926
+ else if (Array.isArray(envConfig.entry)) {
2927
+ envConfig.entry = envConfig.entry.map(resolveDir);
2928
+ }
2929
+ else if (typeof envConfig.entry === "object") {
2930
+ const resolved = {};
2931
+ for (const [key, val] of Object.entries(envConfig.entry)) {
2932
+ resolved[key] = resolveDir(val);
2933
+ }
2934
+ envConfig.entry = resolved;
2935
+ }
2936
+ }
2937
+ if (envConfig.output) {
2938
+ const output = Array.isArray(envConfig.output) ? envConfig.output : [envConfig.output];
2939
+ const resolvedOutputs = output.map((o) => ({
2940
+ ...o,
2941
+ dir: resolveDir(o.dir),
2942
+ }));
2943
+ envConfig.output = Array.isArray(envConfig.output) ? resolvedOutputs : resolvedOutputs[0];
2944
+ }
2945
+ if (envConfig.alias) {
2946
+ const resolvedAlias = {};
2947
+ for (const [key, val] of Object.entries(envConfig.alias)) {
2948
+ resolvedAlias[key] = resolveDir(String(val));
2949
+ }
2950
+ envConfig.alias = resolvedAlias;
2951
+ }
2952
+ resolved.config[env] = envConfig;
2953
+ }
2954
+ return resolved;
2955
+ }
2956
+ async resolveAllConfig() {
2957
+ const defaultConfig = getDefaultConfig(this.context);
2958
+ const userConfig = this.loadDevkitFileConfig();
2959
+ const merged = this.deepMerge(defaultConfig, userConfig);
2960
+ return this.resolvePaths(merged);
2961
+ }
2962
+ }
2963
+
2964
+ /**
2965
+ * 在 transformConfig 完成后、changeConfigure 之前调用 tools[bundler]?(config, ctx)
2966
+ *
2967
+ * 返回值约定:
2968
+ * - hook 返回 undefined / void → 用 mutate 后的 rawConfig
2969
+ * - hook 返回新对象 → 用新对象替换
2970
+ *
2971
+ * hook 抛错 / Promise reject 时不吞掉,由调用方上层 try/catch 处理。
2972
+ */
2973
+ async function applyTools(buildConfig, bundlerName, rawConfig, ctx) {
2974
+ if (!buildConfig?.tools)
2975
+ return rawConfig;
2976
+ const hook = buildConfig.tools[bundlerName];
2977
+ if (typeof hook !== "function")
2978
+ return rawConfig;
2979
+ const result = await hook(rawConfig, ctx);
2980
+ return result === undefined ? rawConfig : result;
2981
+ }
2982
+
2983
+ /**
2984
+ * 简易 connect 风格 middleware 链运行器。
2985
+ *
2986
+ * 不引入 connect 依赖:service 通过 http.createServer 起服务,把 adapter 返回的
2987
+ * middleware 数组按顺序调用;任意 middleware 调 next(err) 触发错误兜底,调 next()
2988
+ * 不带参数则进入下一项;无 next 调用则视作终止响应(已写 res.end)。
2989
+ */
2990
+ function runMiddlewares(req, res, mws) {
2991
+ return new Promise((resolve, reject) => {
2992
+ let i = 0;
2993
+ const next = (err) => {
2994
+ if (err)
2995
+ return reject(err);
2996
+ if (i >= mws.length)
2997
+ return resolve();
2998
+ const mw = mws[i++];
2999
+ try {
3000
+ const r = mw(req, res, next);
3001
+ if (r && typeof r.then === "function") {
3002
+ r.then(undefined, reject);
3003
+ }
3004
+ }
3005
+ catch (e) {
3006
+ reject(e);
3007
+ }
3008
+ };
3009
+ next();
3010
+ });
3011
+ }
3012
+ /**
3013
+ * 启动 dev SSR HTTP server:把 adapter 的 middleware 链串到 http.createServer 上。
3014
+ *
3015
+ * 错误语义:
3016
+ * - middleware 抛错 → 返回 500 + stack overlay(dev 友好),生产不应启用 dev SSR
3017
+ * - 服务器自身 EADDRINUSE / 其他启动错 → reject promise
3018
+ */
3019
+ async function startSSRDevServer(opts) {
3020
+ const mws = Array.isArray(opts.middleware)
3021
+ ? opts.middleware
3022
+ : [opts.middleware];
3023
+ const server = http__default.default.createServer((req, res) => {
3024
+ runMiddlewares(req, res, mws).catch((err) => {
3025
+ opts.onError?.(err);
3026
+ if (!res.headersSent) {
3027
+ res.statusCode = 500;
3028
+ res.setHeader("Content-Type", "text/html; charset=utf-8");
3029
+ }
3030
+ const safeStack = String(err?.stack || err?.message || err)
3031
+ .replace(/&/g, "&amp;")
3032
+ .replace(/</g, "&lt;");
3033
+ res.end(`<pre>${safeStack}</pre>`);
3034
+ });
3035
+ });
3036
+ return new Promise((resolve, reject) => {
3037
+ server.once("error", reject);
3038
+ server.listen(opts.port, opts.host, () => {
3039
+ const addr = server.address();
3040
+ const port = typeof addr === "object" && addr ? addr.port : opts.port;
3041
+ server.removeListener("error", reject);
3042
+ resolve({
3043
+ port,
3044
+ close: () => new Promise((res2) => {
3045
+ server.close(() => res2());
3046
+ }),
3047
+ });
3048
+ });
3049
+ });
3050
+ }
3051
+ /**
3052
+ * 从 buildConfig 中读取 envConfig(按 mode)的 devServer.host/port,回退到默认值
3053
+ */
3054
+ function resolveDevServerBinding(buildConfig, mode) {
3055
+ const envConfig = buildConfig.config?.[mode];
3056
+ const host = envConfig?.devServer?.host || "0.0.0.0";
3057
+ const port = typeof envConfig?.devServer?.port === "number"
3058
+ ? envConfig.devServer.port
3059
+ : 3000;
3060
+ return { host, port };
3061
+ }
3062
+
3063
+ class Service {
3064
+ constructor(context) {
3065
+ // 是否初始化
3066
+ this.isInitial = false;
3067
+ // 打包工具环境
3068
+ this.mode = "development";
3069
+ // 当前执行的命令名(serve / build / ...)
3070
+ this.currentCommand = null;
3071
+ // 执行命令的目录
3072
+ this.context = null;
3073
+ // 注册的命令集合
3074
+ this.commands = {};
3075
+ // 注册的插件集合
3076
+ this.plugins = [];
3077
+ // 各插件运行环境集合
3078
+ this.modes = {};
3079
+ // 日志打印
3080
+ this.logger = new sharedUtils.Logger();
3081
+ // 需要跳过的插件列表
3082
+ this.skipPlugins = null;
3083
+ // 传递进来的config配置
3084
+ this.configLoader = null;
3085
+ // 打包工具配置
3086
+ this.buildConfig = null;
3087
+ this.context = context || process.cwd();
3088
+ this.fileManager = new sharedUtils.FileManager(this.context);
3089
+ this.packageManager = new sharedUtils.PackageManager({
3090
+ context: this.context
3091
+ });
3092
+ }
3093
+ /**
3094
+ * 获取构建配置
3095
+ * @returns 构建配置
3096
+ */
3097
+ getBuildConfig() {
3098
+ return this.buildConfig;
3099
+ }
3100
+ /**
3101
+ * 设置构建配置
3102
+ * @param config 构建配置
3103
+ */
3104
+ setBuildConfig(config) {
3105
+ if (!config) {
3106
+ return;
3107
+ }
3108
+ this.buildConfig = config;
3109
+ }
3110
+ // 获取内置插件列表
3111
+ async resolvePlugins() {
3112
+ const sortedPlugins = [];
3113
+ const builtInPlugins = [
3114
+ await Promise.resolve().then(function () { return require('./chunks/build-DksjZoFJ.cjs'); }).then(m => m.default),
3115
+ await Promise.resolve().then(function () { return require('./chunks/serve-C1wcFsjj.cjs'); }).then(m => m.default),
3116
+ await Promise.resolve().then(function () { return require('./chunks/help-CqnZdJwq.cjs'); }).then(m => m.default)
3117
+ ];
3118
+ for (let plugin of builtInPlugins) {
3119
+ const { defaultModes, apply } = plugin;
3120
+ sortedPlugins.push({
3121
+ id: `built-in:${plugin.defaultModes ? Object.keys(plugin.defaultModes)[0] : 'unknown'}`,
3122
+ apply: apply,
3123
+ defaultModes,
3124
+ });
3125
+ }
3126
+ return sortedPlugins;
3127
+ }
3128
+ // 获取用户配置的插件列表(需在 buildConfig 加载后调用)
3129
+ async resolveUserPlugins() {
3130
+ const userPlugins = [];
3131
+ if (this.buildConfig?.plugins && Array.isArray(this.buildConfig.plugins)) {
3132
+ for (const pluginName of this.buildConfig.plugins) {
3133
+ try {
3134
+ const require$1 = module$2.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
3135
+ const pluginPath = require$1.resolve(pluginName, {
3136
+ paths: [path__default.default.join(this.context, "node_modules")]
3137
+ });
3138
+ // 使用 jiti 加载,支持 .ts 源文件形式的插件包
3139
+ const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
3140
+ const pluginModule = jiti$1(pluginPath);
3141
+ const resolved = pluginModule?.default || pluginModule;
3142
+ if (resolved?.apply) {
3143
+ userPlugins.push({
3144
+ id: `project:${pluginName}`,
3145
+ apply: resolved.apply,
3146
+ defaultModes: resolved.defaultModes || {},
3147
+ });
3148
+ }
3149
+ }
3150
+ catch (e) {
3151
+ this.logger.warn(`无法加载插件: ${pluginName}`, "插件管理");
3152
+ }
3153
+ }
3154
+ }
3155
+ return userPlugins;
3156
+ }
3157
+ /**
3158
+ * 初始化服务所有的配置
3159
+ * @param mode IBuildEnv 构建模式
3160
+ * @param args Record<string, unknown> 额外的参数
3161
+ */
3162
+ async init(mode, args) {
3163
+ this.configLoader = new ConfigLoader(this.context, mode);
3164
+ // 要重新定义projectOptions类型
3165
+ const buildConfig = await this.configLoader.resolveAllConfig();
3166
+ // 设置构建配置
3167
+ this.setBuildConfig({ ...buildConfig, ...(args.bundler ? { bundler: args.bundler } : {}) });
3168
+ // buildConfig 加载完成后,追加用户配置的插件
3169
+ const userPlugins = await this.resolveUserPlugins();
3170
+ this.plugins = [...this.plugins, ...userPlugins];
3171
+ for (let plugin of this.plugins) {
3172
+ // 如果不是需要跳过的插件, 则执行apply函数
3173
+ if (!this.skipPlugins?.has(plugin.id)) {
3174
+ const { id, apply } = plugin;
3175
+ const api = new PluginAPI({ id: id, service: this });
3176
+ apply(api, this.getBuildConfig());
3177
+ }
3178
+ }
3179
+ }
3180
+ /**
3181
+ * 收集需要跳过的插件
3182
+ * @param args 格式化参数
3183
+ * @param rawArgv 字符串参数
3184
+ */
3185
+ setPluginsToSkip(args, rawArgv) {
3186
+ if (!this.skipPlugins) {
3187
+ this.skipPlugins = new Set();
3188
+ }
3189
+ const skipArg = (args["skip-plugin"] || args.skipPlugin || args["skip-plugins"]);
3190
+ if (skipArg) {
3191
+ const pluginNames = skipArg.split(",").map((s) => s.trim()).filter(Boolean);
3192
+ for (const name of pluginNames) {
3193
+ this.skipPlugins.add(name);
3194
+ }
3195
+ this.logger.log(`跳过插件: ${Array.from(this.skipPlugins).join(", ")}`, "插件管理");
3196
+ }
3197
+ }
3198
+ /**
3199
+ * 处理打包工具的原生配置(暴露出去的配置)
3200
+ * @param config 打包工具的配置(针对具体的bundler配置, 所以这里config的类型是Record<string, unknown>)
3201
+ * @returns Recodr<string, unknown>
3202
+ */
3203
+ async configureConfig(config) {
3204
+ if (!this.buildConfig?.changeConfigure) {
3205
+ return config;
3206
+ }
3207
+ const result = this.buildConfig.changeConfigure(config, this.mode);
3208
+ return result instanceof Promise ? await result : result;
3209
+ }
3210
+ /**
3211
+ * 加载打包工具插件
3212
+ * @param packageName 打包工具插件的packageName
3213
+ * @returns 打包工具插件
3214
+ */
3215
+ async loadBundlerPlugin(packageName) {
3216
+ try {
3217
+ const require$1 = module$2.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
3218
+ let bundlerModule;
3219
+ try {
3220
+ // 显式指定查找路径,优先当前 context 的 node_modules
3221
+ const packagePath = require$1.resolve(packageName, {
3222
+ paths: [
3223
+ path__default.default.join(this.context, "node_modules"),
3224
+ path__default.default.join(process.cwd(), "node_modules")
3225
+ ]
3226
+ });
3227
+ bundlerModule = require$1(packagePath);
3228
+ bundlerModule = bundlerModule.default || bundlerModule;
3229
+ }
3230
+ catch (e) {
3231
+ // fallback: 动态 import
3232
+ bundlerModule = await (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(packageName);
3233
+ bundlerModule = bundlerModule.default || bundlerModule;
3234
+ }
3235
+ return bundlerModule;
3236
+ }
3237
+ catch (error) {
3238
+ this.logger.error(`无法加载打包工具插件: ${packageName}`, "构建工具");
3239
+ return null;
3240
+ }
3241
+ }
3242
+ /**
3243
+ * 获取打包工具注册表(bundler 名称 → 适配器包名)
3244
+ * @returns IBuildTools
3245
+ */
3246
+ getBundlerRegistry() {
3247
+ return { ...sharedUtils.BUNDLER_PACKAGE_MAP };
3248
+ }
3249
+ /**
3250
+ * bundler 缺失时按策略矩阵决定:
3251
+ * - TTY 且未设 DEVKIT_NO_PROMPT → 弹 yes/no 询问
3252
+ * - 非 TTY 且 DEVKIT_AUTO_INSTALL=1 → 直接装入 devDeps
3253
+ * - 其他情况 → 报错引导,返回 false
3254
+ */
3255
+ async resolveBundlerOrPrompt(packageName) {
3256
+ const isTTY = !!process.stdout.isTTY && !!process.stdin.isTTY;
3257
+ const noPrompt = process.env.DEVKIT_NO_PROMPT === "1";
3258
+ const autoInstall = process.env.DEVKIT_AUTO_INSTALL === "1";
3259
+ let shouldInstall = false;
3260
+ if (isTTY && !noPrompt) {
3261
+ shouldInstall = await sharedUtils.confirm({
3262
+ message: `未安装 ${packageName},是否现在安装?`,
3263
+ default: true,
3264
+ });
3265
+ }
3266
+ else if (autoInstall) {
3267
+ this.logger.log(`检测到 DEVKIT_AUTO_INSTALL=1,自动安装 ${packageName}`, "构建工具");
3268
+ shouldInstall = true;
3269
+ }
3270
+ else {
3271
+ shouldInstall = false;
3272
+ }
3273
+ if (!shouldInstall) {
3274
+ const shortName = packageName.replace(/^@bundlekit\/bundler-/, "");
3275
+ this.logger.error(`未安装 ${packageName}。请先运行:\n bundlekit-cli add bundler-${shortName}\n` +
3276
+ `或在 CI 中设置环境变量 DEVKIT_AUTO_INSTALL=1`, "构建工具");
3277
+ return false;
3278
+ }
3279
+ if (!this.packageManager) {
3280
+ this.logger.error("packageManager is not initialized");
3281
+ return false;
3282
+ }
3283
+ const installed = await this.packageManager.add(packageName, { dev: true });
3284
+ if (!installed) {
3285
+ this.logger.error(`安装 ${packageName} 失败`, "构建工具");
3286
+ return false;
3287
+ }
3288
+ this.logger.done(`已安装 ${packageName} 至 devDependencies`, "构建工具");
3289
+ return true;
3290
+ }
3291
+ /**
3292
+ * 单次 pass 的执行流:transformConfig → tools → changeConfigure → run
3293
+ */
3294
+ async runSinglePass(bundlerPlugin, passConfig, bundlerName, env) {
3295
+ const builder = new bundlerPlugin(this, this.mode);
3296
+ // server pass 的 ctx.env 切换为 'server',给 tools hook 区分
3297
+ const toolsCtx = {
3298
+ mode: this.mode,
3299
+ command: (this.currentCommand === "build" ? "build" : "serve"),
3300
+ env,
3301
+ bundler: bundlerName,
3302
+ };
3303
+ const builderConifg = await builder.transformConfig(passConfig);
3304
+ const afterTools = await applyTools(passConfig, bundlerName, builderConifg, toolsCtx);
3305
+ const finalConfig = await this.configureConfig(afterTools);
3306
+ await builder.run(finalConfig);
3307
+ }
3308
+ /**
3309
+ * 获取指定的bundler打包工具, 开始执行打包任务
3310
+ * @param bundler 打包工具名称 vite/webpack/rollup/rspack/rolldown
3311
+ */
3312
+ async startBuilder() {
3313
+ const bundlerList = this.getBundlerRegistry();
3314
+ const finalBundler = this.buildConfig?.bundler || "vite";
3315
+ const packageName = bundlerList[finalBundler];
3316
+ let isInstallBundler = !!(await this.loadBundlerPlugin(packageName));
3317
+ // 如果打包工具不在默认列表中,则按策略矩阵决定是否安装并写入 devDependencies
3318
+ if (!isInstallBundler) {
3319
+ const installed = await this.resolveBundlerOrPrompt(packageName);
3320
+ if (!installed) {
3321
+ process.exit(1);
3322
+ }
3323
+ isInstallBundler = !!(await this.loadBundlerPlugin(packageName));
3324
+ if (!isInstallBundler) {
3325
+ this.logger.error(`安装后仍无法加载 ${packageName},请检查 node_modules`, "构建工具");
3326
+ process.exit(1);
3327
+ }
3328
+ }
3329
+ if (!isInstallBundler)
3330
+ return;
3331
+ this.logger.log(`使用的构建:${finalBundler}`, "构建工具");
3332
+ const bundlerPlugin = await this.loadBundlerPlugin(packageName);
3333
+ // 检测是否启用 SSR:当前 envConfig 上有 ssr 字段
3334
+ const envConfig = this.buildConfig?.config?.[this.mode];
3335
+ const ssrEnabled = !!envConfig?.ssr;
3336
+ if (!ssrEnabled) {
3337
+ // 普通单 pass 流(保持向后兼容)
3338
+ await this.runSinglePass(bundlerPlugin, this.buildConfig, finalBundler, "client");
3339
+ return;
3340
+ }
3341
+ // dev SSR 路径:service 起 HTTP server,adapter 提供 middleware 链
3342
+ // 当且仅当 (currentCommand === 'serve') 且 envConfig.ssr.dev !== false 时启用 dev SSR
3343
+ const ssrDev = !!envConfig?.ssr?.dev;
3344
+ if (this.currentCommand === "serve" && ssrDev) {
3345
+ const builder = new bundlerPlugin(this, this.mode);
3346
+ if (typeof builder.createSSRMiddleware !== "function") {
3347
+ this.logger.error(`bundler "${finalBundler}" 未实现 createSSRMiddleware,无法启动 dev SSR`, "构建工具");
3348
+ process.exit(1);
3349
+ }
3350
+ try {
3351
+ const middleware = await builder.createSSRMiddleware(this.buildConfig, {
3352
+ env: "client",
3353
+ isProduction: false,
3354
+ });
3355
+ const { host, port } = resolveDevServerBinding(this.buildConfig, this.mode);
3356
+ const handle = await startSSRDevServer({
3357
+ middleware,
3358
+ host,
3359
+ port,
3360
+ onError: (err) => {
3361
+ this.logger.error(`SSR middleware 异常: ${err?.message ?? err}`, "构建工具");
3362
+ },
3363
+ });
3364
+ this.logger.done(`SSR dev server 就绪:http://${host === "0.0.0.0" ? "localhost" : host}:${handle.port}`, "构建工具");
3365
+ }
3366
+ catch (err) {
3367
+ this.logger.error(`启动 SSR dev server 失败: ${err?.message ?? err}`, "构建工具");
3368
+ process.exit(1);
3369
+ }
3370
+ return;
3371
+ }
3372
+ // build SSR 双 pass:先 client,再 server
3373
+ this.logger.log(`SSR 模式启用:将依次执行 client + server 两次构建`, "构建工具");
3374
+ // Pass 1: client
3375
+ await this.runSinglePass(bundlerPlugin, this.buildConfig, finalBundler, "client");
3376
+ // Pass 2: server(用 buildSSRView 切换 entry / output / target)
3377
+ const serverBuildConfig = sharedUtils.buildSSRView(this.buildConfig, this.mode);
3378
+ await this.runSinglePass(bundlerPlugin, serverBuildConfig, finalBundler, "server");
3379
+ this.logger.done(`SSR 双产物构建完成`, "构建工具");
3380
+ }
3381
+ /**
3382
+ * service 开始运行函数
3383
+ * @param command 执行的命令 build/serve/help 等等
3384
+ * @param args args = { _: ['serve'| 'build'], open: true, port: 880};
3385
+ * @param rawArgv 原始命令参数 rawArgv = ['serve', '--open', '--port', '8080']
3386
+ */
3387
+ async run(command, args, rawArgv = []) {
3388
+ if (this.isInitial) {
3389
+ return;
3390
+ }
3391
+ this.isInitial = true;
3392
+ this.currentCommand = command;
3393
+ // 解析项目内插件和内置插件处理
3394
+ this.plugins = await this.resolvePlugins();
3395
+ // 收集各插件依赖支持的环境
3396
+ this.modes = this.plugins.reduce((modes, plugin) => {
3397
+ if (plugin?.defaultModes) {
3398
+ return { ...modes, ...plugin.defaultModes };
3399
+ }
3400
+ return modes;
3401
+ }, {});
3402
+ // 当前的环境
3403
+ this.mode = (typeof args.mode === 'string'
3404
+ ? args.mode
3405
+ : command === 'build' && args.watch
3406
+ ? 'development'
3407
+ : this.modes[command]);
3408
+ // 需要跳过的插件
3409
+ this.setPluginsToSkip(args, rawArgv);
3410
+ args._ = args._ || [];
3411
+ // 初始化操作
3412
+ await this.init(this.mode, args);
3413
+ let runCommand = this.commands[command];
3414
+ if (!runCommand && command) {
3415
+ this.logger.error(`command ${command} is not defined in bundlekit-service`);
3416
+ process.exit(1);
3417
+ }
3418
+ if (!command || args.help || args.h) {
3419
+ runCommand = this.commands["help"];
3420
+ }
3421
+ else {
3422
+ args._.shift();
3423
+ rawArgv.shift();
3424
+ }
3425
+ const { fn } = runCommand;
3426
+ fn(args, rawArgv);
3427
+ }
3428
+ }
3429
+
3430
+ async function startBuildService() {
3431
+ const logger = new sharedUtils.Logger();
3432
+ try {
3433
+ // 检查node版本
3434
+ let requireNodeVersion = pkg.engines.node;
3435
+ if (!semver$1.satisfies(process.version, requireNodeVersion, { includePrerelease: true })) {
3436
+ //增加打印错误信息
3437
+ logger.error(`Required node version ${requireNodeVersion}, but got ${process.version}.\nPlease upgrade your node.`);
3438
+ process.exit(1);
3439
+ }
3440
+ const service = new Service();
3441
+ const rawArgv = process.argv.slice(2);
3442
+ const args = minimist$1(rawArgv, {
3443
+ // TODO 这里可以增加更多的参数转成布尔值
3444
+ boolean: [
3445
+ "open",
3446
+ ]
3447
+ });
3448
+ const command = args._[0];
3449
+ // 在服务启动前注册进程信号处理,确保启动过程中也能优雅退出
3450
+ process.on('SIGINT', () => {
3451
+ logger.info('接收到 SIGINT 信号,正在优雅关闭服务...');
3452
+ process.exit(0);
3453
+ });
3454
+ process.on('SIGTERM', () => {
3455
+ logger.info('接收到 SIGTERM 信号,正在优雅关闭服务...');
3456
+ process.exit(0);
3457
+ });
3458
+ await service.run(command, args, rawArgv);
3459
+ }
3460
+ catch (error) {
3461
+ // 增加打印错误信息
3462
+ logger.error(error);
3463
+ process.exit(1);
3464
+ }
3465
+ }
3466
+ startBuildService();
3467
+
3468
+ exports.getDefaultConfig = getDefaultConfig;