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