web-extend-plugin-vue2 0.1.4 → 0.2.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,4020 @@
1
+ import Vue from 'vue';
2
+
3
+ /**
4
+ * 宿主可覆盖的默认运行时配置(路径、白名单、超时等)。
5
+ * 使用方式:`resolveRuntimeOptions({ ...defaultWebExtendPluginRuntime, manifestListPath: '/api/my-plugins' })`
6
+ * 或只传需要改动的字段:`resolveRuntimeOptions({ manifestListPath: '/api/my-plugins' })`。
7
+ *
8
+ * @module default-runtime-config
9
+ */
10
+
11
+ /**
12
+ * @typedef {typeof defaultWebExtendPluginRuntime} WebExtendPluginDefaultRuntime
13
+ */
14
+
15
+ const defaultWebExtendPluginRuntime = {
16
+ /** 清单 HTTP 服务前缀(与后端 context-path 对齐),不含尾部 `/` */
17
+ manifestBase: '/fp-api',
18
+
19
+ /**
20
+ * 拉取插件清单的 **路径段**(以 `/` 开头),拼在 `manifestBase` 之后。
21
+ * 完整 URL:`{manifestBase}{manifestListPath}` → 默认 `/fp-api/api/frontend-plugins`
22
+ */
23
+ manifestListPath: '/api/frontend-plugins',
24
+
25
+ /** 清单 `fetch` 的 `credentials`,需 Cookie 会话时用 `include` */
26
+ manifestFetchCredentials: 'include',
27
+
28
+ /** 插件 dev 服务存活探测路径(拼在 `webPluginDevOrigin` 后) */
29
+ devPingPath: '/__web_plugin_dev_ping',
30
+
31
+ /** 插件 dev 热更新 SSE 路径(拼在插件 dev 的 origin 后) */
32
+ devReloadSsePath: '/__web_plugin_reload_stream',
33
+
34
+ /** 隐式 dev 映射里,每个 id 对应的入口路径(相对插件 dev origin) */
35
+ webPluginDevEntryPath: '/src/plugin-entry.js',
36
+
37
+ /** `fetch(devPingUrl)` 超时毫秒数 */
38
+ devPingTimeoutMs: 500,
39
+
40
+ /**
41
+ * **隐式 dev 映射**(可选):开发模式下若 `webPluginDevOrigin` 上 ping 成功,运行时会为若干插件 id 自动生成
42
+ * `{ id → origin + webPluginDevEntryPath }`,从而用 dev 服务入口替代清单里的 dist,便于热更新联调。
43
+ *
44
+ * 插件 id 来源优先级:`webPluginDevIds`(或 `VITE_WEB_PLUGIN_DEV_IDS`)→ 本字段。**默认 `[]`**,
45
+ * 避免把仓库示例 id 写进通用宿主;联调时在 `.env` 里设 `VITE_WEB_PLUGIN_DEV_IDS=com.xxx,com.yyy`,
46
+ * 或 `resolveRuntimeOptions({ defaultImplicitDevPluginIds: ['com.xxx'] })` 即可。
47
+ */
48
+ defaultImplicitDevPluginIds: [],
49
+
50
+ /**
51
+ * 允许通过 `<script>` / 动态 `import()` 加载的插件脚本所在主机名(小写),防误配公网 URL。
52
+ */
53
+ allowedScriptHosts: ['localhost', '127.0.0.1', '::1'],
54
+
55
+ /**
56
+ * `hostApi.getBridge().request(path)` 允许的 path 前缀;须以 `/` 开头。
57
+ * 需与后端实际 API 前缀一致。
58
+ */
59
+ bridgeAllowedPathPrefixes: ['/api/']
60
+ };
61
+
62
+ function getDefaultExportFromCjs (x) {
63
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
64
+ }
65
+
66
+ var re = {exports: {}};
67
+
68
+ var constants;
69
+ var hasRequiredConstants;
70
+
71
+ function requireConstants () {
72
+ if (hasRequiredConstants) return constants;
73
+ hasRequiredConstants = 1;
74
+
75
+ // Note: this is the semver.org version of the spec that it implements
76
+ // Not necessarily the package version of this code.
77
+ const SEMVER_SPEC_VERSION = '2.0.0';
78
+
79
+ const MAX_LENGTH = 256;
80
+ const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER ||
81
+ /* istanbul ignore next */ 9007199254740991;
82
+
83
+ // Max safe segment length for coercion.
84
+ const MAX_SAFE_COMPONENT_LENGTH = 16;
85
+
86
+ // Max safe length for a build identifier. The max length minus 6 characters for
87
+ // the shortest version with a build 0.0.0+BUILD.
88
+ const MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
89
+
90
+ const RELEASE_TYPES = [
91
+ 'major',
92
+ 'premajor',
93
+ 'minor',
94
+ 'preminor',
95
+ 'patch',
96
+ 'prepatch',
97
+ 'prerelease',
98
+ ];
99
+
100
+ constants = {
101
+ MAX_LENGTH,
102
+ MAX_SAFE_COMPONENT_LENGTH,
103
+ MAX_SAFE_BUILD_LENGTH,
104
+ MAX_SAFE_INTEGER,
105
+ RELEASE_TYPES,
106
+ SEMVER_SPEC_VERSION,
107
+ FLAG_INCLUDE_PRERELEASE: 0b001,
108
+ FLAG_LOOSE: 0b010,
109
+ };
110
+ return constants;
111
+ }
112
+
113
+ var debug_1;
114
+ var hasRequiredDebug;
115
+
116
+ function requireDebug () {
117
+ if (hasRequiredDebug) return debug_1;
118
+ hasRequiredDebug = 1;
119
+
120
+ const debug = (
121
+ typeof process === 'object' &&
122
+ process.env &&
123
+ process.env.NODE_DEBUG &&
124
+ /\bsemver\b/i.test(process.env.NODE_DEBUG)
125
+ ) ? (...args) => console.error('SEMVER', ...args)
126
+ : () => {};
127
+
128
+ debug_1 = debug;
129
+ return debug_1;
130
+ }
131
+
132
+ var hasRequiredRe;
133
+
134
+ function requireRe () {
135
+ if (hasRequiredRe) return re.exports;
136
+ hasRequiredRe = 1;
137
+ (function (module, exports$1) {
138
+
139
+ const {
140
+ MAX_SAFE_COMPONENT_LENGTH,
141
+ MAX_SAFE_BUILD_LENGTH,
142
+ MAX_LENGTH,
143
+ } = requireConstants();
144
+ const debug = requireDebug();
145
+ exports$1 = module.exports = {};
146
+
147
+ // The actual regexps go on exports.re
148
+ const re = exports$1.re = [];
149
+ const safeRe = exports$1.safeRe = [];
150
+ const src = exports$1.src = [];
151
+ const safeSrc = exports$1.safeSrc = [];
152
+ const t = exports$1.t = {};
153
+ let R = 0;
154
+
155
+ const LETTERDASHNUMBER = '[a-zA-Z0-9-]';
156
+
157
+ // Replace some greedy regex tokens to prevent regex dos issues. These regex are
158
+ // used internally via the safeRe object since all inputs in this library get
159
+ // normalized first to trim and collapse all extra whitespace. The original
160
+ // regexes are exported for userland consumption and lower level usage. A
161
+ // future breaking change could export the safer regex only with a note that
162
+ // all input should have extra whitespace removed.
163
+ const safeRegexReplacements = [
164
+ ['\\s', 1],
165
+ ['\\d', MAX_LENGTH],
166
+ [LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH],
167
+ ];
168
+
169
+ const makeSafeRegex = (value) => {
170
+ for (const [token, max] of safeRegexReplacements) {
171
+ value = value
172
+ .split(`${token}*`).join(`${token}{0,${max}}`)
173
+ .split(`${token}+`).join(`${token}{1,${max}}`);
174
+ }
175
+ return value
176
+ };
177
+
178
+ const createToken = (name, value, isGlobal) => {
179
+ const safe = makeSafeRegex(value);
180
+ const index = R++;
181
+ debug(name, index, value);
182
+ t[name] = index;
183
+ src[index] = value;
184
+ safeSrc[index] = safe;
185
+ re[index] = new RegExp(value, isGlobal ? 'g' : undefined);
186
+ safeRe[index] = new RegExp(safe, isGlobal ? 'g' : undefined);
187
+ };
188
+
189
+ // The following Regular Expressions can be used for tokenizing,
190
+ // validating, and parsing SemVer version strings.
191
+
192
+ // ## Numeric Identifier
193
+ // A single `0`, or a non-zero digit followed by zero or more digits.
194
+
195
+ createToken('NUMERICIDENTIFIER', '0|[1-9]\\d*');
196
+ createToken('NUMERICIDENTIFIERLOOSE', '\\d+');
197
+
198
+ // ## Non-numeric Identifier
199
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
200
+ // more letters, digits, or hyphens.
201
+
202
+ createToken('NONNUMERICIDENTIFIER', `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
203
+
204
+ // ## Main Version
205
+ // Three dot-separated numeric identifiers.
206
+
207
+ createToken('MAINVERSION', `(${src[t.NUMERICIDENTIFIER]})\\.` +
208
+ `(${src[t.NUMERICIDENTIFIER]})\\.` +
209
+ `(${src[t.NUMERICIDENTIFIER]})`);
210
+
211
+ createToken('MAINVERSIONLOOSE', `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
212
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.` +
213
+ `(${src[t.NUMERICIDENTIFIERLOOSE]})`);
214
+
215
+ // ## Pre-release Version Identifier
216
+ // A numeric identifier, or a non-numeric identifier.
217
+ // Non-numeric identifiers include numeric identifiers but can be longer.
218
+ // Therefore non-numeric identifiers must go first.
219
+
220
+ createToken('PRERELEASEIDENTIFIER', `(?:${src[t.NONNUMERICIDENTIFIER]
221
+ }|${src[t.NUMERICIDENTIFIER]})`);
222
+
223
+ createToken('PRERELEASEIDENTIFIERLOOSE', `(?:${src[t.NONNUMERICIDENTIFIER]
224
+ }|${src[t.NUMERICIDENTIFIERLOOSE]})`);
225
+
226
+ // ## Pre-release Version
227
+ // Hyphen, followed by one or more dot-separated pre-release version
228
+ // identifiers.
229
+
230
+ createToken('PRERELEASE', `(?:-(${src[t.PRERELEASEIDENTIFIER]
231
+ }(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
232
+
233
+ createToken('PRERELEASELOOSE', `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]
234
+ }(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
235
+
236
+ // ## Build Metadata Identifier
237
+ // Any combination of digits, letters, or hyphens.
238
+
239
+ createToken('BUILDIDENTIFIER', `${LETTERDASHNUMBER}+`);
240
+
241
+ // ## Build Metadata
242
+ // Plus sign, followed by one or more period-separated build metadata
243
+ // identifiers.
244
+
245
+ createToken('BUILD', `(?:\\+(${src[t.BUILDIDENTIFIER]
246
+ }(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
247
+
248
+ // ## Full Version String
249
+ // A main version, followed optionally by a pre-release version and
250
+ // build metadata.
251
+
252
+ // Note that the only major, minor, patch, and pre-release sections of
253
+ // the version string are capturing groups. The build metadata is not a
254
+ // capturing group, because it should not ever be used in version
255
+ // comparison.
256
+
257
+ createToken('FULLPLAIN', `v?${src[t.MAINVERSION]
258
+ }${src[t.PRERELEASE]}?${
259
+ src[t.BUILD]}?`);
260
+
261
+ createToken('FULL', `^${src[t.FULLPLAIN]}$`);
262
+
263
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
264
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
265
+ // common in the npm registry.
266
+ createToken('LOOSEPLAIN', `[v=\\s]*${src[t.MAINVERSIONLOOSE]
267
+ }${src[t.PRERELEASELOOSE]}?${
268
+ src[t.BUILD]}?`);
269
+
270
+ createToken('LOOSE', `^${src[t.LOOSEPLAIN]}$`);
271
+
272
+ createToken('GTLT', '((?:<|>)?=?)');
273
+
274
+ // Something like "2.*" or "1.2.x".
275
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
276
+ // Only the first item is strictly required.
277
+ createToken('XRANGEIDENTIFIERLOOSE', `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
278
+ createToken('XRANGEIDENTIFIER', `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
279
+
280
+ createToken('XRANGEPLAIN', `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})` +
281
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
282
+ `(?:\\.(${src[t.XRANGEIDENTIFIER]})` +
283
+ `(?:${src[t.PRERELEASE]})?${
284
+ src[t.BUILD]}?` +
285
+ `)?)?`);
286
+
287
+ createToken('XRANGEPLAINLOOSE', `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})` +
288
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
289
+ `(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})` +
290
+ `(?:${src[t.PRERELEASELOOSE]})?${
291
+ src[t.BUILD]}?` +
292
+ `)?)?`);
293
+
294
+ createToken('XRANGE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
295
+ createToken('XRANGELOOSE', `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
296
+
297
+ // Coercion.
298
+ // Extract anything that could conceivably be a part of a valid semver
299
+ createToken('COERCEPLAIN', `${'(^|[^\\d])' +
300
+ '(\\d{1,'}${MAX_SAFE_COMPONENT_LENGTH}})` +
301
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?` +
302
+ `(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
303
+ createToken('COERCE', `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
304
+ createToken('COERCEFULL', src[t.COERCEPLAIN] +
305
+ `(?:${src[t.PRERELEASE]})?` +
306
+ `(?:${src[t.BUILD]})?` +
307
+ `(?:$|[^\\d])`);
308
+ createToken('COERCERTL', src[t.COERCE], true);
309
+ createToken('COERCERTLFULL', src[t.COERCEFULL], true);
310
+
311
+ // Tilde ranges.
312
+ // Meaning is "reasonably at or greater than"
313
+ createToken('LONETILDE', '(?:~>?)');
314
+
315
+ createToken('TILDETRIM', `(\\s*)${src[t.LONETILDE]}\\s+`, true);
316
+ exports$1.tildeTrimReplace = '$1~';
317
+
318
+ createToken('TILDE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
319
+ createToken('TILDELOOSE', `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
320
+
321
+ // Caret ranges.
322
+ // Meaning is "at least and backwards compatible with"
323
+ createToken('LONECARET', '(?:\\^)');
324
+
325
+ createToken('CARETTRIM', `(\\s*)${src[t.LONECARET]}\\s+`, true);
326
+ exports$1.caretTrimReplace = '$1^';
327
+
328
+ createToken('CARET', `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
329
+ createToken('CARETLOOSE', `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
330
+
331
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
332
+ createToken('COMPARATORLOOSE', `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
333
+ createToken('COMPARATOR', `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
334
+
335
+ // An expression to strip any whitespace between the gtlt and the thing
336
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
337
+ createToken('COMPARATORTRIM', `(\\s*)${src[t.GTLT]
338
+ }\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
339
+ exports$1.comparatorTrimReplace = '$1$2$3';
340
+
341
+ // Something like `1.2.3 - 1.2.4`
342
+ // Note that these all use the loose form, because they'll be
343
+ // checked against either the strict or loose comparator form
344
+ // later.
345
+ createToken('HYPHENRANGE', `^\\s*(${src[t.XRANGEPLAIN]})` +
346
+ `\\s+-\\s+` +
347
+ `(${src[t.XRANGEPLAIN]})` +
348
+ `\\s*$`);
349
+
350
+ createToken('HYPHENRANGELOOSE', `^\\s*(${src[t.XRANGEPLAINLOOSE]})` +
351
+ `\\s+-\\s+` +
352
+ `(${src[t.XRANGEPLAINLOOSE]})` +
353
+ `\\s*$`);
354
+
355
+ // Star ranges basically just allow anything at all.
356
+ createToken('STAR', '(<|>)?=?\\s*\\*');
357
+ // >=0.0.0 is like a star
358
+ createToken('GTE0', '^\\s*>=\\s*0\\.0\\.0\\s*$');
359
+ createToken('GTE0PRE', '^\\s*>=\\s*0\\.0\\.0-0\\s*$');
360
+ } (re, re.exports));
361
+ return re.exports;
362
+ }
363
+
364
+ var parseOptions_1;
365
+ var hasRequiredParseOptions;
366
+
367
+ function requireParseOptions () {
368
+ if (hasRequiredParseOptions) return parseOptions_1;
369
+ hasRequiredParseOptions = 1;
370
+
371
+ // parse out just the options we care about
372
+ const looseOption = Object.freeze({ loose: true });
373
+ const emptyOpts = Object.freeze({ });
374
+ const parseOptions = options => {
375
+ if (!options) {
376
+ return emptyOpts
377
+ }
378
+
379
+ if (typeof options !== 'object') {
380
+ return looseOption
381
+ }
382
+
383
+ return options
384
+ };
385
+ parseOptions_1 = parseOptions;
386
+ return parseOptions_1;
387
+ }
388
+
389
+ var identifiers;
390
+ var hasRequiredIdentifiers;
391
+
392
+ function requireIdentifiers () {
393
+ if (hasRequiredIdentifiers) return identifiers;
394
+ hasRequiredIdentifiers = 1;
395
+
396
+ const numeric = /^[0-9]+$/;
397
+ const compareIdentifiers = (a, b) => {
398
+ if (typeof a === 'number' && typeof b === 'number') {
399
+ return a === b ? 0 : a < b ? -1 : 1
400
+ }
401
+
402
+ const anum = numeric.test(a);
403
+ const bnum = numeric.test(b);
404
+
405
+ if (anum && bnum) {
406
+ a = +a;
407
+ b = +b;
408
+ }
409
+
410
+ return a === b ? 0
411
+ : (anum && !bnum) ? -1
412
+ : (bnum && !anum) ? 1
413
+ : a < b ? -1
414
+ : 1
415
+ };
416
+
417
+ const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a);
418
+
419
+ identifiers = {
420
+ compareIdentifiers,
421
+ rcompareIdentifiers,
422
+ };
423
+ return identifiers;
424
+ }
425
+
426
+ var semver$2;
427
+ var hasRequiredSemver$1;
428
+
429
+ function requireSemver$1 () {
430
+ if (hasRequiredSemver$1) return semver$2;
431
+ hasRequiredSemver$1 = 1;
432
+
433
+ const debug = requireDebug();
434
+ const { MAX_LENGTH, MAX_SAFE_INTEGER } = requireConstants();
435
+ const { safeRe: re, t } = requireRe();
436
+
437
+ const parseOptions = requireParseOptions();
438
+ const { compareIdentifiers } = requireIdentifiers();
439
+ class SemVer {
440
+ constructor (version, options) {
441
+ options = parseOptions(options);
442
+
443
+ if (version instanceof SemVer) {
444
+ if (version.loose === !!options.loose &&
445
+ version.includePrerelease === !!options.includePrerelease) {
446
+ return version
447
+ } else {
448
+ version = version.version;
449
+ }
450
+ } else if (typeof version !== 'string') {
451
+ throw new TypeError(`Invalid version. Must be a string. Got type "${typeof version}".`)
452
+ }
453
+
454
+ if (version.length > MAX_LENGTH) {
455
+ throw new TypeError(
456
+ `version is longer than ${MAX_LENGTH} characters`
457
+ )
458
+ }
459
+
460
+ debug('SemVer', version, options);
461
+ this.options = options;
462
+ this.loose = !!options.loose;
463
+ // this isn't actually relevant for versions, but keep it so that we
464
+ // don't run into trouble passing this.options around.
465
+ this.includePrerelease = !!options.includePrerelease;
466
+
467
+ const m = version.trim().match(options.loose ? re[t.LOOSE] : re[t.FULL]);
468
+
469
+ if (!m) {
470
+ throw new TypeError(`Invalid Version: ${version}`)
471
+ }
472
+
473
+ this.raw = version;
474
+
475
+ // these are actually numbers
476
+ this.major = +m[1];
477
+ this.minor = +m[2];
478
+ this.patch = +m[3];
479
+
480
+ if (this.major > MAX_SAFE_INTEGER || this.major < 0) {
481
+ throw new TypeError('Invalid major version')
482
+ }
483
+
484
+ if (this.minor > MAX_SAFE_INTEGER || this.minor < 0) {
485
+ throw new TypeError('Invalid minor version')
486
+ }
487
+
488
+ if (this.patch > MAX_SAFE_INTEGER || this.patch < 0) {
489
+ throw new TypeError('Invalid patch version')
490
+ }
491
+
492
+ // numberify any prerelease numeric ids
493
+ if (!m[4]) {
494
+ this.prerelease = [];
495
+ } else {
496
+ this.prerelease = m[4].split('.').map((id) => {
497
+ if (/^[0-9]+$/.test(id)) {
498
+ const num = +id;
499
+ if (num >= 0 && num < MAX_SAFE_INTEGER) {
500
+ return num
501
+ }
502
+ }
503
+ return id
504
+ });
505
+ }
506
+
507
+ this.build = m[5] ? m[5].split('.') : [];
508
+ this.format();
509
+ }
510
+
511
+ format () {
512
+ this.version = `${this.major}.${this.minor}.${this.patch}`;
513
+ if (this.prerelease.length) {
514
+ this.version += `-${this.prerelease.join('.')}`;
515
+ }
516
+ return this.version
517
+ }
518
+
519
+ toString () {
520
+ return this.version
521
+ }
522
+
523
+ compare (other) {
524
+ debug('SemVer.compare', this.version, this.options, other);
525
+ if (!(other instanceof SemVer)) {
526
+ if (typeof other === 'string' && other === this.version) {
527
+ return 0
528
+ }
529
+ other = new SemVer(other, this.options);
530
+ }
531
+
532
+ if (other.version === this.version) {
533
+ return 0
534
+ }
535
+
536
+ return this.compareMain(other) || this.comparePre(other)
537
+ }
538
+
539
+ compareMain (other) {
540
+ if (!(other instanceof SemVer)) {
541
+ other = new SemVer(other, this.options);
542
+ }
543
+
544
+ if (this.major < other.major) {
545
+ return -1
546
+ }
547
+ if (this.major > other.major) {
548
+ return 1
549
+ }
550
+ if (this.minor < other.minor) {
551
+ return -1
552
+ }
553
+ if (this.minor > other.minor) {
554
+ return 1
555
+ }
556
+ if (this.patch < other.patch) {
557
+ return -1
558
+ }
559
+ if (this.patch > other.patch) {
560
+ return 1
561
+ }
562
+ return 0
563
+ }
564
+
565
+ comparePre (other) {
566
+ if (!(other instanceof SemVer)) {
567
+ other = new SemVer(other, this.options);
568
+ }
569
+
570
+ // NOT having a prerelease is > having one
571
+ if (this.prerelease.length && !other.prerelease.length) {
572
+ return -1
573
+ } else if (!this.prerelease.length && other.prerelease.length) {
574
+ return 1
575
+ } else if (!this.prerelease.length && !other.prerelease.length) {
576
+ return 0
577
+ }
578
+
579
+ let i = 0;
580
+ do {
581
+ const a = this.prerelease[i];
582
+ const b = other.prerelease[i];
583
+ debug('prerelease compare', i, a, b);
584
+ if (a === undefined && b === undefined) {
585
+ return 0
586
+ } else if (b === undefined) {
587
+ return 1
588
+ } else if (a === undefined) {
589
+ return -1
590
+ } else if (a === b) {
591
+ continue
592
+ } else {
593
+ return compareIdentifiers(a, b)
594
+ }
595
+ } while (++i)
596
+ }
597
+
598
+ compareBuild (other) {
599
+ if (!(other instanceof SemVer)) {
600
+ other = new SemVer(other, this.options);
601
+ }
602
+
603
+ let i = 0;
604
+ do {
605
+ const a = this.build[i];
606
+ const b = other.build[i];
607
+ debug('build compare', i, a, b);
608
+ if (a === undefined && b === undefined) {
609
+ return 0
610
+ } else if (b === undefined) {
611
+ return 1
612
+ } else if (a === undefined) {
613
+ return -1
614
+ } else if (a === b) {
615
+ continue
616
+ } else {
617
+ return compareIdentifiers(a, b)
618
+ }
619
+ } while (++i)
620
+ }
621
+
622
+ // preminor will bump the version up to the next minor release, and immediately
623
+ // down to pre-release. premajor and prepatch work the same way.
624
+ inc (release, identifier, identifierBase) {
625
+ if (release.startsWith('pre')) {
626
+ if (!identifier && identifierBase === false) {
627
+ throw new Error('invalid increment argument: identifier is empty')
628
+ }
629
+ // Avoid an invalid semver results
630
+ if (identifier) {
631
+ const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE]);
632
+ if (!match || match[1] !== identifier) {
633
+ throw new Error(`invalid identifier: ${identifier}`)
634
+ }
635
+ }
636
+ }
637
+
638
+ switch (release) {
639
+ case 'premajor':
640
+ this.prerelease.length = 0;
641
+ this.patch = 0;
642
+ this.minor = 0;
643
+ this.major++;
644
+ this.inc('pre', identifier, identifierBase);
645
+ break
646
+ case 'preminor':
647
+ this.prerelease.length = 0;
648
+ this.patch = 0;
649
+ this.minor++;
650
+ this.inc('pre', identifier, identifierBase);
651
+ break
652
+ case 'prepatch':
653
+ // If this is already a prerelease, it will bump to the next version
654
+ // drop any prereleases that might already exist, since they are not
655
+ // relevant at this point.
656
+ this.prerelease.length = 0;
657
+ this.inc('patch', identifier, identifierBase);
658
+ this.inc('pre', identifier, identifierBase);
659
+ break
660
+ // If the input is a non-prerelease version, this acts the same as
661
+ // prepatch.
662
+ case 'prerelease':
663
+ if (this.prerelease.length === 0) {
664
+ this.inc('patch', identifier, identifierBase);
665
+ }
666
+ this.inc('pre', identifier, identifierBase);
667
+ break
668
+ case 'release':
669
+ if (this.prerelease.length === 0) {
670
+ throw new Error(`version ${this.raw} is not a prerelease`)
671
+ }
672
+ this.prerelease.length = 0;
673
+ break
674
+
675
+ case 'major':
676
+ // If this is a pre-major version, bump up to the same major version.
677
+ // Otherwise increment major.
678
+ // 1.0.0-5 bumps to 1.0.0
679
+ // 1.1.0 bumps to 2.0.0
680
+ if (
681
+ this.minor !== 0 ||
682
+ this.patch !== 0 ||
683
+ this.prerelease.length === 0
684
+ ) {
685
+ this.major++;
686
+ }
687
+ this.minor = 0;
688
+ this.patch = 0;
689
+ this.prerelease = [];
690
+ break
691
+ case 'minor':
692
+ // If this is a pre-minor version, bump up to the same minor version.
693
+ // Otherwise increment minor.
694
+ // 1.2.0-5 bumps to 1.2.0
695
+ // 1.2.1 bumps to 1.3.0
696
+ if (this.patch !== 0 || this.prerelease.length === 0) {
697
+ this.minor++;
698
+ }
699
+ this.patch = 0;
700
+ this.prerelease = [];
701
+ break
702
+ case 'patch':
703
+ // If this is not a pre-release version, it will increment the patch.
704
+ // If it is a pre-release it will bump up to the same patch version.
705
+ // 1.2.0-5 patches to 1.2.0
706
+ // 1.2.0 patches to 1.2.1
707
+ if (this.prerelease.length === 0) {
708
+ this.patch++;
709
+ }
710
+ this.prerelease = [];
711
+ break
712
+ // This probably shouldn't be used publicly.
713
+ // 1.0.0 'pre' would become 1.0.0-0 which is the wrong direction.
714
+ case 'pre': {
715
+ const base = Number(identifierBase) ? 1 : 0;
716
+
717
+ if (this.prerelease.length === 0) {
718
+ this.prerelease = [base];
719
+ } else {
720
+ let i = this.prerelease.length;
721
+ while (--i >= 0) {
722
+ if (typeof this.prerelease[i] === 'number') {
723
+ this.prerelease[i]++;
724
+ i = -2;
725
+ }
726
+ }
727
+ if (i === -1) {
728
+ // didn't increment anything
729
+ if (identifier === this.prerelease.join('.') && identifierBase === false) {
730
+ throw new Error('invalid increment argument: identifier already exists')
731
+ }
732
+ this.prerelease.push(base);
733
+ }
734
+ }
735
+ if (identifier) {
736
+ // 1.2.0-beta.1 bumps to 1.2.0-beta.2,
737
+ // 1.2.0-beta.fooblz or 1.2.0-beta bumps to 1.2.0-beta.0
738
+ let prerelease = [identifier, base];
739
+ if (identifierBase === false) {
740
+ prerelease = [identifier];
741
+ }
742
+ if (compareIdentifiers(this.prerelease[0], identifier) === 0) {
743
+ if (isNaN(this.prerelease[1])) {
744
+ this.prerelease = prerelease;
745
+ }
746
+ } else {
747
+ this.prerelease = prerelease;
748
+ }
749
+ }
750
+ break
751
+ }
752
+ default:
753
+ throw new Error(`invalid increment argument: ${release}`)
754
+ }
755
+ this.raw = this.format();
756
+ if (this.build.length) {
757
+ this.raw += `+${this.build.join('.')}`;
758
+ }
759
+ return this
760
+ }
761
+ }
762
+
763
+ semver$2 = SemVer;
764
+ return semver$2;
765
+ }
766
+
767
+ var parse_1;
768
+ var hasRequiredParse;
769
+
770
+ function requireParse () {
771
+ if (hasRequiredParse) return parse_1;
772
+ hasRequiredParse = 1;
773
+
774
+ const SemVer = requireSemver$1();
775
+ const parse = (version, options, throwErrors = false) => {
776
+ if (version instanceof SemVer) {
777
+ return version
778
+ }
779
+ try {
780
+ return new SemVer(version, options)
781
+ } catch (er) {
782
+ if (!throwErrors) {
783
+ return null
784
+ }
785
+ throw er
786
+ }
787
+ };
788
+
789
+ parse_1 = parse;
790
+ return parse_1;
791
+ }
792
+
793
+ var valid_1;
794
+ var hasRequiredValid$1;
795
+
796
+ function requireValid$1 () {
797
+ if (hasRequiredValid$1) return valid_1;
798
+ hasRequiredValid$1 = 1;
799
+
800
+ const parse = requireParse();
801
+ const valid = (version, options) => {
802
+ const v = parse(version, options);
803
+ return v ? v.version : null
804
+ };
805
+ valid_1 = valid;
806
+ return valid_1;
807
+ }
808
+
809
+ var clean_1;
810
+ var hasRequiredClean;
811
+
812
+ function requireClean () {
813
+ if (hasRequiredClean) return clean_1;
814
+ hasRequiredClean = 1;
815
+
816
+ const parse = requireParse();
817
+ const clean = (version, options) => {
818
+ const s = parse(version.trim().replace(/^[=v]+/, ''), options);
819
+ return s ? s.version : null
820
+ };
821
+ clean_1 = clean;
822
+ return clean_1;
823
+ }
824
+
825
+ var inc_1;
826
+ var hasRequiredInc;
827
+
828
+ function requireInc () {
829
+ if (hasRequiredInc) return inc_1;
830
+ hasRequiredInc = 1;
831
+
832
+ const SemVer = requireSemver$1();
833
+
834
+ const inc = (version, release, options, identifier, identifierBase) => {
835
+ if (typeof (options) === 'string') {
836
+ identifierBase = identifier;
837
+ identifier = options;
838
+ options = undefined;
839
+ }
840
+
841
+ try {
842
+ return new SemVer(
843
+ version instanceof SemVer ? version.version : version,
844
+ options
845
+ ).inc(release, identifier, identifierBase).version
846
+ } catch (er) {
847
+ return null
848
+ }
849
+ };
850
+ inc_1 = inc;
851
+ return inc_1;
852
+ }
853
+
854
+ var diff_1;
855
+ var hasRequiredDiff;
856
+
857
+ function requireDiff () {
858
+ if (hasRequiredDiff) return diff_1;
859
+ hasRequiredDiff = 1;
860
+
861
+ const parse = requireParse();
862
+
863
+ const diff = (version1, version2) => {
864
+ const v1 = parse(version1, null, true);
865
+ const v2 = parse(version2, null, true);
866
+ const comparison = v1.compare(v2);
867
+
868
+ if (comparison === 0) {
869
+ return null
870
+ }
871
+
872
+ const v1Higher = comparison > 0;
873
+ const highVersion = v1Higher ? v1 : v2;
874
+ const lowVersion = v1Higher ? v2 : v1;
875
+ const highHasPre = !!highVersion.prerelease.length;
876
+ const lowHasPre = !!lowVersion.prerelease.length;
877
+
878
+ if (lowHasPre && !highHasPre) {
879
+ // Going from prerelease -> no prerelease requires some special casing
880
+
881
+ // If the low version has only a major, then it will always be a major
882
+ // Some examples:
883
+ // 1.0.0-1 -> 1.0.0
884
+ // 1.0.0-1 -> 1.1.1
885
+ // 1.0.0-1 -> 2.0.0
886
+ if (!lowVersion.patch && !lowVersion.minor) {
887
+ return 'major'
888
+ }
889
+
890
+ // If the main part has no difference
891
+ if (lowVersion.compareMain(highVersion) === 0) {
892
+ if (lowVersion.minor && !lowVersion.patch) {
893
+ return 'minor'
894
+ }
895
+ return 'patch'
896
+ }
897
+ }
898
+
899
+ // add the `pre` prefix if we are going to a prerelease version
900
+ const prefix = highHasPre ? 'pre' : '';
901
+
902
+ if (v1.major !== v2.major) {
903
+ return prefix + 'major'
904
+ }
905
+
906
+ if (v1.minor !== v2.minor) {
907
+ return prefix + 'minor'
908
+ }
909
+
910
+ if (v1.patch !== v2.patch) {
911
+ return prefix + 'patch'
912
+ }
913
+
914
+ // high and low are prereleases
915
+ return 'prerelease'
916
+ };
917
+
918
+ diff_1 = diff;
919
+ return diff_1;
920
+ }
921
+
922
+ var major_1;
923
+ var hasRequiredMajor;
924
+
925
+ function requireMajor () {
926
+ if (hasRequiredMajor) return major_1;
927
+ hasRequiredMajor = 1;
928
+
929
+ const SemVer = requireSemver$1();
930
+ const major = (a, loose) => new SemVer(a, loose).major;
931
+ major_1 = major;
932
+ return major_1;
933
+ }
934
+
935
+ var minor_1;
936
+ var hasRequiredMinor;
937
+
938
+ function requireMinor () {
939
+ if (hasRequiredMinor) return minor_1;
940
+ hasRequiredMinor = 1;
941
+
942
+ const SemVer = requireSemver$1();
943
+ const minor = (a, loose) => new SemVer(a, loose).minor;
944
+ minor_1 = minor;
945
+ return minor_1;
946
+ }
947
+
948
+ var patch_1;
949
+ var hasRequiredPatch;
950
+
951
+ function requirePatch () {
952
+ if (hasRequiredPatch) return patch_1;
953
+ hasRequiredPatch = 1;
954
+
955
+ const SemVer = requireSemver$1();
956
+ const patch = (a, loose) => new SemVer(a, loose).patch;
957
+ patch_1 = patch;
958
+ return patch_1;
959
+ }
960
+
961
+ var prerelease_1;
962
+ var hasRequiredPrerelease;
963
+
964
+ function requirePrerelease () {
965
+ if (hasRequiredPrerelease) return prerelease_1;
966
+ hasRequiredPrerelease = 1;
967
+
968
+ const parse = requireParse();
969
+ const prerelease = (version, options) => {
970
+ const parsed = parse(version, options);
971
+ return (parsed && parsed.prerelease.length) ? parsed.prerelease : null
972
+ };
973
+ prerelease_1 = prerelease;
974
+ return prerelease_1;
975
+ }
976
+
977
+ var compare_1;
978
+ var hasRequiredCompare;
979
+
980
+ function requireCompare () {
981
+ if (hasRequiredCompare) return compare_1;
982
+ hasRequiredCompare = 1;
983
+
984
+ const SemVer = requireSemver$1();
985
+ const compare = (a, b, loose) =>
986
+ new SemVer(a, loose).compare(new SemVer(b, loose));
987
+
988
+ compare_1 = compare;
989
+ return compare_1;
990
+ }
991
+
992
+ var rcompare_1;
993
+ var hasRequiredRcompare;
994
+
995
+ function requireRcompare () {
996
+ if (hasRequiredRcompare) return rcompare_1;
997
+ hasRequiredRcompare = 1;
998
+
999
+ const compare = requireCompare();
1000
+ const rcompare = (a, b, loose) => compare(b, a, loose);
1001
+ rcompare_1 = rcompare;
1002
+ return rcompare_1;
1003
+ }
1004
+
1005
+ var compareLoose_1;
1006
+ var hasRequiredCompareLoose;
1007
+
1008
+ function requireCompareLoose () {
1009
+ if (hasRequiredCompareLoose) return compareLoose_1;
1010
+ hasRequiredCompareLoose = 1;
1011
+
1012
+ const compare = requireCompare();
1013
+ const compareLoose = (a, b) => compare(a, b, true);
1014
+ compareLoose_1 = compareLoose;
1015
+ return compareLoose_1;
1016
+ }
1017
+
1018
+ var compareBuild_1;
1019
+ var hasRequiredCompareBuild;
1020
+
1021
+ function requireCompareBuild () {
1022
+ if (hasRequiredCompareBuild) return compareBuild_1;
1023
+ hasRequiredCompareBuild = 1;
1024
+
1025
+ const SemVer = requireSemver$1();
1026
+ const compareBuild = (a, b, loose) => {
1027
+ const versionA = new SemVer(a, loose);
1028
+ const versionB = new SemVer(b, loose);
1029
+ return versionA.compare(versionB) || versionA.compareBuild(versionB)
1030
+ };
1031
+ compareBuild_1 = compareBuild;
1032
+ return compareBuild_1;
1033
+ }
1034
+
1035
+ var sort_1;
1036
+ var hasRequiredSort;
1037
+
1038
+ function requireSort () {
1039
+ if (hasRequiredSort) return sort_1;
1040
+ hasRequiredSort = 1;
1041
+
1042
+ const compareBuild = requireCompareBuild();
1043
+ const sort = (list, loose) => list.sort((a, b) => compareBuild(a, b, loose));
1044
+ sort_1 = sort;
1045
+ return sort_1;
1046
+ }
1047
+
1048
+ var rsort_1;
1049
+ var hasRequiredRsort;
1050
+
1051
+ function requireRsort () {
1052
+ if (hasRequiredRsort) return rsort_1;
1053
+ hasRequiredRsort = 1;
1054
+
1055
+ const compareBuild = requireCompareBuild();
1056
+ const rsort = (list, loose) => list.sort((a, b) => compareBuild(b, a, loose));
1057
+ rsort_1 = rsort;
1058
+ return rsort_1;
1059
+ }
1060
+
1061
+ var gt_1;
1062
+ var hasRequiredGt;
1063
+
1064
+ function requireGt () {
1065
+ if (hasRequiredGt) return gt_1;
1066
+ hasRequiredGt = 1;
1067
+
1068
+ const compare = requireCompare();
1069
+ const gt = (a, b, loose) => compare(a, b, loose) > 0;
1070
+ gt_1 = gt;
1071
+ return gt_1;
1072
+ }
1073
+
1074
+ var lt_1;
1075
+ var hasRequiredLt;
1076
+
1077
+ function requireLt () {
1078
+ if (hasRequiredLt) return lt_1;
1079
+ hasRequiredLt = 1;
1080
+
1081
+ const compare = requireCompare();
1082
+ const lt = (a, b, loose) => compare(a, b, loose) < 0;
1083
+ lt_1 = lt;
1084
+ return lt_1;
1085
+ }
1086
+
1087
+ var eq_1;
1088
+ var hasRequiredEq;
1089
+
1090
+ function requireEq () {
1091
+ if (hasRequiredEq) return eq_1;
1092
+ hasRequiredEq = 1;
1093
+
1094
+ const compare = requireCompare();
1095
+ const eq = (a, b, loose) => compare(a, b, loose) === 0;
1096
+ eq_1 = eq;
1097
+ return eq_1;
1098
+ }
1099
+
1100
+ var neq_1;
1101
+ var hasRequiredNeq;
1102
+
1103
+ function requireNeq () {
1104
+ if (hasRequiredNeq) return neq_1;
1105
+ hasRequiredNeq = 1;
1106
+
1107
+ const compare = requireCompare();
1108
+ const neq = (a, b, loose) => compare(a, b, loose) !== 0;
1109
+ neq_1 = neq;
1110
+ return neq_1;
1111
+ }
1112
+
1113
+ var gte_1;
1114
+ var hasRequiredGte;
1115
+
1116
+ function requireGte () {
1117
+ if (hasRequiredGte) return gte_1;
1118
+ hasRequiredGte = 1;
1119
+
1120
+ const compare = requireCompare();
1121
+ const gte = (a, b, loose) => compare(a, b, loose) >= 0;
1122
+ gte_1 = gte;
1123
+ return gte_1;
1124
+ }
1125
+
1126
+ var lte_1;
1127
+ var hasRequiredLte;
1128
+
1129
+ function requireLte () {
1130
+ if (hasRequiredLte) return lte_1;
1131
+ hasRequiredLte = 1;
1132
+
1133
+ const compare = requireCompare();
1134
+ const lte = (a, b, loose) => compare(a, b, loose) <= 0;
1135
+ lte_1 = lte;
1136
+ return lte_1;
1137
+ }
1138
+
1139
+ var cmp_1;
1140
+ var hasRequiredCmp;
1141
+
1142
+ function requireCmp () {
1143
+ if (hasRequiredCmp) return cmp_1;
1144
+ hasRequiredCmp = 1;
1145
+
1146
+ const eq = requireEq();
1147
+ const neq = requireNeq();
1148
+ const gt = requireGt();
1149
+ const gte = requireGte();
1150
+ const lt = requireLt();
1151
+ const lte = requireLte();
1152
+
1153
+ const cmp = (a, op, b, loose) => {
1154
+ switch (op) {
1155
+ case '===':
1156
+ if (typeof a === 'object') {
1157
+ a = a.version;
1158
+ }
1159
+ if (typeof b === 'object') {
1160
+ b = b.version;
1161
+ }
1162
+ return a === b
1163
+
1164
+ case '!==':
1165
+ if (typeof a === 'object') {
1166
+ a = a.version;
1167
+ }
1168
+ if (typeof b === 'object') {
1169
+ b = b.version;
1170
+ }
1171
+ return a !== b
1172
+
1173
+ case '':
1174
+ case '=':
1175
+ case '==':
1176
+ return eq(a, b, loose)
1177
+
1178
+ case '!=':
1179
+ return neq(a, b, loose)
1180
+
1181
+ case '>':
1182
+ return gt(a, b, loose)
1183
+
1184
+ case '>=':
1185
+ return gte(a, b, loose)
1186
+
1187
+ case '<':
1188
+ return lt(a, b, loose)
1189
+
1190
+ case '<=':
1191
+ return lte(a, b, loose)
1192
+
1193
+ default:
1194
+ throw new TypeError(`Invalid operator: ${op}`)
1195
+ }
1196
+ };
1197
+ cmp_1 = cmp;
1198
+ return cmp_1;
1199
+ }
1200
+
1201
+ var coerce_1;
1202
+ var hasRequiredCoerce;
1203
+
1204
+ function requireCoerce () {
1205
+ if (hasRequiredCoerce) return coerce_1;
1206
+ hasRequiredCoerce = 1;
1207
+
1208
+ const SemVer = requireSemver$1();
1209
+ const parse = requireParse();
1210
+ const { safeRe: re, t } = requireRe();
1211
+
1212
+ const coerce = (version, options) => {
1213
+ if (version instanceof SemVer) {
1214
+ return version
1215
+ }
1216
+
1217
+ if (typeof version === 'number') {
1218
+ version = String(version);
1219
+ }
1220
+
1221
+ if (typeof version !== 'string') {
1222
+ return null
1223
+ }
1224
+
1225
+ options = options || {};
1226
+
1227
+ let match = null;
1228
+ if (!options.rtl) {
1229
+ match = version.match(options.includePrerelease ? re[t.COERCEFULL] : re[t.COERCE]);
1230
+ } else {
1231
+ // Find the right-most coercible string that does not share
1232
+ // a terminus with a more left-ward coercible string.
1233
+ // Eg, '1.2.3.4' wants to coerce '2.3.4', not '3.4' or '4'
1234
+ // With includePrerelease option set, '1.2.3.4-rc' wants to coerce '2.3.4-rc', not '2.3.4'
1235
+ //
1236
+ // Walk through the string checking with a /g regexp
1237
+ // Manually set the index so as to pick up overlapping matches.
1238
+ // Stop when we get a match that ends at the string end, since no
1239
+ // coercible string can be more right-ward without the same terminus.
1240
+ const coerceRtlRegex = options.includePrerelease ? re[t.COERCERTLFULL] : re[t.COERCERTL];
1241
+ let next;
1242
+ while ((next = coerceRtlRegex.exec(version)) &&
1243
+ (!match || match.index + match[0].length !== version.length)
1244
+ ) {
1245
+ if (!match ||
1246
+ next.index + next[0].length !== match.index + match[0].length) {
1247
+ match = next;
1248
+ }
1249
+ coerceRtlRegex.lastIndex = next.index + next[1].length + next[2].length;
1250
+ }
1251
+ // leave it in a clean state
1252
+ coerceRtlRegex.lastIndex = -1;
1253
+ }
1254
+
1255
+ if (match === null) {
1256
+ return null
1257
+ }
1258
+
1259
+ const major = match[2];
1260
+ const minor = match[3] || '0';
1261
+ const patch = match[4] || '0';
1262
+ const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : '';
1263
+ const build = options.includePrerelease && match[6] ? `+${match[6]}` : '';
1264
+
1265
+ return parse(`${major}.${minor}.${patch}${prerelease}${build}`, options)
1266
+ };
1267
+ coerce_1 = coerce;
1268
+ return coerce_1;
1269
+ }
1270
+
1271
+ var lrucache;
1272
+ var hasRequiredLrucache;
1273
+
1274
+ function requireLrucache () {
1275
+ if (hasRequiredLrucache) return lrucache;
1276
+ hasRequiredLrucache = 1;
1277
+
1278
+ class LRUCache {
1279
+ constructor () {
1280
+ this.max = 1000;
1281
+ this.map = new Map();
1282
+ }
1283
+
1284
+ get (key) {
1285
+ const value = this.map.get(key);
1286
+ if (value === undefined) {
1287
+ return undefined
1288
+ } else {
1289
+ // Remove the key from the map and add it to the end
1290
+ this.map.delete(key);
1291
+ this.map.set(key, value);
1292
+ return value
1293
+ }
1294
+ }
1295
+
1296
+ delete (key) {
1297
+ return this.map.delete(key)
1298
+ }
1299
+
1300
+ set (key, value) {
1301
+ const deleted = this.delete(key);
1302
+
1303
+ if (!deleted && value !== undefined) {
1304
+ // If cache is full, delete the least recently used item
1305
+ if (this.map.size >= this.max) {
1306
+ const firstKey = this.map.keys().next().value;
1307
+ this.delete(firstKey);
1308
+ }
1309
+
1310
+ this.map.set(key, value);
1311
+ }
1312
+
1313
+ return this
1314
+ }
1315
+ }
1316
+
1317
+ lrucache = LRUCache;
1318
+ return lrucache;
1319
+ }
1320
+
1321
+ var range;
1322
+ var hasRequiredRange;
1323
+
1324
+ function requireRange () {
1325
+ if (hasRequiredRange) return range;
1326
+ hasRequiredRange = 1;
1327
+
1328
+ const SPACE_CHARACTERS = /\s+/g;
1329
+
1330
+ // hoisted class for cyclic dependency
1331
+ class Range {
1332
+ constructor (range, options) {
1333
+ options = parseOptions(options);
1334
+
1335
+ if (range instanceof Range) {
1336
+ if (
1337
+ range.loose === !!options.loose &&
1338
+ range.includePrerelease === !!options.includePrerelease
1339
+ ) {
1340
+ return range
1341
+ } else {
1342
+ return new Range(range.raw, options)
1343
+ }
1344
+ }
1345
+
1346
+ if (range instanceof Comparator) {
1347
+ // just put it in the set and return
1348
+ this.raw = range.value;
1349
+ this.set = [[range]];
1350
+ this.formatted = undefined;
1351
+ return this
1352
+ }
1353
+
1354
+ this.options = options;
1355
+ this.loose = !!options.loose;
1356
+ this.includePrerelease = !!options.includePrerelease;
1357
+
1358
+ // First reduce all whitespace as much as possible so we do not have to rely
1359
+ // on potentially slow regexes like \s*. This is then stored and used for
1360
+ // future error messages as well.
1361
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
1362
+
1363
+ // First, split on ||
1364
+ this.set = this.raw
1365
+ .split('||')
1366
+ // map the range to a 2d array of comparators
1367
+ .map(r => this.parseRange(r.trim()))
1368
+ // throw out any comparator lists that are empty
1369
+ // this generally means that it was not a valid range, which is allowed
1370
+ // in loose mode, but will still throw if the WHOLE range is invalid.
1371
+ .filter(c => c.length);
1372
+
1373
+ if (!this.set.length) {
1374
+ throw new TypeError(`Invalid SemVer Range: ${this.raw}`)
1375
+ }
1376
+
1377
+ // if we have any that are not the null set, throw out null sets.
1378
+ if (this.set.length > 1) {
1379
+ // keep the first one, in case they're all null sets
1380
+ const first = this.set[0];
1381
+ this.set = this.set.filter(c => !isNullSet(c[0]));
1382
+ if (this.set.length === 0) {
1383
+ this.set = [first];
1384
+ } else if (this.set.length > 1) {
1385
+ // if we have any that are *, then the range is just *
1386
+ for (const c of this.set) {
1387
+ if (c.length === 1 && isAny(c[0])) {
1388
+ this.set = [c];
1389
+ break
1390
+ }
1391
+ }
1392
+ }
1393
+ }
1394
+
1395
+ this.formatted = undefined;
1396
+ }
1397
+
1398
+ get range () {
1399
+ if (this.formatted === undefined) {
1400
+ this.formatted = '';
1401
+ for (let i = 0; i < this.set.length; i++) {
1402
+ if (i > 0) {
1403
+ this.formatted += '||';
1404
+ }
1405
+ const comps = this.set[i];
1406
+ for (let k = 0; k < comps.length; k++) {
1407
+ if (k > 0) {
1408
+ this.formatted += ' ';
1409
+ }
1410
+ this.formatted += comps[k].toString().trim();
1411
+ }
1412
+ }
1413
+ }
1414
+ return this.formatted
1415
+ }
1416
+
1417
+ format () {
1418
+ return this.range
1419
+ }
1420
+
1421
+ toString () {
1422
+ return this.range
1423
+ }
1424
+
1425
+ parseRange (range) {
1426
+ // memoize range parsing for performance.
1427
+ // this is a very hot path, and fully deterministic.
1428
+ const memoOpts =
1429
+ (this.options.includePrerelease && FLAG_INCLUDE_PRERELEASE) |
1430
+ (this.options.loose && FLAG_LOOSE);
1431
+ const memoKey = memoOpts + ':' + range;
1432
+ const cached = cache.get(memoKey);
1433
+ if (cached) {
1434
+ return cached
1435
+ }
1436
+
1437
+ const loose = this.options.loose;
1438
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
1439
+ const hr = loose ? re[t.HYPHENRANGELOOSE] : re[t.HYPHENRANGE];
1440
+ range = range.replace(hr, hyphenReplace(this.options.includePrerelease));
1441
+ debug('hyphen replace', range);
1442
+
1443
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
1444
+ range = range.replace(re[t.COMPARATORTRIM], comparatorTrimReplace);
1445
+ debug('comparator trim', range);
1446
+
1447
+ // `~ 1.2.3` => `~1.2.3`
1448
+ range = range.replace(re[t.TILDETRIM], tildeTrimReplace);
1449
+ debug('tilde trim', range);
1450
+
1451
+ // `^ 1.2.3` => `^1.2.3`
1452
+ range = range.replace(re[t.CARETTRIM], caretTrimReplace);
1453
+ debug('caret trim', range);
1454
+
1455
+ // At this point, the range is completely trimmed and
1456
+ // ready to be split into comparators.
1457
+
1458
+ let rangeList = range
1459
+ .split(' ')
1460
+ .map(comp => parseComparator(comp, this.options))
1461
+ .join(' ')
1462
+ .split(/\s+/)
1463
+ // >=0.0.0 is equivalent to *
1464
+ .map(comp => replaceGTE0(comp, this.options));
1465
+
1466
+ if (loose) {
1467
+ // in loose mode, throw out any that are not valid comparators
1468
+ rangeList = rangeList.filter(comp => {
1469
+ debug('loose invalid filter', comp, this.options);
1470
+ return !!comp.match(re[t.COMPARATORLOOSE])
1471
+ });
1472
+ }
1473
+ debug('range list', rangeList);
1474
+
1475
+ // if any comparators are the null set, then replace with JUST null set
1476
+ // if more than one comparator, remove any * comparators
1477
+ // also, don't include the same comparator more than once
1478
+ const rangeMap = new Map();
1479
+ const comparators = rangeList.map(comp => new Comparator(comp, this.options));
1480
+ for (const comp of comparators) {
1481
+ if (isNullSet(comp)) {
1482
+ return [comp]
1483
+ }
1484
+ rangeMap.set(comp.value, comp);
1485
+ }
1486
+ if (rangeMap.size > 1 && rangeMap.has('')) {
1487
+ rangeMap.delete('');
1488
+ }
1489
+
1490
+ const result = [...rangeMap.values()];
1491
+ cache.set(memoKey, result);
1492
+ return result
1493
+ }
1494
+
1495
+ intersects (range, options) {
1496
+ if (!(range instanceof Range)) {
1497
+ throw new TypeError('a Range is required')
1498
+ }
1499
+
1500
+ return this.set.some((thisComparators) => {
1501
+ return (
1502
+ isSatisfiable(thisComparators, options) &&
1503
+ range.set.some((rangeComparators) => {
1504
+ return (
1505
+ isSatisfiable(rangeComparators, options) &&
1506
+ thisComparators.every((thisComparator) => {
1507
+ return rangeComparators.every((rangeComparator) => {
1508
+ return thisComparator.intersects(rangeComparator, options)
1509
+ })
1510
+ })
1511
+ )
1512
+ })
1513
+ )
1514
+ })
1515
+ }
1516
+
1517
+ // if ANY of the sets match ALL of its comparators, then pass
1518
+ test (version) {
1519
+ if (!version) {
1520
+ return false
1521
+ }
1522
+
1523
+ if (typeof version === 'string') {
1524
+ try {
1525
+ version = new SemVer(version, this.options);
1526
+ } catch (er) {
1527
+ return false
1528
+ }
1529
+ }
1530
+
1531
+ for (let i = 0; i < this.set.length; i++) {
1532
+ if (testSet(this.set[i], version, this.options)) {
1533
+ return true
1534
+ }
1535
+ }
1536
+ return false
1537
+ }
1538
+ }
1539
+
1540
+ range = Range;
1541
+
1542
+ const LRU = requireLrucache();
1543
+ const cache = new LRU();
1544
+
1545
+ const parseOptions = requireParseOptions();
1546
+ const Comparator = requireComparator();
1547
+ const debug = requireDebug();
1548
+ const SemVer = requireSemver$1();
1549
+ const {
1550
+ safeRe: re,
1551
+ t,
1552
+ comparatorTrimReplace,
1553
+ tildeTrimReplace,
1554
+ caretTrimReplace,
1555
+ } = requireRe();
1556
+ const { FLAG_INCLUDE_PRERELEASE, FLAG_LOOSE } = requireConstants();
1557
+
1558
+ const isNullSet = c => c.value === '<0.0.0-0';
1559
+ const isAny = c => c.value === '';
1560
+
1561
+ // take a set of comparators and determine whether there
1562
+ // exists a version which can satisfy it
1563
+ const isSatisfiable = (comparators, options) => {
1564
+ let result = true;
1565
+ const remainingComparators = comparators.slice();
1566
+ let testComparator = remainingComparators.pop();
1567
+
1568
+ while (result && remainingComparators.length) {
1569
+ result = remainingComparators.every((otherComparator) => {
1570
+ return testComparator.intersects(otherComparator, options)
1571
+ });
1572
+
1573
+ testComparator = remainingComparators.pop();
1574
+ }
1575
+
1576
+ return result
1577
+ };
1578
+
1579
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
1580
+ // already replaced the hyphen ranges
1581
+ // turn into a set of JUST comparators.
1582
+ const parseComparator = (comp, options) => {
1583
+ comp = comp.replace(re[t.BUILD], '');
1584
+ debug('comp', comp, options);
1585
+ comp = replaceCarets(comp, options);
1586
+ debug('caret', comp);
1587
+ comp = replaceTildes(comp, options);
1588
+ debug('tildes', comp);
1589
+ comp = replaceXRanges(comp, options);
1590
+ debug('xrange', comp);
1591
+ comp = replaceStars(comp, options);
1592
+ debug('stars', comp);
1593
+ return comp
1594
+ };
1595
+
1596
+ const isX = id => !id || id.toLowerCase() === 'x' || id === '*';
1597
+
1598
+ // ~, ~> --> * (any, kinda silly)
1599
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0-0
1600
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0-0
1601
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0-0
1602
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0-0
1603
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0-0
1604
+ // ~0.0.1 --> >=0.0.1 <0.1.0-0
1605
+ const replaceTildes = (comp, options) => {
1606
+ return comp
1607
+ .trim()
1608
+ .split(/\s+/)
1609
+ .map((c) => replaceTilde(c, options))
1610
+ .join(' ')
1611
+ };
1612
+
1613
+ const replaceTilde = (comp, options) => {
1614
+ const r = options.loose ? re[t.TILDELOOSE] : re[t.TILDE];
1615
+ return comp.replace(r, (_, M, m, p, pr) => {
1616
+ debug('tilde', comp, _, M, m, p, pr);
1617
+ let ret;
1618
+
1619
+ if (isX(M)) {
1620
+ ret = '';
1621
+ } else if (isX(m)) {
1622
+ ret = `>=${M}.0.0 <${+M + 1}.0.0-0`;
1623
+ } else if (isX(p)) {
1624
+ // ~1.2 == >=1.2.0 <1.3.0-0
1625
+ ret = `>=${M}.${m}.0 <${M}.${+m + 1}.0-0`;
1626
+ } else if (pr) {
1627
+ debug('replaceTilde pr', pr);
1628
+ ret = `>=${M}.${m}.${p}-${pr
1629
+ } <${M}.${+m + 1}.0-0`;
1630
+ } else {
1631
+ // ~1.2.3 == >=1.2.3 <1.3.0-0
1632
+ ret = `>=${M}.${m}.${p
1633
+ } <${M}.${+m + 1}.0-0`;
1634
+ }
1635
+
1636
+ debug('tilde return', ret);
1637
+ return ret
1638
+ })
1639
+ };
1640
+
1641
+ // ^ --> * (any, kinda silly)
1642
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0-0
1643
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0-0
1644
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0-0
1645
+ // ^1.2.3 --> >=1.2.3 <2.0.0-0
1646
+ // ^1.2.0 --> >=1.2.0 <2.0.0-0
1647
+ // ^0.0.1 --> >=0.0.1 <0.0.2-0
1648
+ // ^0.1.0 --> >=0.1.0 <0.2.0-0
1649
+ const replaceCarets = (comp, options) => {
1650
+ return comp
1651
+ .trim()
1652
+ .split(/\s+/)
1653
+ .map((c) => replaceCaret(c, options))
1654
+ .join(' ')
1655
+ };
1656
+
1657
+ const replaceCaret = (comp, options) => {
1658
+ debug('caret', comp, options);
1659
+ const r = options.loose ? re[t.CARETLOOSE] : re[t.CARET];
1660
+ const z = options.includePrerelease ? '-0' : '';
1661
+ return comp.replace(r, (_, M, m, p, pr) => {
1662
+ debug('caret', comp, _, M, m, p, pr);
1663
+ let ret;
1664
+
1665
+ if (isX(M)) {
1666
+ ret = '';
1667
+ } else if (isX(m)) {
1668
+ ret = `>=${M}.0.0${z} <${+M + 1}.0.0-0`;
1669
+ } else if (isX(p)) {
1670
+ if (M === '0') {
1671
+ ret = `>=${M}.${m}.0${z} <${M}.${+m + 1}.0-0`;
1672
+ } else {
1673
+ ret = `>=${M}.${m}.0${z} <${+M + 1}.0.0-0`;
1674
+ }
1675
+ } else if (pr) {
1676
+ debug('replaceCaret pr', pr);
1677
+ if (M === '0') {
1678
+ if (m === '0') {
1679
+ ret = `>=${M}.${m}.${p}-${pr
1680
+ } <${M}.${m}.${+p + 1}-0`;
1681
+ } else {
1682
+ ret = `>=${M}.${m}.${p}-${pr
1683
+ } <${M}.${+m + 1}.0-0`;
1684
+ }
1685
+ } else {
1686
+ ret = `>=${M}.${m}.${p}-${pr
1687
+ } <${+M + 1}.0.0-0`;
1688
+ }
1689
+ } else {
1690
+ debug('no pr');
1691
+ if (M === '0') {
1692
+ if (m === '0') {
1693
+ ret = `>=${M}.${m}.${p
1694
+ }${z} <${M}.${m}.${+p + 1}-0`;
1695
+ } else {
1696
+ ret = `>=${M}.${m}.${p
1697
+ }${z} <${M}.${+m + 1}.0-0`;
1698
+ }
1699
+ } else {
1700
+ ret = `>=${M}.${m}.${p
1701
+ } <${+M + 1}.0.0-0`;
1702
+ }
1703
+ }
1704
+
1705
+ debug('caret return', ret);
1706
+ return ret
1707
+ })
1708
+ };
1709
+
1710
+ const replaceXRanges = (comp, options) => {
1711
+ debug('replaceXRanges', comp, options);
1712
+ return comp
1713
+ .split(/\s+/)
1714
+ .map((c) => replaceXRange(c, options))
1715
+ .join(' ')
1716
+ };
1717
+
1718
+ const replaceXRange = (comp, options) => {
1719
+ comp = comp.trim();
1720
+ const r = options.loose ? re[t.XRANGELOOSE] : re[t.XRANGE];
1721
+ return comp.replace(r, (ret, gtlt, M, m, p, pr) => {
1722
+ debug('xRange', comp, ret, gtlt, M, m, p, pr);
1723
+ const xM = isX(M);
1724
+ const xm = xM || isX(m);
1725
+ const xp = xm || isX(p);
1726
+ const anyX = xp;
1727
+
1728
+ if (gtlt === '=' && anyX) {
1729
+ gtlt = '';
1730
+ }
1731
+
1732
+ // if we're including prereleases in the match, then we need
1733
+ // to fix this to -0, the lowest possible prerelease value
1734
+ pr = options.includePrerelease ? '-0' : '';
1735
+
1736
+ if (xM) {
1737
+ if (gtlt === '>' || gtlt === '<') {
1738
+ // nothing is allowed
1739
+ ret = '<0.0.0-0';
1740
+ } else {
1741
+ // nothing is forbidden
1742
+ ret = '*';
1743
+ }
1744
+ } else if (gtlt && anyX) {
1745
+ // we know patch is an x, because we have any x at all.
1746
+ // replace X with 0
1747
+ if (xm) {
1748
+ m = 0;
1749
+ }
1750
+ p = 0;
1751
+
1752
+ if (gtlt === '>') {
1753
+ // >1 => >=2.0.0
1754
+ // >1.2 => >=1.3.0
1755
+ gtlt = '>=';
1756
+ if (xm) {
1757
+ M = +M + 1;
1758
+ m = 0;
1759
+ p = 0;
1760
+ } else {
1761
+ m = +m + 1;
1762
+ p = 0;
1763
+ }
1764
+ } else if (gtlt === '<=') {
1765
+ // <=0.7.x is actually <0.8.0, since any 0.7.x should
1766
+ // pass. Similarly, <=7.x is actually <8.0.0, etc.
1767
+ gtlt = '<';
1768
+ if (xm) {
1769
+ M = +M + 1;
1770
+ } else {
1771
+ m = +m + 1;
1772
+ }
1773
+ }
1774
+
1775
+ if (gtlt === '<') {
1776
+ pr = '-0';
1777
+ }
1778
+
1779
+ ret = `${gtlt + M}.${m}.${p}${pr}`;
1780
+ } else if (xm) {
1781
+ ret = `>=${M}.0.0${pr} <${+M + 1}.0.0-0`;
1782
+ } else if (xp) {
1783
+ ret = `>=${M}.${m}.0${pr
1784
+ } <${M}.${+m + 1}.0-0`;
1785
+ }
1786
+
1787
+ debug('xRange return', ret);
1788
+
1789
+ return ret
1790
+ })
1791
+ };
1792
+
1793
+ // Because * is AND-ed with everything else in the comparator,
1794
+ // and '' means "any version", just remove the *s entirely.
1795
+ const replaceStars = (comp, options) => {
1796
+ debug('replaceStars', comp, options);
1797
+ // Looseness is ignored here. star is always as loose as it gets!
1798
+ return comp
1799
+ .trim()
1800
+ .replace(re[t.STAR], '')
1801
+ };
1802
+
1803
+ const replaceGTE0 = (comp, options) => {
1804
+ debug('replaceGTE0', comp, options);
1805
+ return comp
1806
+ .trim()
1807
+ .replace(re[options.includePrerelease ? t.GTE0PRE : t.GTE0], '')
1808
+ };
1809
+
1810
+ // This function is passed to string.replace(re[t.HYPHENRANGE])
1811
+ // M, m, patch, prerelease, build
1812
+ // 1.2 - 3.4.5 => >=1.2.0 <=3.4.5
1813
+ // 1.2.3 - 3.4 => >=1.2.0 <3.5.0-0 Any 3.4.x will do
1814
+ // 1.2 - 3.4 => >=1.2.0 <3.5.0-0
1815
+ // TODO build?
1816
+ const hyphenReplace = incPr => ($0,
1817
+ from, fM, fm, fp, fpr, fb,
1818
+ to, tM, tm, tp, tpr) => {
1819
+ if (isX(fM)) {
1820
+ from = '';
1821
+ } else if (isX(fm)) {
1822
+ from = `>=${fM}.0.0${incPr ? '-0' : ''}`;
1823
+ } else if (isX(fp)) {
1824
+ from = `>=${fM}.${fm}.0${incPr ? '-0' : ''}`;
1825
+ } else if (fpr) {
1826
+ from = `>=${from}`;
1827
+ } else {
1828
+ from = `>=${from}${incPr ? '-0' : ''}`;
1829
+ }
1830
+
1831
+ if (isX(tM)) {
1832
+ to = '';
1833
+ } else if (isX(tm)) {
1834
+ to = `<${+tM + 1}.0.0-0`;
1835
+ } else if (isX(tp)) {
1836
+ to = `<${tM}.${+tm + 1}.0-0`;
1837
+ } else if (tpr) {
1838
+ to = `<=${tM}.${tm}.${tp}-${tpr}`;
1839
+ } else if (incPr) {
1840
+ to = `<${tM}.${tm}.${+tp + 1}-0`;
1841
+ } else {
1842
+ to = `<=${to}`;
1843
+ }
1844
+
1845
+ return `${from} ${to}`.trim()
1846
+ };
1847
+
1848
+ const testSet = (set, version, options) => {
1849
+ for (let i = 0; i < set.length; i++) {
1850
+ if (!set[i].test(version)) {
1851
+ return false
1852
+ }
1853
+ }
1854
+
1855
+ if (version.prerelease.length && !options.includePrerelease) {
1856
+ // Find the set of versions that are allowed to have prereleases
1857
+ // For example, ^1.2.3-pr.1 desugars to >=1.2.3-pr.1 <2.0.0
1858
+ // That should allow `1.2.3-pr.2` to pass.
1859
+ // However, `1.2.4-alpha.notready` should NOT be allowed,
1860
+ // even though it's within the range set by the comparators.
1861
+ for (let i = 0; i < set.length; i++) {
1862
+ debug(set[i].semver);
1863
+ if (set[i].semver === Comparator.ANY) {
1864
+ continue
1865
+ }
1866
+
1867
+ if (set[i].semver.prerelease.length > 0) {
1868
+ const allowed = set[i].semver;
1869
+ if (allowed.major === version.major &&
1870
+ allowed.minor === version.minor &&
1871
+ allowed.patch === version.patch) {
1872
+ return true
1873
+ }
1874
+ }
1875
+ }
1876
+
1877
+ // Version has a -pre, but it's not one of the ones we like.
1878
+ return false
1879
+ }
1880
+
1881
+ return true
1882
+ };
1883
+ return range;
1884
+ }
1885
+
1886
+ var comparator;
1887
+ var hasRequiredComparator;
1888
+
1889
+ function requireComparator () {
1890
+ if (hasRequiredComparator) return comparator;
1891
+ hasRequiredComparator = 1;
1892
+
1893
+ const ANY = Symbol('SemVer ANY');
1894
+ // hoisted class for cyclic dependency
1895
+ class Comparator {
1896
+ static get ANY () {
1897
+ return ANY
1898
+ }
1899
+
1900
+ constructor (comp, options) {
1901
+ options = parseOptions(options);
1902
+
1903
+ if (comp instanceof Comparator) {
1904
+ if (comp.loose === !!options.loose) {
1905
+ return comp
1906
+ } else {
1907
+ comp = comp.value;
1908
+ }
1909
+ }
1910
+
1911
+ comp = comp.trim().split(/\s+/).join(' ');
1912
+ debug('comparator', comp, options);
1913
+ this.options = options;
1914
+ this.loose = !!options.loose;
1915
+ this.parse(comp);
1916
+
1917
+ if (this.semver === ANY) {
1918
+ this.value = '';
1919
+ } else {
1920
+ this.value = this.operator + this.semver.version;
1921
+ }
1922
+
1923
+ debug('comp', this);
1924
+ }
1925
+
1926
+ parse (comp) {
1927
+ const r = this.options.loose ? re[t.COMPARATORLOOSE] : re[t.COMPARATOR];
1928
+ const m = comp.match(r);
1929
+
1930
+ if (!m) {
1931
+ throw new TypeError(`Invalid comparator: ${comp}`)
1932
+ }
1933
+
1934
+ this.operator = m[1] !== undefined ? m[1] : '';
1935
+ if (this.operator === '=') {
1936
+ this.operator = '';
1937
+ }
1938
+
1939
+ // if it literally is just '>' or '' then allow anything.
1940
+ if (!m[2]) {
1941
+ this.semver = ANY;
1942
+ } else {
1943
+ this.semver = new SemVer(m[2], this.options.loose);
1944
+ }
1945
+ }
1946
+
1947
+ toString () {
1948
+ return this.value
1949
+ }
1950
+
1951
+ test (version) {
1952
+ debug('Comparator.test', version, this.options.loose);
1953
+
1954
+ if (this.semver === ANY || version === ANY) {
1955
+ return true
1956
+ }
1957
+
1958
+ if (typeof version === 'string') {
1959
+ try {
1960
+ version = new SemVer(version, this.options);
1961
+ } catch (er) {
1962
+ return false
1963
+ }
1964
+ }
1965
+
1966
+ return cmp(version, this.operator, this.semver, this.options)
1967
+ }
1968
+
1969
+ intersects (comp, options) {
1970
+ if (!(comp instanceof Comparator)) {
1971
+ throw new TypeError('a Comparator is required')
1972
+ }
1973
+
1974
+ if (this.operator === '') {
1975
+ if (this.value === '') {
1976
+ return true
1977
+ }
1978
+ return new Range(comp.value, options).test(this.value)
1979
+ } else if (comp.operator === '') {
1980
+ if (comp.value === '') {
1981
+ return true
1982
+ }
1983
+ return new Range(this.value, options).test(comp.semver)
1984
+ }
1985
+
1986
+ options = parseOptions(options);
1987
+
1988
+ // Special cases where nothing can possibly be lower
1989
+ if (options.includePrerelease &&
1990
+ (this.value === '<0.0.0-0' || comp.value === '<0.0.0-0')) {
1991
+ return false
1992
+ }
1993
+ if (!options.includePrerelease &&
1994
+ (this.value.startsWith('<0.0.0') || comp.value.startsWith('<0.0.0'))) {
1995
+ return false
1996
+ }
1997
+
1998
+ // Same direction increasing (> or >=)
1999
+ if (this.operator.startsWith('>') && comp.operator.startsWith('>')) {
2000
+ return true
2001
+ }
2002
+ // Same direction decreasing (< or <=)
2003
+ if (this.operator.startsWith('<') && comp.operator.startsWith('<')) {
2004
+ return true
2005
+ }
2006
+ // same SemVer and both sides are inclusive (<= or >=)
2007
+ if (
2008
+ (this.semver.version === comp.semver.version) &&
2009
+ this.operator.includes('=') && comp.operator.includes('=')) {
2010
+ return true
2011
+ }
2012
+ // opposite directions less than
2013
+ if (cmp(this.semver, '<', comp.semver, options) &&
2014
+ this.operator.startsWith('>') && comp.operator.startsWith('<')) {
2015
+ return true
2016
+ }
2017
+ // opposite directions greater than
2018
+ if (cmp(this.semver, '>', comp.semver, options) &&
2019
+ this.operator.startsWith('<') && comp.operator.startsWith('>')) {
2020
+ return true
2021
+ }
2022
+ return false
2023
+ }
2024
+ }
2025
+
2026
+ comparator = Comparator;
2027
+
2028
+ const parseOptions = requireParseOptions();
2029
+ const { safeRe: re, t } = requireRe();
2030
+ const cmp = requireCmp();
2031
+ const debug = requireDebug();
2032
+ const SemVer = requireSemver$1();
2033
+ const Range = requireRange();
2034
+ return comparator;
2035
+ }
2036
+
2037
+ var satisfies_1;
2038
+ var hasRequiredSatisfies;
2039
+
2040
+ function requireSatisfies () {
2041
+ if (hasRequiredSatisfies) return satisfies_1;
2042
+ hasRequiredSatisfies = 1;
2043
+
2044
+ const Range = requireRange();
2045
+ const satisfies = (version, range, options) => {
2046
+ try {
2047
+ range = new Range(range, options);
2048
+ } catch (er) {
2049
+ return false
2050
+ }
2051
+ return range.test(version)
2052
+ };
2053
+ satisfies_1 = satisfies;
2054
+ return satisfies_1;
2055
+ }
2056
+
2057
+ var toComparators_1;
2058
+ var hasRequiredToComparators;
2059
+
2060
+ function requireToComparators () {
2061
+ if (hasRequiredToComparators) return toComparators_1;
2062
+ hasRequiredToComparators = 1;
2063
+
2064
+ const Range = requireRange();
2065
+
2066
+ // Mostly just for testing and legacy API reasons
2067
+ const toComparators = (range, options) =>
2068
+ new Range(range, options).set
2069
+ .map(comp => comp.map(c => c.value).join(' ').trim().split(' '));
2070
+
2071
+ toComparators_1 = toComparators;
2072
+ return toComparators_1;
2073
+ }
2074
+
2075
+ var maxSatisfying_1;
2076
+ var hasRequiredMaxSatisfying;
2077
+
2078
+ function requireMaxSatisfying () {
2079
+ if (hasRequiredMaxSatisfying) return maxSatisfying_1;
2080
+ hasRequiredMaxSatisfying = 1;
2081
+
2082
+ const SemVer = requireSemver$1();
2083
+ const Range = requireRange();
2084
+
2085
+ const maxSatisfying = (versions, range, options) => {
2086
+ let max = null;
2087
+ let maxSV = null;
2088
+ let rangeObj = null;
2089
+ try {
2090
+ rangeObj = new Range(range, options);
2091
+ } catch (er) {
2092
+ return null
2093
+ }
2094
+ versions.forEach((v) => {
2095
+ if (rangeObj.test(v)) {
2096
+ // satisfies(v, range, options)
2097
+ if (!max || maxSV.compare(v) === -1) {
2098
+ // compare(max, v, true)
2099
+ max = v;
2100
+ maxSV = new SemVer(max, options);
2101
+ }
2102
+ }
2103
+ });
2104
+ return max
2105
+ };
2106
+ maxSatisfying_1 = maxSatisfying;
2107
+ return maxSatisfying_1;
2108
+ }
2109
+
2110
+ var minSatisfying_1;
2111
+ var hasRequiredMinSatisfying;
2112
+
2113
+ function requireMinSatisfying () {
2114
+ if (hasRequiredMinSatisfying) return minSatisfying_1;
2115
+ hasRequiredMinSatisfying = 1;
2116
+
2117
+ const SemVer = requireSemver$1();
2118
+ const Range = requireRange();
2119
+ const minSatisfying = (versions, range, options) => {
2120
+ let min = null;
2121
+ let minSV = null;
2122
+ let rangeObj = null;
2123
+ try {
2124
+ rangeObj = new Range(range, options);
2125
+ } catch (er) {
2126
+ return null
2127
+ }
2128
+ versions.forEach((v) => {
2129
+ if (rangeObj.test(v)) {
2130
+ // satisfies(v, range, options)
2131
+ if (!min || minSV.compare(v) === 1) {
2132
+ // compare(min, v, true)
2133
+ min = v;
2134
+ minSV = new SemVer(min, options);
2135
+ }
2136
+ }
2137
+ });
2138
+ return min
2139
+ };
2140
+ minSatisfying_1 = minSatisfying;
2141
+ return minSatisfying_1;
2142
+ }
2143
+
2144
+ var minVersion_1;
2145
+ var hasRequiredMinVersion;
2146
+
2147
+ function requireMinVersion () {
2148
+ if (hasRequiredMinVersion) return minVersion_1;
2149
+ hasRequiredMinVersion = 1;
2150
+
2151
+ const SemVer = requireSemver$1();
2152
+ const Range = requireRange();
2153
+ const gt = requireGt();
2154
+
2155
+ const minVersion = (range, loose) => {
2156
+ range = new Range(range, loose);
2157
+
2158
+ let minver = new SemVer('0.0.0');
2159
+ if (range.test(minver)) {
2160
+ return minver
2161
+ }
2162
+
2163
+ minver = new SemVer('0.0.0-0');
2164
+ if (range.test(minver)) {
2165
+ return minver
2166
+ }
2167
+
2168
+ minver = null;
2169
+ for (let i = 0; i < range.set.length; ++i) {
2170
+ const comparators = range.set[i];
2171
+
2172
+ let setMin = null;
2173
+ comparators.forEach((comparator) => {
2174
+ // Clone to avoid manipulating the comparator's semver object.
2175
+ const compver = new SemVer(comparator.semver.version);
2176
+ switch (comparator.operator) {
2177
+ case '>':
2178
+ if (compver.prerelease.length === 0) {
2179
+ compver.patch++;
2180
+ } else {
2181
+ compver.prerelease.push(0);
2182
+ }
2183
+ compver.raw = compver.format();
2184
+ /* fallthrough */
2185
+ case '':
2186
+ case '>=':
2187
+ if (!setMin || gt(compver, setMin)) {
2188
+ setMin = compver;
2189
+ }
2190
+ break
2191
+ case '<':
2192
+ case '<=':
2193
+ /* Ignore maximum versions */
2194
+ break
2195
+ /* istanbul ignore next */
2196
+ default:
2197
+ throw new Error(`Unexpected operation: ${comparator.operator}`)
2198
+ }
2199
+ });
2200
+ if (setMin && (!minver || gt(minver, setMin))) {
2201
+ minver = setMin;
2202
+ }
2203
+ }
2204
+
2205
+ if (minver && range.test(minver)) {
2206
+ return minver
2207
+ }
2208
+
2209
+ return null
2210
+ };
2211
+ minVersion_1 = minVersion;
2212
+ return minVersion_1;
2213
+ }
2214
+
2215
+ var valid;
2216
+ var hasRequiredValid;
2217
+
2218
+ function requireValid () {
2219
+ if (hasRequiredValid) return valid;
2220
+ hasRequiredValid = 1;
2221
+
2222
+ const Range = requireRange();
2223
+ const validRange = (range, options) => {
2224
+ try {
2225
+ // Return '*' instead of '' so that truthiness works.
2226
+ // This will throw if it's invalid anyway
2227
+ return new Range(range, options).range || '*'
2228
+ } catch (er) {
2229
+ return null
2230
+ }
2231
+ };
2232
+ valid = validRange;
2233
+ return valid;
2234
+ }
2235
+
2236
+ var outside_1;
2237
+ var hasRequiredOutside;
2238
+
2239
+ function requireOutside () {
2240
+ if (hasRequiredOutside) return outside_1;
2241
+ hasRequiredOutside = 1;
2242
+
2243
+ const SemVer = requireSemver$1();
2244
+ const Comparator = requireComparator();
2245
+ const { ANY } = Comparator;
2246
+ const Range = requireRange();
2247
+ const satisfies = requireSatisfies();
2248
+ const gt = requireGt();
2249
+ const lt = requireLt();
2250
+ const lte = requireLte();
2251
+ const gte = requireGte();
2252
+
2253
+ const outside = (version, range, hilo, options) => {
2254
+ version = new SemVer(version, options);
2255
+ range = new Range(range, options);
2256
+
2257
+ let gtfn, ltefn, ltfn, comp, ecomp;
2258
+ switch (hilo) {
2259
+ case '>':
2260
+ gtfn = gt;
2261
+ ltefn = lte;
2262
+ ltfn = lt;
2263
+ comp = '>';
2264
+ ecomp = '>=';
2265
+ break
2266
+ case '<':
2267
+ gtfn = lt;
2268
+ ltefn = gte;
2269
+ ltfn = gt;
2270
+ comp = '<';
2271
+ ecomp = '<=';
2272
+ break
2273
+ default:
2274
+ throw new TypeError('Must provide a hilo val of "<" or ">"')
2275
+ }
2276
+
2277
+ // If it satisfies the range it is not outside
2278
+ if (satisfies(version, range, options)) {
2279
+ return false
2280
+ }
2281
+
2282
+ // From now on, variable terms are as if we're in "gtr" mode.
2283
+ // but note that everything is flipped for the "ltr" function.
2284
+
2285
+ for (let i = 0; i < range.set.length; ++i) {
2286
+ const comparators = range.set[i];
2287
+
2288
+ let high = null;
2289
+ let low = null;
2290
+
2291
+ comparators.forEach((comparator) => {
2292
+ if (comparator.semver === ANY) {
2293
+ comparator = new Comparator('>=0.0.0');
2294
+ }
2295
+ high = high || comparator;
2296
+ low = low || comparator;
2297
+ if (gtfn(comparator.semver, high.semver, options)) {
2298
+ high = comparator;
2299
+ } else if (ltfn(comparator.semver, low.semver, options)) {
2300
+ low = comparator;
2301
+ }
2302
+ });
2303
+
2304
+ // If the edge version comparator has a operator then our version
2305
+ // isn't outside it
2306
+ if (high.operator === comp || high.operator === ecomp) {
2307
+ return false
2308
+ }
2309
+
2310
+ // If the lowest version comparator has an operator and our version
2311
+ // is less than it then it isn't higher than the range
2312
+ if ((!low.operator || low.operator === comp) &&
2313
+ ltefn(version, low.semver)) {
2314
+ return false
2315
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
2316
+ return false
2317
+ }
2318
+ }
2319
+ return true
2320
+ };
2321
+
2322
+ outside_1 = outside;
2323
+ return outside_1;
2324
+ }
2325
+
2326
+ var gtr_1;
2327
+ var hasRequiredGtr;
2328
+
2329
+ function requireGtr () {
2330
+ if (hasRequiredGtr) return gtr_1;
2331
+ hasRequiredGtr = 1;
2332
+
2333
+ // Determine if version is greater than all the versions possible in the range.
2334
+ const outside = requireOutside();
2335
+ const gtr = (version, range, options) => outside(version, range, '>', options);
2336
+ gtr_1 = gtr;
2337
+ return gtr_1;
2338
+ }
2339
+
2340
+ var ltr_1;
2341
+ var hasRequiredLtr;
2342
+
2343
+ function requireLtr () {
2344
+ if (hasRequiredLtr) return ltr_1;
2345
+ hasRequiredLtr = 1;
2346
+
2347
+ const outside = requireOutside();
2348
+ // Determine if version is less than all the versions possible in the range
2349
+ const ltr = (version, range, options) => outside(version, range, '<', options);
2350
+ ltr_1 = ltr;
2351
+ return ltr_1;
2352
+ }
2353
+
2354
+ var intersects_1;
2355
+ var hasRequiredIntersects;
2356
+
2357
+ function requireIntersects () {
2358
+ if (hasRequiredIntersects) return intersects_1;
2359
+ hasRequiredIntersects = 1;
2360
+
2361
+ const Range = requireRange();
2362
+ const intersects = (r1, r2, options) => {
2363
+ r1 = new Range(r1, options);
2364
+ r2 = new Range(r2, options);
2365
+ return r1.intersects(r2, options)
2366
+ };
2367
+ intersects_1 = intersects;
2368
+ return intersects_1;
2369
+ }
2370
+
2371
+ var simplify;
2372
+ var hasRequiredSimplify;
2373
+
2374
+ function requireSimplify () {
2375
+ if (hasRequiredSimplify) return simplify;
2376
+ hasRequiredSimplify = 1;
2377
+
2378
+ // given a set of versions and a range, create a "simplified" range
2379
+ // that includes the same versions that the original range does
2380
+ // If the original range is shorter than the simplified one, return that.
2381
+ const satisfies = requireSatisfies();
2382
+ const compare = requireCompare();
2383
+ simplify = (versions, range, options) => {
2384
+ const set = [];
2385
+ let first = null;
2386
+ let prev = null;
2387
+ const v = versions.sort((a, b) => compare(a, b, options));
2388
+ for (const version of v) {
2389
+ const included = satisfies(version, range, options);
2390
+ if (included) {
2391
+ prev = version;
2392
+ if (!first) {
2393
+ first = version;
2394
+ }
2395
+ } else {
2396
+ if (prev) {
2397
+ set.push([first, prev]);
2398
+ }
2399
+ prev = null;
2400
+ first = null;
2401
+ }
2402
+ }
2403
+ if (first) {
2404
+ set.push([first, null]);
2405
+ }
2406
+
2407
+ const ranges = [];
2408
+ for (const [min, max] of set) {
2409
+ if (min === max) {
2410
+ ranges.push(min);
2411
+ } else if (!max && min === v[0]) {
2412
+ ranges.push('*');
2413
+ } else if (!max) {
2414
+ ranges.push(`>=${min}`);
2415
+ } else if (min === v[0]) {
2416
+ ranges.push(`<=${max}`);
2417
+ } else {
2418
+ ranges.push(`${min} - ${max}`);
2419
+ }
2420
+ }
2421
+ const simplified = ranges.join(' || ');
2422
+ const original = typeof range.raw === 'string' ? range.raw : String(range);
2423
+ return simplified.length < original.length ? simplified : range
2424
+ };
2425
+ return simplify;
2426
+ }
2427
+
2428
+ var subset_1;
2429
+ var hasRequiredSubset;
2430
+
2431
+ function requireSubset () {
2432
+ if (hasRequiredSubset) return subset_1;
2433
+ hasRequiredSubset = 1;
2434
+
2435
+ const Range = requireRange();
2436
+ const Comparator = requireComparator();
2437
+ const { ANY } = Comparator;
2438
+ const satisfies = requireSatisfies();
2439
+ const compare = requireCompare();
2440
+
2441
+ // Complex range `r1 || r2 || ...` is a subset of `R1 || R2 || ...` iff:
2442
+ // - Every simple range `r1, r2, ...` is a null set, OR
2443
+ // - Every simple range `r1, r2, ...` which is not a null set is a subset of
2444
+ // some `R1, R2, ...`
2445
+ //
2446
+ // Simple range `c1 c2 ...` is a subset of simple range `C1 C2 ...` iff:
2447
+ // - If c is only the ANY comparator
2448
+ // - If C is only the ANY comparator, return true
2449
+ // - Else if in prerelease mode, return false
2450
+ // - else replace c with `[>=0.0.0]`
2451
+ // - If C is only the ANY comparator
2452
+ // - if in prerelease mode, return true
2453
+ // - else replace C with `[>=0.0.0]`
2454
+ // - Let EQ be the set of = comparators in c
2455
+ // - If EQ is more than one, return true (null set)
2456
+ // - Let GT be the highest > or >= comparator in c
2457
+ // - Let LT be the lowest < or <= comparator in c
2458
+ // - If GT and LT, and GT.semver > LT.semver, return true (null set)
2459
+ // - If any C is a = range, and GT or LT are set, return false
2460
+ // - If EQ
2461
+ // - If GT, and EQ does not satisfy GT, return true (null set)
2462
+ // - If LT, and EQ does not satisfy LT, return true (null set)
2463
+ // - If EQ satisfies every C, return true
2464
+ // - Else return false
2465
+ // - If GT
2466
+ // - If GT.semver is lower than any > or >= comp in C, return false
2467
+ // - If GT is >=, and GT.semver does not satisfy every C, return false
2468
+ // - If GT.semver has a prerelease, and not in prerelease mode
2469
+ // - If no C has a prerelease and the GT.semver tuple, return false
2470
+ // - If LT
2471
+ // - If LT.semver is greater than any < or <= comp in C, return false
2472
+ // - If LT is <=, and LT.semver does not satisfy every C, return false
2473
+ // - If LT.semver has a prerelease, and not in prerelease mode
2474
+ // - If no C has a prerelease and the LT.semver tuple, return false
2475
+ // - Else return true
2476
+
2477
+ const subset = (sub, dom, options = {}) => {
2478
+ if (sub === dom) {
2479
+ return true
2480
+ }
2481
+
2482
+ sub = new Range(sub, options);
2483
+ dom = new Range(dom, options);
2484
+ let sawNonNull = false;
2485
+
2486
+ OUTER: for (const simpleSub of sub.set) {
2487
+ for (const simpleDom of dom.set) {
2488
+ const isSub = simpleSubset(simpleSub, simpleDom, options);
2489
+ sawNonNull = sawNonNull || isSub !== null;
2490
+ if (isSub) {
2491
+ continue OUTER
2492
+ }
2493
+ }
2494
+ // the null set is a subset of everything, but null simple ranges in
2495
+ // a complex range should be ignored. so if we saw a non-null range,
2496
+ // then we know this isn't a subset, but if EVERY simple range was null,
2497
+ // then it is a subset.
2498
+ if (sawNonNull) {
2499
+ return false
2500
+ }
2501
+ }
2502
+ return true
2503
+ };
2504
+
2505
+ const minimumVersionWithPreRelease = [new Comparator('>=0.0.0-0')];
2506
+ const minimumVersion = [new Comparator('>=0.0.0')];
2507
+
2508
+ const simpleSubset = (sub, dom, options) => {
2509
+ if (sub === dom) {
2510
+ return true
2511
+ }
2512
+
2513
+ if (sub.length === 1 && sub[0].semver === ANY) {
2514
+ if (dom.length === 1 && dom[0].semver === ANY) {
2515
+ return true
2516
+ } else if (options.includePrerelease) {
2517
+ sub = minimumVersionWithPreRelease;
2518
+ } else {
2519
+ sub = minimumVersion;
2520
+ }
2521
+ }
2522
+
2523
+ if (dom.length === 1 && dom[0].semver === ANY) {
2524
+ if (options.includePrerelease) {
2525
+ return true
2526
+ } else {
2527
+ dom = minimumVersion;
2528
+ }
2529
+ }
2530
+
2531
+ const eqSet = new Set();
2532
+ let gt, lt;
2533
+ for (const c of sub) {
2534
+ if (c.operator === '>' || c.operator === '>=') {
2535
+ gt = higherGT(gt, c, options);
2536
+ } else if (c.operator === '<' || c.operator === '<=') {
2537
+ lt = lowerLT(lt, c, options);
2538
+ } else {
2539
+ eqSet.add(c.semver);
2540
+ }
2541
+ }
2542
+
2543
+ if (eqSet.size > 1) {
2544
+ return null
2545
+ }
2546
+
2547
+ let gtltComp;
2548
+ if (gt && lt) {
2549
+ gtltComp = compare(gt.semver, lt.semver, options);
2550
+ if (gtltComp > 0) {
2551
+ return null
2552
+ } else if (gtltComp === 0 && (gt.operator !== '>=' || lt.operator !== '<=')) {
2553
+ return null
2554
+ }
2555
+ }
2556
+
2557
+ // will iterate one or zero times
2558
+ for (const eq of eqSet) {
2559
+ if (gt && !satisfies(eq, String(gt), options)) {
2560
+ return null
2561
+ }
2562
+
2563
+ if (lt && !satisfies(eq, String(lt), options)) {
2564
+ return null
2565
+ }
2566
+
2567
+ for (const c of dom) {
2568
+ if (!satisfies(eq, String(c), options)) {
2569
+ return false
2570
+ }
2571
+ }
2572
+
2573
+ return true
2574
+ }
2575
+
2576
+ let higher, lower;
2577
+ let hasDomLT, hasDomGT;
2578
+ // if the subset has a prerelease, we need a comparator in the superset
2579
+ // with the same tuple and a prerelease, or it's not a subset
2580
+ let needDomLTPre = lt &&
2581
+ !options.includePrerelease &&
2582
+ lt.semver.prerelease.length ? lt.semver : false;
2583
+ let needDomGTPre = gt &&
2584
+ !options.includePrerelease &&
2585
+ gt.semver.prerelease.length ? gt.semver : false;
2586
+ // exception: <1.2.3-0 is the same as <1.2.3
2587
+ if (needDomLTPre && needDomLTPre.prerelease.length === 1 &&
2588
+ lt.operator === '<' && needDomLTPre.prerelease[0] === 0) {
2589
+ needDomLTPre = false;
2590
+ }
2591
+
2592
+ for (const c of dom) {
2593
+ hasDomGT = hasDomGT || c.operator === '>' || c.operator === '>=';
2594
+ hasDomLT = hasDomLT || c.operator === '<' || c.operator === '<=';
2595
+ if (gt) {
2596
+ if (needDomGTPre) {
2597
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2598
+ c.semver.major === needDomGTPre.major &&
2599
+ c.semver.minor === needDomGTPre.minor &&
2600
+ c.semver.patch === needDomGTPre.patch) {
2601
+ needDomGTPre = false;
2602
+ }
2603
+ }
2604
+ if (c.operator === '>' || c.operator === '>=') {
2605
+ higher = higherGT(gt, c, options);
2606
+ if (higher === c && higher !== gt) {
2607
+ return false
2608
+ }
2609
+ } else if (gt.operator === '>=' && !satisfies(gt.semver, String(c), options)) {
2610
+ return false
2611
+ }
2612
+ }
2613
+ if (lt) {
2614
+ if (needDomLTPre) {
2615
+ if (c.semver.prerelease && c.semver.prerelease.length &&
2616
+ c.semver.major === needDomLTPre.major &&
2617
+ c.semver.minor === needDomLTPre.minor &&
2618
+ c.semver.patch === needDomLTPre.patch) {
2619
+ needDomLTPre = false;
2620
+ }
2621
+ }
2622
+ if (c.operator === '<' || c.operator === '<=') {
2623
+ lower = lowerLT(lt, c, options);
2624
+ if (lower === c && lower !== lt) {
2625
+ return false
2626
+ }
2627
+ } else if (lt.operator === '<=' && !satisfies(lt.semver, String(c), options)) {
2628
+ return false
2629
+ }
2630
+ }
2631
+ if (!c.operator && (lt || gt) && gtltComp !== 0) {
2632
+ return false
2633
+ }
2634
+ }
2635
+
2636
+ // if there was a < or >, and nothing in the dom, then must be false
2637
+ // UNLESS it was limited by another range in the other direction.
2638
+ // Eg, >1.0.0 <1.0.1 is still a subset of <2.0.0
2639
+ if (gt && hasDomLT && !lt && gtltComp !== 0) {
2640
+ return false
2641
+ }
2642
+
2643
+ if (lt && hasDomGT && !gt && gtltComp !== 0) {
2644
+ return false
2645
+ }
2646
+
2647
+ // we needed a prerelease range in a specific tuple, but didn't get one
2648
+ // then this isn't a subset. eg >=1.2.3-pre is not a subset of >=1.0.0,
2649
+ // because it includes prereleases in the 1.2.3 tuple
2650
+ if (needDomGTPre || needDomLTPre) {
2651
+ return false
2652
+ }
2653
+
2654
+ return true
2655
+ };
2656
+
2657
+ // >=1.2.3 is lower than >1.2.3
2658
+ const higherGT = (a, b, options) => {
2659
+ if (!a) {
2660
+ return b
2661
+ }
2662
+ const comp = compare(a.semver, b.semver, options);
2663
+ return comp > 0 ? a
2664
+ : comp < 0 ? b
2665
+ : b.operator === '>' && a.operator === '>=' ? b
2666
+ : a
2667
+ };
2668
+
2669
+ // <=1.2.3 is higher than <1.2.3
2670
+ const lowerLT = (a, b, options) => {
2671
+ if (!a) {
2672
+ return b
2673
+ }
2674
+ const comp = compare(a.semver, b.semver, options);
2675
+ return comp < 0 ? a
2676
+ : comp > 0 ? b
2677
+ : b.operator === '<' && a.operator === '<=' ? b
2678
+ : a
2679
+ };
2680
+
2681
+ subset_1 = subset;
2682
+ return subset_1;
2683
+ }
2684
+
2685
+ var semver$1;
2686
+ var hasRequiredSemver;
2687
+
2688
+ function requireSemver () {
2689
+ if (hasRequiredSemver) return semver$1;
2690
+ hasRequiredSemver = 1;
2691
+
2692
+ // just pre-load all the stuff that index.js lazily exports
2693
+ const internalRe = requireRe();
2694
+ const constants = requireConstants();
2695
+ const SemVer = requireSemver$1();
2696
+ const identifiers = requireIdentifiers();
2697
+ const parse = requireParse();
2698
+ const valid = requireValid$1();
2699
+ const clean = requireClean();
2700
+ const inc = requireInc();
2701
+ const diff = requireDiff();
2702
+ const major = requireMajor();
2703
+ const minor = requireMinor();
2704
+ const patch = requirePatch();
2705
+ const prerelease = requirePrerelease();
2706
+ const compare = requireCompare();
2707
+ const rcompare = requireRcompare();
2708
+ const compareLoose = requireCompareLoose();
2709
+ const compareBuild = requireCompareBuild();
2710
+ const sort = requireSort();
2711
+ const rsort = requireRsort();
2712
+ const gt = requireGt();
2713
+ const lt = requireLt();
2714
+ const eq = requireEq();
2715
+ const neq = requireNeq();
2716
+ const gte = requireGte();
2717
+ const lte = requireLte();
2718
+ const cmp = requireCmp();
2719
+ const coerce = requireCoerce();
2720
+ const Comparator = requireComparator();
2721
+ const Range = requireRange();
2722
+ const satisfies = requireSatisfies();
2723
+ const toComparators = requireToComparators();
2724
+ const maxSatisfying = requireMaxSatisfying();
2725
+ const minSatisfying = requireMinSatisfying();
2726
+ const minVersion = requireMinVersion();
2727
+ const validRange = requireValid();
2728
+ const outside = requireOutside();
2729
+ const gtr = requireGtr();
2730
+ const ltr = requireLtr();
2731
+ const intersects = requireIntersects();
2732
+ const simplifyRange = requireSimplify();
2733
+ const subset = requireSubset();
2734
+ semver$1 = {
2735
+ parse,
2736
+ valid,
2737
+ clean,
2738
+ inc,
2739
+ diff,
2740
+ major,
2741
+ minor,
2742
+ patch,
2743
+ prerelease,
2744
+ compare,
2745
+ rcompare,
2746
+ compareLoose,
2747
+ compareBuild,
2748
+ sort,
2749
+ rsort,
2750
+ gt,
2751
+ lt,
2752
+ eq,
2753
+ neq,
2754
+ gte,
2755
+ lte,
2756
+ cmp,
2757
+ coerce,
2758
+ Comparator,
2759
+ Range,
2760
+ satisfies,
2761
+ toComparators,
2762
+ maxSatisfying,
2763
+ minSatisfying,
2764
+ minVersion,
2765
+ validRange,
2766
+ outside,
2767
+ gtr,
2768
+ ltr,
2769
+ intersects,
2770
+ simplifyRange,
2771
+ subset,
2772
+ SemVer,
2773
+ re: internalRe.re,
2774
+ src: internalRe.src,
2775
+ tokens: internalRe.t,
2776
+ SEMVER_SPEC_VERSION: constants.SEMVER_SPEC_VERSION,
2777
+ RELEASE_TYPES: constants.RELEASE_TYPES,
2778
+ compareIdentifiers: identifiers.compareIdentifiers,
2779
+ rcompareIdentifiers: identifiers.rcompareIdentifiers,
2780
+ };
2781
+ return semver$1;
2782
+ }
2783
+
2784
+ var semverExports = requireSemver();
2785
+ var semver = /*@__PURE__*/getDefaultExportFromCjs(semverExports);
2786
+
2787
+ /**
2788
+ * 不依赖 `import.meta`,兼容 Webpack 4/5、Vue CLI、Vite、Rspack 等宿主。
2789
+ * - Webpack / Vue CLI:依赖构建时注入的 `process.env`(如 `VUE_APP_*`、`DefinePlugin` 注入的 `VITE_*`)。
2790
+ * - Vite:在入口调用 `setWebExtendPluginEnv(import.meta.env)`,或 `installWebExtendPluginVue2(..., { env: import.meta.env })`。
2791
+ * - 也可在入口前设置 `globalThis.__WEP_ENV__ = import.meta.env`(与 setWebExtendPluginEnv 二选一即可)。
2792
+ *
2793
+ * @module bundled-env
2794
+ */
2795
+
2796
+ /** @type {Record<string, unknown> | null} */
2797
+ let _explicitEnv = null;
2798
+
2799
+ /**
2800
+ * 显式注入与 `import.meta.env` 同形态的对象(推荐 Vite 宿主在入口调用一次)。
2801
+ * @param {Record<string, unknown> | null | undefined} env
2802
+ */
2803
+ function setWebExtendPluginEnv(env) {
2804
+ _explicitEnv = env && typeof env === 'object' ? env : null;
2805
+ }
2806
+
2807
+ /**
2808
+ * @returns {Record<string, unknown> | null}
2809
+ */
2810
+ function getInjectedEnvObject() {
2811
+ if (_explicitEnv) {
2812
+ return _explicitEnv
2813
+ }
2814
+ try {
2815
+ const g = typeof globalThis !== 'undefined' ? globalThis : undefined;
2816
+ if (g && g.__WEP_ENV__ && typeof g.__WEP_ENV__ === 'object') {
2817
+ return g.__WEP_ENV__
2818
+ }
2819
+ } catch (_) {}
2820
+ return null
2821
+ }
2822
+
2823
+ /**
2824
+ * 从注入环境读取字符串配置键(`VITE_*` / `PLUGIN_*` 等)。
2825
+ * @param {string} key
2826
+ * @returns {string|undefined}
2827
+ */
2828
+ function readInjectedEnvKey(key) {
2829
+ const o = getInjectedEnvObject();
2830
+ if (!o || !(key in o)) {
2831
+ return undefined
2832
+ }
2833
+ const v = o[key];
2834
+ if (v === undefined || v === '') {
2835
+ return undefined
2836
+ }
2837
+ return String(v)
2838
+ }
2839
+
2840
+ /**
2841
+ * @returns {boolean}
2842
+ */
2843
+ function readInjectedEnvDev() {
2844
+ const o = getInjectedEnvObject();
2845
+ return !!(o && o.DEV === true)
2846
+ }
2847
+
2848
+ /**
2849
+ * 与 `plugin-web-starter`(WebPluginsResponse)返回的 `hostPluginApiVersion` 保持一致,用于契约校验。
2850
+ * @type {string}
2851
+ */
2852
+ const HOST_PLUGIN_API_VERSION = '1.0.0';
2853
+
2854
+ /**
2855
+ * 宿主侧插件引导:拉取清单、dev 映射、加载入口脚本、调用 activator。
2856
+ * 路径与白名单等默认值见 `defaultWebExtendPluginRuntime`,可通过 `resolveRuntimeOptions` / 环境变量覆盖。
2857
+ *
2858
+ * **Webpack 宿主**:用 `DefinePlugin` 注入 `process.env.VITE_*` 或 **`PLUGIN_*`**(等价键),或 `resolveRuntimeOptions` 显式传参。
2859
+ * **Vite 宿主**:入口调用 `setWebExtendPluginEnv(import.meta.env)`,或 `installWebExtendPluginVue2(..., { env: import.meta.env })`。
2860
+ *
2861
+ * @module PluginRuntime
2862
+ */
2863
+
2864
+ const DEF = defaultWebExtendPluginRuntime;
2865
+
2866
+ /**
2867
+ * @typedef {object} WebExtendPluginRuntimeOptions
2868
+ * @property {string} [manifestBase] 清单服务 URL 前缀
2869
+ * @property {string} [manifestListPath] 清单接口路径(以 `/` 开头),拼在 manifestBase 后
2870
+ * @property {RequestCredentials} [manifestFetchCredentials] 清单 fetch 的 credentials
2871
+ * @property {boolean} [isDev] 开发模式
2872
+ * @property {string} [webPluginDevOrigin] 插件 dev origin
2873
+ * @property {string} [webPluginDevIds] 逗号分隔 id,隐式 dev 映射
2874
+ * @property {string} [webPluginDevMapJson] 显式 dev 映射 JSON
2875
+ * @property {string} [webPluginDevEntryPath] 隐式 dev 入口路径(相对插件 dev origin)
2876
+ * @property {string} [devPingPath] dev 存活探测路径
2877
+ * @property {string} [devReloadSsePath] dev 热更新 SSE 路径
2878
+ * @property {number} [devPingTimeoutMs] 探测超时
2879
+ * @property {string[]} [defaultImplicitDevPluginIds] 无 `webPluginDevIds`/env 时用于隐式 dev 的 id;包内默认 `[]`
2880
+ * @property {string[]} [allowedScriptHosts] 允许加载脚本的主机名
2881
+ * @property {string[]} [bridgeAllowedPathPrefixes] bridge.request 白名单前缀
2882
+ * @property {boolean} [bootstrapSummary] bootstrap 结束是否打印摘要
2883
+ */
2884
+
2885
+ /**
2886
+ * 从 Webpack `DefinePlugin` 等注入的 `process.env` 读取。
2887
+ * @param {string} key
2888
+ * @returns {string|undefined}
2889
+ */
2890
+ function readProcessEnv(key) {
2891
+ try {
2892
+ if (typeof process !== 'undefined' && process.env && key in process.env) {
2893
+ const v = process.env[key];
2894
+ if (v !== undefined && v !== '') {
2895
+ return String(v)
2896
+ }
2897
+ }
2898
+ } catch (_) {}
2899
+ return undefined
2900
+ }
2901
+
2902
+ /**
2903
+ * `VITE_*` 的并列命名:同值可读 `PLUGIN_*`(`VITE_WEB_PLUGIN_X` → `PLUGIN_WEB_PLUGIN_X`)。
2904
+ * Vite 需在 `defineConfig({ envPrefix: ['VITE_', 'PLUGIN_'] })` 中暴露 `PLUGIN_`;Webpack 用 DefinePlugin 注入即可。
2905
+ * @param {string} viteStyleKey 以 `VITE_` 开头的键名
2906
+ * @returns {string|null}
2907
+ */
2908
+ function viteKeyToPluginAlternate(viteStyleKey) {
2909
+ if (typeof viteStyleKey !== 'string' || !viteStyleKey.startsWith('VITE_')) {
2910
+ return null
2911
+ }
2912
+ return `PLUGIN_${viteStyleKey.slice(5)}`
2913
+ }
2914
+
2915
+ /**
2916
+ * 先读注入环境(`setWebExtendPluginEnv` / `__WEP_ENV__`)中的 `VITE_*` 与并列 `PLUGIN_*`,再读 `process.env`,最后 `fallback`。
2917
+ * @param {string} key 仍以 `VITE_*` 为逻辑名(与文档一致)
2918
+ * @param {string} [fallback='']
2919
+ */
2920
+ function resolveBundledEnv(key, fallback = '') {
2921
+ const alt = viteKeyToPluginAlternate(key);
2922
+ const inj = readInjectedEnvKey(key);
2923
+ const fromInjected =
2924
+ inj === undefined || inj === null ? (alt ? readInjectedEnvKey(alt) : undefined) : inj;
2925
+ const proc = readProcessEnv(key);
2926
+ const fromProcess =
2927
+ proc === undefined || proc === null ? (alt ? readProcessEnv(alt) : undefined) : proc;
2928
+ const first = fromInjected === undefined || fromInjected === null ? fromProcess : fromInjected;
2929
+ return first === undefined || first === null ? fallback : first
2930
+ }
2931
+
2932
+ /**
2933
+ * @returns {boolean}
2934
+ */
2935
+ function resolveBundledIsDev() {
2936
+ try {
2937
+ if (readInjectedEnvDev()) {
2938
+ return true
2939
+ }
2940
+ } catch (_) {}
2941
+ try {
2942
+ if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development') {
2943
+ return true
2944
+ }
2945
+ } catch (_) {}
2946
+ return false
2947
+ }
2948
+
2949
+ /**
2950
+ * @param {string} p
2951
+ */
2952
+ function ensureLeadingPath(p) {
2953
+ const t = String(p || '').trim();
2954
+ if (!t) {
2955
+ return '/'
2956
+ }
2957
+ return t.startsWith('/') ? t : `/${t}`
2958
+ }
2959
+
2960
+ /**
2961
+ * 解析 `include` | `omit` | `same-origin`,非法时回退默认值。
2962
+ * @param {string|undefined} userVal
2963
+ * @param {string} envKey
2964
+ * @param {RequestCredentials} fallback
2965
+ */
2966
+ function resolveManifestCredentials(userVal, envKey, fallback) {
2967
+ if (userVal !== undefined && userVal !== '') {
2968
+ const s = String(userVal);
2969
+ if (s === 'include' || s === 'omit' || s === 'same-origin') {
2970
+ return s
2971
+ }
2972
+ }
2973
+ const e = resolveBundledEnv(envKey, '');
2974
+ if (e === 'include' || e === 'omit' || e === 'same-origin') {
2975
+ return e
2976
+ }
2977
+ return fallback
2978
+ }
2979
+
2980
+ /**
2981
+ * @param {number|undefined} userVal
2982
+ * @param {string} envKey
2983
+ * @param {number} fallback
2984
+ */
2985
+ function resolvePositiveInt(userVal, envKey, fallback) {
2986
+ if (typeof userVal === 'number' && Number.isFinite(userVal) && userVal > 0) {
2987
+ return Math.floor(userVal)
2988
+ }
2989
+ const raw = resolveBundledEnv(envKey, '');
2990
+ const n = raw ? parseInt(raw, 10) : NaN;
2991
+ if (Number.isFinite(n) && n > 0) {
2992
+ return n
2993
+ }
2994
+ return fallback
2995
+ }
2996
+
2997
+ /**
2998
+ * 合并用户、环境变量与 `defaultWebExtendPluginRuntime`,得到完整运行时选项(宿主可只传需要覆盖的字段)。
2999
+ * @param {WebExtendPluginRuntimeOptions} [user]
3000
+ * @returns {object}
3001
+ */
3002
+ function resolveRuntimeOptions(user = {}) {
3003
+ const manifestBaseRaw =
3004
+ user.manifestBase !== undefined && user.manifestBase !== ''
3005
+ ? String(user.manifestBase)
3006
+ : resolveBundledEnv('VITE_FRONTEND_PLUGIN_BASE', DEF.manifestBase) || DEF.manifestBase;
3007
+
3008
+ const manifestListPath = ensureLeadingPath(
3009
+ user.manifestListPath !== undefined && user.manifestListPath !== ''
3010
+ ? user.manifestListPath
3011
+ : resolveBundledEnv('VITE_WEB_PLUGIN_MANIFEST_PATH', DEF.manifestListPath)
3012
+ );
3013
+
3014
+ const defaultImplicitDevPluginIds =
3015
+ Array.isArray(user.defaultImplicitDevPluginIds)
3016
+ ? user.defaultImplicitDevPluginIds.map(String).filter(Boolean)
3017
+ : (() => {
3018
+ const e = resolveBundledEnv('VITE_WEB_PLUGIN_IMPLICIT_DEV_IDS', '');
3019
+ if (e) {
3020
+ return e
3021
+ .split(',')
3022
+ .map((s) => s.trim())
3023
+ .filter(Boolean)
3024
+ }
3025
+ return [...DEF.defaultImplicitDevPluginIds]
3026
+ })();
3027
+
3028
+ const allowedScriptHosts =
3029
+ Array.isArray(user.allowedScriptHosts) && user.allowedScriptHosts.length > 0
3030
+ ? user.allowedScriptHosts.map((h) => normalizeHost(String(h))).filter(Boolean)
3031
+ : (() => {
3032
+ const e = resolveBundledEnv('VITE_WEB_PLUGIN_ALLOWED_SCRIPT_HOSTS', '');
3033
+ if (e) {
3034
+ return e
3035
+ .split(',')
3036
+ .map((s) => normalizeHost(s.trim()))
3037
+ .filter(Boolean)
3038
+ }
3039
+ return [...DEF.allowedScriptHosts]
3040
+ })();
3041
+
3042
+ const bridgeAllowedPathPrefixes =
3043
+ Array.isArray(user.bridgeAllowedPathPrefixes) && user.bridgeAllowedPathPrefixes.length > 0
3044
+ ? user.bridgeAllowedPathPrefixes.map((p) => ensureLeadingPath(p)).filter(Boolean)
3045
+ : (() => {
3046
+ const e = resolveBundledEnv('VITE_WEB_PLUGIN_BRIDGE_PREFIXES', '');
3047
+ if (e) {
3048
+ return e
3049
+ .split(',')
3050
+ .map((s) => ensureLeadingPath(s.trim()))
3051
+ .filter(Boolean)
3052
+ }
3053
+ return [...DEF.bridgeAllowedPathPrefixes]
3054
+ })();
3055
+
3056
+ return {
3057
+ manifestBase: manifestBaseRaw.replace(/\/$/, '') || DEF.manifestBase.replace(/\/$/, ''),
3058
+ manifestListPath,
3059
+ manifestFetchCredentials: resolveManifestCredentials(
3060
+ user.manifestFetchCredentials,
3061
+ 'VITE_WEB_PLUGIN_MANIFEST_CREDENTIALS',
3062
+ DEF.manifestFetchCredentials
3063
+ ),
3064
+ isDev: user.isDev !== undefined ? user.isDev : resolveBundledIsDev(),
3065
+ webPluginDevOrigin:
3066
+ user.webPluginDevOrigin !== undefined ? user.webPluginDevOrigin : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_ORIGIN', ''),
3067
+ webPluginDevIds:
3068
+ user.webPluginDevIds !== undefined ? user.webPluginDevIds : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_IDS', ''),
3069
+ webPluginDevMapJson:
3070
+ user.webPluginDevMapJson !== undefined
3071
+ ? user.webPluginDevMapJson
3072
+ : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_MAP', ''),
3073
+ webPluginDevEntryPath: ensureLeadingPath(
3074
+ user.webPluginDevEntryPath !== undefined && user.webPluginDevEntryPath !== ''
3075
+ ? user.webPluginDevEntryPath
3076
+ : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_ENTRY', DEF.webPluginDevEntryPath)
3077
+ ),
3078
+ devPingPath: ensureLeadingPath(
3079
+ user.devPingPath !== undefined && user.devPingPath !== ''
3080
+ ? user.devPingPath
3081
+ : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_PING_PATH', DEF.devPingPath)
3082
+ ),
3083
+ devReloadSsePath: ensureLeadingPath(
3084
+ user.devReloadSsePath !== undefined && user.devReloadSsePath !== ''
3085
+ ? user.devReloadSsePath
3086
+ : resolveBundledEnv('VITE_WEB_PLUGIN_DEV_SSE_PATH', DEF.devReloadSsePath)
3087
+ ),
3088
+ devPingTimeoutMs: resolvePositiveInt(user.devPingTimeoutMs, 'VITE_WEB_PLUGIN_DEV_PING_TIMEOUT_MS', DEF.devPingTimeoutMs),
3089
+ defaultImplicitDevPluginIds,
3090
+ allowedScriptHosts,
3091
+ bridgeAllowedPathPrefixes,
3092
+ bootstrapSummary: user.bootstrapSummary
3093
+ }
3094
+ }
3095
+
3096
+ /**
3097
+ * @param {ReturnType<typeof resolveRuntimeOptions>} opts
3098
+ */
3099
+ function shouldShowBootstrapSummary(opts) {
3100
+ if (opts.bootstrapSummary === true) {
3101
+ return true
3102
+ }
3103
+ if (opts.bootstrapSummary === false) {
3104
+ return false
3105
+ }
3106
+ const env = resolveBundledEnv('VITE_PLUGINS_BOOTSTRAP_SUMMARY', '');
3107
+ if (env === '0' || env === 'false') {
3108
+ return false
3109
+ }
3110
+ if (env === '1' || env === 'true') {
3111
+ return true
3112
+ }
3113
+ return resolveBundledIsDev()
3114
+ }
3115
+
3116
+ /**
3117
+ * @param {string} hostname
3118
+ */
3119
+ function normalizeHost(hostname) {
3120
+ if (!hostname) {
3121
+ return ''
3122
+ }
3123
+ const h = hostname.toLowerCase();
3124
+ if (h.startsWith('[') && h.endsWith(']')) {
3125
+ return h.slice(1, -1)
3126
+ }
3127
+ return h
3128
+ }
3129
+
3130
+ /**
3131
+ * @param {string[]} hostnames
3132
+ * @returns {Set<string>}
3133
+ */
3134
+ function buildAllowedScriptHostsSet(hostnames) {
3135
+ const s = new Set();
3136
+ for (const h of hostnames) {
3137
+ const n = normalizeHost(h);
3138
+ if (n) {
3139
+ s.add(n);
3140
+ }
3141
+ }
3142
+ return s
3143
+ }
3144
+
3145
+ /**
3146
+ * @param {string} url
3147
+ * @param {Set<string>} hostSet
3148
+ */
3149
+ function isScriptHostAllowed(url, hostSet) {
3150
+ if (typeof window === 'undefined') {
3151
+ return false
3152
+ }
3153
+ try {
3154
+ const u = new URL(url, window.location.origin);
3155
+ const h = normalizeHost(u.hostname);
3156
+ return hostSet.has(h)
3157
+ } catch {
3158
+ return false
3159
+ }
3160
+ }
3161
+
3162
+ /**
3163
+ * @param {ReturnType<typeof resolveRuntimeOptions>} opts
3164
+ */
3165
+ function parseWebPluginDevMapExplicit(opts) {
3166
+ if (!opts.isDev) {
3167
+ return null
3168
+ }
3169
+ const raw = opts.webPluginDevMapJson;
3170
+ if (raw === undefined || raw === null || String(raw).trim() === '') {
3171
+ return null
3172
+ }
3173
+ try {
3174
+ const map = JSON.parse(String(raw));
3175
+ return map && typeof map === 'object' ? map : null
3176
+ } catch {
3177
+ console.warn('[plugins] webPluginDevMapJson / VITE_WEB_PLUGIN_DEV_MAP is not valid JSON');
3178
+ return null
3179
+ }
3180
+ }
3181
+
3182
+ /**
3183
+ * @param {ReturnType<typeof resolveRuntimeOptions>} opts
3184
+ * @param {Set<string>} hostSet
3185
+ */
3186
+ async function buildImplicitWebPluginDevMap(opts, hostSet) {
3187
+ if (!opts.isDev) {
3188
+ return {}
3189
+ }
3190
+ const origin =
3191
+ opts.webPluginDevOrigin === undefined || opts.webPluginDevOrigin === null
3192
+ ? ''
3193
+ : String(opts.webPluginDevOrigin).trim();
3194
+ if (!origin) {
3195
+ return {}
3196
+ }
3197
+ if (!isScriptHostAllowed(`${origin}/`, hostSet)) {
3198
+ return {}
3199
+ }
3200
+
3201
+ const idsRaw = opts.webPluginDevIds;
3202
+ const ids =
3203
+ idsRaw !== undefined && idsRaw !== null && String(idsRaw).trim() !== ''
3204
+ ? String(idsRaw)
3205
+ .split(',')
3206
+ .map((s) => s.trim())
3207
+ .filter(Boolean)
3208
+ : [...opts.defaultImplicitDevPluginIds];
3209
+
3210
+ if (ids.length === 0) {
3211
+ return {}
3212
+ }
3213
+
3214
+ const base = origin.replace(/\/$/, '');
3215
+ const pingUrl = `${base}${opts.devPingPath}`;
3216
+ try {
3217
+ const ctrl = new AbortController();
3218
+ const timer = setTimeout(() => ctrl.abort(), opts.devPingTimeoutMs);
3219
+ const r = await fetch(pingUrl, {
3220
+ mode: 'cors',
3221
+ cache: 'no-store',
3222
+ signal: ctrl.signal
3223
+ });
3224
+ clearTimeout(timer);
3225
+ if (!r.ok) {
3226
+ return {}
3227
+ }
3228
+ const body = (await r.text()).trim();
3229
+ if (body !== 'ok') {
3230
+ return {}
3231
+ }
3232
+ } catch {
3233
+ return {}
3234
+ }
3235
+
3236
+ const pathPart = opts.webPluginDevEntryPath;
3237
+ const map = {};
3238
+ for (const id of ids) {
3239
+ map[id] = `${base}${pathPart}`;
3240
+ }
3241
+ if (ids.length) {
3242
+ console.info(
3243
+ '[plugins] 已检测到插件 dev 服务(',
3244
+ base,
3245
+ '),下列 id 将加载隐式 dev 入口(',
3246
+ pathPart,
3247
+ ')而非清单 dist:',
3248
+ ids.join(', ')
3249
+ );
3250
+ }
3251
+ return map
3252
+ }
3253
+
3254
+ /**
3255
+ * @param {Record<string, string>} implicit
3256
+ * @param {Record<string, string>|null} explicit
3257
+ */
3258
+ function mergeDevMaps(implicit, explicit) {
3259
+ const i = implicit && typeof implicit === 'object' ? implicit : {};
3260
+ const e = explicit && typeof explicit === 'object' ? explicit : {};
3261
+ return { ...i, ...e }
3262
+ }
3263
+
3264
+ /** @type {Map<string, EventSource>} */
3265
+ const pluginDevEventSources = new Map();
3266
+
3267
+ let pluginDevBeforeUnloadRegistered = false;
3268
+
3269
+ function closeAllPluginDevEventSources() {
3270
+ for (const es of pluginDevEventSources.values()) {
3271
+ try {
3272
+ es.close();
3273
+ } catch (_) {}
3274
+ }
3275
+ pluginDevEventSources.clear();
3276
+ }
3277
+
3278
+ function ensurePluginDevBeforeUnload() {
3279
+ if (pluginDevBeforeUnloadRegistered || typeof window === 'undefined') {
3280
+ return
3281
+ }
3282
+ pluginDevBeforeUnloadRegistered = true;
3283
+ window.addEventListener('beforeunload', closeAllPluginDevEventSources);
3284
+ }
3285
+
3286
+ /**
3287
+ * @param {string} origin
3288
+ * @param {Set<string>} hostSet
3289
+ */
3290
+ function isDevOriginAllowedForSse(origin, hostSet) {
3291
+ try {
3292
+ const u = new URL(origin);
3293
+ return hostSet.has(normalizeHost(u.hostname))
3294
+ } catch {
3295
+ return false
3296
+ }
3297
+ }
3298
+
3299
+ /**
3300
+ * @param {string} origin
3301
+ * @param {boolean} isDev
3302
+ * @param {Set<string>} hostSet
3303
+ * @param {string} ssePath
3304
+ */
3305
+ function startPluginDevReloadSse(origin, isDev, hostSet, ssePath) {
3306
+ if (!isDev || pluginDevEventSources.has(origin)) {
3307
+ return
3308
+ }
3309
+ if (!isDevOriginAllowedForSse(origin, hostSet)) {
3310
+ return
3311
+ }
3312
+ ensurePluginDevBeforeUnload();
3313
+ const base = origin.replace(/\/$/, '');
3314
+ const url = `${base}${ssePath}`;
3315
+ try {
3316
+ const es = new EventSource(url);
3317
+ pluginDevEventSources.set(origin, es);
3318
+ es.addEventListener('reload', () => {
3319
+ window.location.reload();
3320
+ });
3321
+ es.onopen = () => {
3322
+ console.info('[plugins] plugin dev reload SSE:', url);
3323
+ };
3324
+ } catch (e) {
3325
+ console.warn('[plugins] EventSource failed', url, e);
3326
+ }
3327
+ }
3328
+
3329
+ /**
3330
+ * @param {Record<string, string>|null|undefined} devMap
3331
+ * @param {boolean} isDev
3332
+ * @param {Set<string>} hostSet
3333
+ * @param {string} ssePath
3334
+ */
3335
+ function startPluginDevSseForMap(devMap, isDev, hostSet, ssePath) {
3336
+ if (!isDev || !devMap || typeof window === 'undefined') {
3337
+ return
3338
+ }
3339
+ const origins = new Set();
3340
+ for (const entry of Object.values(devMap)) {
3341
+ if (typeof entry !== 'string') {
3342
+ continue
3343
+ }
3344
+ const t = entry.trim();
3345
+ if (!t) {
3346
+ continue
3347
+ }
3348
+ try {
3349
+ origins.add(new URL(t, window.location.href).origin);
3350
+ } catch {
3351
+ /* skip */
3352
+ }
3353
+ }
3354
+ for (const o of origins) {
3355
+ startPluginDevReloadSse(o, isDev, hostSet, ssePath);
3356
+ }
3357
+ }
3358
+
3359
+ const loadScriptMemo = new Map();
3360
+
3361
+ function loadScript(src) {
3362
+ if (typeof document === 'undefined') {
3363
+ return Promise.reject(new Error('loadScript: no document'))
3364
+ }
3365
+ if (loadScriptMemo.has(src)) {
3366
+ return loadScriptMemo.get(src)
3367
+ }
3368
+ const p = new Promise((resolve, reject) => {
3369
+ const scripts = document.getElementsByTagName('script');
3370
+ for (let i = 0; i < scripts.length; i++) {
3371
+ const el = scripts[i];
3372
+ if (el.src === src) {
3373
+ if (el.getAttribute('data-wep-loaded') === 'true') {
3374
+ resolve();
3375
+ return
3376
+ }
3377
+ el.addEventListener(
3378
+ 'load',
3379
+ () => {
3380
+ el.setAttribute('data-wep-loaded', 'true');
3381
+ resolve();
3382
+ },
3383
+ { once: true }
3384
+ );
3385
+ el.addEventListener('error', () => reject(new Error('loadScript failed: ' + src)), { once: true });
3386
+ return
3387
+ }
3388
+ }
3389
+ const s = document.createElement('script');
3390
+ s.async = true;
3391
+ s.src = src;
3392
+ s.onload = () => {
3393
+ s.setAttribute('data-wep-loaded', 'true');
3394
+ resolve();
3395
+ };
3396
+ s.onerror = () => reject(new Error('loadScript failed: ' + src));
3397
+ document.head.appendChild(s);
3398
+ });
3399
+ loadScriptMemo.set(src, p);
3400
+ p.catch(() => loadScriptMemo.delete(src));
3401
+ return p
3402
+ }
3403
+
3404
+ /**
3405
+ * @param {{ id: string }} p
3406
+ * @param {string} [entryUrl]
3407
+ * @param {Record<string, string>|null|undefined} devMap
3408
+ * @param {Set<string>} hostSet
3409
+ */
3410
+ async function loadPluginEntry(p, entryUrl, devMap, hostSet) {
3411
+ const devEntry = devMap && typeof devMap[p.id] === 'string' ? devMap[p.id].trim() : '';
3412
+ if (devEntry) {
3413
+ if (!isScriptHostAllowed(devEntry, hostSet)) {
3414
+ console.warn('[plugins] dev entry URL not allowed', p.id, devEntry);
3415
+ return
3416
+ }
3417
+ try {
3418
+ await import(
3419
+ /* webpackIgnore: true */
3420
+ /* @vite-ignore */
3421
+ devEntry
3422
+ );
3423
+ } catch (e) {
3424
+ console.warn('[plugins] dev module import failed, try manifest entryUrl', p.id, e);
3425
+ if (entryUrl && isScriptHostAllowed(entryUrl, hostSet)) {
3426
+ await loadScript(entryUrl);
3427
+ }
3428
+ return
3429
+ }
3430
+ return
3431
+ }
3432
+ if (!entryUrl || !isScriptHostAllowed(entryUrl, hostSet)) {
3433
+ console.warn('[plugins] skip (entryUrl not allowed)', p.id, entryUrl);
3434
+ return
3435
+ }
3436
+ await loadScript(entryUrl);
3437
+ }
3438
+
3439
+ /**
3440
+ * @param {import('vue-router').default} router
3441
+ * @param {(pluginId: string, router: import('vue-router').default, hostKit?: { bridgeAllowedPathPrefixes: string[] }) => object} createHostApiFactory
3442
+ * 始终传入三个参数;单参工厂 `(id) => createHostApi(id, router)` 仍可用,后两个实参被忽略。
3443
+ * @param {WebExtendPluginRuntimeOptions} [runtimeOptions]
3444
+ */
3445
+ async function bootstrapPlugins(router, createHostApiFactory, runtimeOptions) {
3446
+ if (typeof window === 'undefined') {
3447
+ console.warn('[plugins] bootstrapPlugins skipped: requires browser (window)');
3448
+ return
3449
+ }
3450
+ const opts = resolveRuntimeOptions(runtimeOptions || {});
3451
+ const base = String(opts.manifestBase).replace(/\/$/, '');
3452
+ const manifestUrl = `${base}${opts.manifestListPath}`;
3453
+ const hostSet = buildAllowedScriptHostsSet(opts.allowedScriptHosts);
3454
+ const explicit = parseWebPluginDevMapExplicit(opts);
3455
+
3456
+ const [manifestResult, implicit] = await Promise.all([
3457
+ (async () => {
3458
+ try {
3459
+ const res = await fetch(manifestUrl, { credentials: opts.manifestFetchCredentials });
3460
+ if (!res.ok) {
3461
+ return { ok: false, status: res.status, data: null }
3462
+ }
3463
+ const data = await res.json();
3464
+ return { ok: true, data }
3465
+ } catch (e) {
3466
+ return { ok: false, error: e, data: null }
3467
+ }
3468
+ })(),
3469
+ buildImplicitWebPluginDevMap(opts, hostSet)
3470
+ ]);
3471
+
3472
+ const devMap = mergeDevMaps(implicit, explicit);
3473
+ startPluginDevSseForMap(devMap, opts.isDev, hostSet, opts.devReloadSsePath);
3474
+
3475
+ const hostKit = { bridgeAllowedPathPrefixes: opts.bridgeAllowedPathPrefixes };
3476
+
3477
+ if (!manifestResult.ok) {
3478
+ if (manifestResult.error) {
3479
+ console.warn('[plugins] fetch manifest failed', manifestResult.error);
3480
+ } else {
3481
+ console.warn('[plugins] manifest HTTP', manifestResult.status, manifestUrl);
3482
+ }
3483
+ if (shouldShowBootstrapSummary(opts)) {
3484
+ console.info('[plugins] bootstrap_summary', { ok: false, reason: 'manifest_fetch' });
3485
+ }
3486
+ return
3487
+ }
3488
+ /** @type {{ hostPluginApiVersion?: string, plugins?: object[] }} */
3489
+ const data = manifestResult.data;
3490
+ if (!data) {
3491
+ if (shouldShowBootstrapSummary(opts)) {
3492
+ console.info('[plugins] bootstrap_summary', { ok: false, reason: 'manifest_empty_body' });
3493
+ }
3494
+ return
3495
+ }
3496
+
3497
+ const apiVer = data.hostPluginApiVersion;
3498
+ if (apiVer) {
3499
+ const coerced = semver.coerce(apiVer);
3500
+ const maj = coerced ? coerced.major : 0;
3501
+ const range = `^${maj}.0.0`;
3502
+ if (!semver.satisfies(HOST_PLUGIN_API_VERSION, range, { includePrerelease: true })) {
3503
+ console.warn(
3504
+ '[plugins] host API version mismatch: host implements',
3505
+ HOST_PLUGIN_API_VERSION,
3506
+ 'server declares',
3507
+ apiVer
3508
+ );
3509
+ }
3510
+ }
3511
+
3512
+ window.__PLUGIN_ACTIVATORS__ = window.__PLUGIN_ACTIVATORS__ || {};
3513
+
3514
+ const plugins = data.plugins || [];
3515
+ if (plugins.length === 0) {
3516
+ console.info(
3517
+ '[plugins] 清单为空。请检查:① 后端清单服务(plugin-web-starter)是否已接入;② web-plugin.web-plugins-dir 是否指向含各插件子目录及 manifest.json 的路径;③ 浏览器直接访问',
3518
+ manifestUrl,
3519
+ '是否返回 plugins 条目。'
3520
+ );
3521
+ }
3522
+
3523
+ const summary = {
3524
+ manifestCount: plugins.length,
3525
+ activated: 0,
3526
+ skipEngines: 0,
3527
+ skipLoad: 0,
3528
+ skipNoActivator: 0,
3529
+ activateFail: 0
3530
+ };
3531
+
3532
+ for (const p of plugins) {
3533
+ const range = p.engines && p.engines.host;
3534
+ if (range && !semver.satisfies(HOST_PLUGIN_API_VERSION, range, { includePrerelease: true })) {
3535
+ console.warn('[plugins] skip (engines.host)', p.id, range);
3536
+ summary.skipEngines++;
3537
+ continue
3538
+ }
3539
+ const entryUrl = p.entryUrl;
3540
+ try {
3541
+ await loadPluginEntry(p, entryUrl, devMap, hostSet);
3542
+ } catch (e) {
3543
+ console.warn('[plugins] script load failed', p.id, e);
3544
+ summary.skipLoad++;
3545
+ continue
3546
+ }
3547
+ const activator = window.__PLUGIN_ACTIVATORS__[p.id];
3548
+ if (typeof activator !== 'function') {
3549
+ console.warn('[plugins] no activator for', p.id);
3550
+ summary.skipNoActivator++;
3551
+ continue
3552
+ }
3553
+ const hostApi = createHostApiFactory(p.id, router, hostKit);
3554
+ try {
3555
+ activator(hostApi);
3556
+ summary.activated++;
3557
+ } catch (e) {
3558
+ console.error('[plugins] activate failed', p.id, e);
3559
+ summary.activateFail++;
3560
+ }
3561
+ }
3562
+
3563
+ if (shouldShowBootstrapSummary(opts)) {
3564
+ console.info('[plugins] bootstrap_summary', { ok: true, ...summary });
3565
+ }
3566
+ }
3567
+
3568
+ /**
3569
+ * 插件通过宿主访问后端的受控通道:仅允许配置的前缀路径,默认 `/api/`;强制默认 `same-origin` 携带 Cookie。
3570
+ * 前缀列表由 `createRequestBridge({ allowedPathPrefixes })` 传入,与 `defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes` 对齐。
3571
+ *
3572
+ * @module bridge
3573
+ */
3574
+
3575
+ /**
3576
+ * @param {string} p
3577
+ */
3578
+ function ensureLeadingSlash(p) {
3579
+ const t = String(p || '').trim();
3580
+ if (!t) {
3581
+ return '/'
3582
+ }
3583
+ return t.startsWith('/') ? t : `/${t}`
3584
+ }
3585
+
3586
+ /**
3587
+ * @param {{ allowedPathPrefixes?: string[] }} [config]
3588
+ */
3589
+ function createRequestBridge(config = {}) {
3590
+ const raw =
3591
+ Array.isArray(config.allowedPathPrefixes) && config.allowedPathPrefixes.length > 0
3592
+ ? config.allowedPathPrefixes
3593
+ : defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes;
3594
+ const allowedPathPrefixes = raw.map((p) => ensureLeadingSlash(p));
3595
+
3596
+ return {
3597
+ /**
3598
+ * 发起受控 `fetch`。
3599
+ * @param {string} path 必须以 `/` 开头,且匹配某一 `allowedPathPrefixes` 前缀
3600
+ * @param {RequestInit} [init] 会与默认 `{ credentials: 'same-origin' }` 合并(后者可被覆盖)
3601
+ */
3602
+ async request(path, init = {}) {
3603
+ if (typeof path !== 'string' || !path.startsWith('/')) {
3604
+ throw new Error('[bridge] path must be a string starting with /')
3605
+ }
3606
+ const allowed = allowedPathPrefixes.some((p) => path.startsWith(p));
3607
+ if (!allowed) {
3608
+ throw new Error('[bridge] path not allowed: ' + path)
3609
+ }
3610
+ return fetch(path, {
3611
+ credentials: 'same-origin',
3612
+ ...init
3613
+ })
3614
+ }
3615
+ }
3616
+ }
3617
+
3618
+ /**
3619
+ * 宿主全局响应式注册表:菜单与扩展点槽位,供布局与 `ExtensionPoint` 订阅。
3620
+ *
3621
+ * @module registries
3622
+ */
3623
+
3624
+ /**
3625
+ * @type {{
3626
+ * menus: object[],
3627
+ * slots: Record<string, Array<{ pluginId: string, component: import('vue').Component, priority: number, key: string }>>
3628
+ * }}
3629
+ */
3630
+ const registries = Vue.observable({
3631
+ menus: [],
3632
+ /** 扩展点 id → 已注册组件列表(内容区 / 工具栏等共用模型) */
3633
+ slots: {},
3634
+ /**
3635
+ * 每次变更 slots 时递增,供 ExtensionPoint 计算属性显式依赖。
3636
+ * Vue 2 对「先访问不存在的 slots[key]、后 Vue.set 补 key」的依赖收集不可靠,会导致扩展点不刷新。
3637
+ */
3638
+ slotRevision: 0
3639
+ });
3640
+
3641
+ /**
3642
+ * 按 `pluginId` 收集 `onTeardown` 回调,供 `disposeWebPlugin` 统一执行。
3643
+ *
3644
+ * @module teardown-registry
3645
+ */
3646
+
3647
+ /** @type {Map<string, Function[]>} */
3648
+ const byPlugin = new Map();
3649
+
3650
+ /**
3651
+ * 登记插件卸载时要执行的同步回调(建议只做解绑、清定时器等轻量逻辑)。
3652
+ * @param {string} pluginId
3653
+ * @param {() => void} fn
3654
+ */
3655
+ function registerPluginTeardown(pluginId, fn) {
3656
+ if (typeof fn !== 'function') {
3657
+ return
3658
+ }
3659
+ let arr = byPlugin.get(pluginId);
3660
+ if (!arr) {
3661
+ arr = [];
3662
+ byPlugin.set(pluginId, arr);
3663
+ }
3664
+ arr.push(fn);
3665
+ }
3666
+
3667
+ /**
3668
+ * 执行并清空该插件已登记的全部 teardown;调用后 Map 中不再保留该 id。
3669
+ * @param {string} pluginId
3670
+ */
3671
+ function runPluginTeardowns(pluginId) {
3672
+ const arr = byPlugin.get(pluginId);
3673
+ if (!arr) {
3674
+ return
3675
+ }
3676
+ byPlugin.delete(pluginId);
3677
+ for (const fn of arr) {
3678
+ try {
3679
+ fn();
3680
+ } catch (e) {
3681
+ console.warn('[plugins] teardown failed', pluginId, e);
3682
+ }
3683
+ }
3684
+ }
3685
+
3686
+ /**
3687
+ * 构造供插件 activator 调用的宿主 API(路由、菜单、扩展点、资源注入等)。
3688
+ * 与打包工具无关;Webpack 宿主需已配置 `vue-loader` 以编译本包内的 `.vue` 依赖。
3689
+ *
3690
+ * @module createHostApi
3691
+ */
3692
+
3693
+ /** 扩展点列表项 key 递增,避免用 Date.now() 导致列表重排时误卸载组件 */
3694
+ let slotItemKeySeq = 0;
3695
+ /** 无 name 的动态路由合成名递增,避免多次 registerRoutes 重名 */
3696
+ let routeSynthSeq = 0;
3697
+
3698
+ /**
3699
+ * @typedef {object} RegisterSlotEntry
3700
+ * @property {import('vue').Component} component
3701
+ * @property {number} [priority]
3702
+ */
3703
+
3704
+ /**
3705
+ * @typedef {object} HostApi
3706
+ * @property {string} hostPluginApiVersion 宿主实现的协议版本
3707
+ * @property {(routes: import('vue-router').RouteConfig[]) => void} registerRoutes 注册路由;无 `name` 时自动生成稳定合成名;优先 `router.addRoute`
3708
+ * @property {(items: object[]) => void} registerMenuItems 注册菜单并按 `order` 排序
3709
+ * @property {(pointId: string, components: RegisterSlotEntry[]) => void} registerSlotComponents 向扩展点挂载组件
3710
+ * @property {(urls?: string[]) => void} registerStylesheetUrls 注入 `link[rel=stylesheet]`,带 `data-plugin-asset`
3711
+ * @property {(urls?: string[]) => void} registerScriptUrls 顺序注入外链脚本
3712
+ * @property {() => void} registerSanitizedHtmlSnippet MVP 未实现,调用即抛错
3713
+ * @property {() => ReturnType<typeof createRequestBridge>} getBridge 受控 `fetch` 代理
3714
+ * @property {(pluginId: string, fn: () => void) => void} onTeardown 注册卸载回调;由 `disposeWebPlugin(pluginId)` 触发
3715
+ */
3716
+
3717
+ /**
3718
+ * @typedef {object} HostKitOptions
3719
+ * @property {string[]} [bridgeAllowedPathPrefixes] 覆盖 `getBridge().request` 允许的 URL 前缀;默认见 `defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes`
3720
+ */
3721
+
3722
+ /**
3723
+ * 创建单个插件在宿主侧的 API 句柄,传入插件 `activator(hostApi)`。
3724
+ *
3725
+ * `bootstrapPlugins` 始终以 `(pluginId, router, hostKitOptions)` 调用工厂;请使用 `(id, r, kit) => createHostApi(id, r, kit)` 传入 `bridgeAllowedPathPrefixes`。
3726
+ * 单参工厂 `(id) => createHostApi(id, router)` 仍可用(忽略后两个实参),此时 bridge 仅用包内默认前缀。
3727
+ *
3728
+ * @param {string} pluginId 与 manifest.id 一致
3729
+ * @param {import('vue-router').default} router 宿主 Vue Router 实例(vue-router@3)
3730
+ * @param {HostKitOptions} [hostKitOptions]
3731
+ * @returns {HostApi}
3732
+ */
3733
+ function createHostApi(pluginId, router, hostKitOptions = {}) {
3734
+ const bridgePrefixes =
3735
+ Array.isArray(hostKitOptions.bridgeAllowedPathPrefixes) &&
3736
+ hostKitOptions.bridgeAllowedPathPrefixes.length > 0
3737
+ ? hostKitOptions.bridgeAllowedPathPrefixes
3738
+ : defaultWebExtendPluginRuntime.bridgeAllowedPathPrefixes;
3739
+ const bridge = createRequestBridge({ allowedPathPrefixes: bridgePrefixes });
3740
+
3741
+ /**
3742
+ * 注入样式表;`disposeWebPlugin` 会按 `data-plugin-asset` 移除对应节点。
3743
+ * @param {string} href
3744
+ */
3745
+ function injectStylesheet(href) {
3746
+ const link = document.createElement('link');
3747
+ link.rel = 'stylesheet';
3748
+ link.href = href;
3749
+ link.setAttribute('data-plugin-asset', pluginId);
3750
+ document.head.appendChild(link);
3751
+ }
3752
+
3753
+ /**
3754
+ * 注入外链脚本(用于插件额外资源,非清单主入口)。
3755
+ * @param {string} src
3756
+ * @returns {Promise<void>}
3757
+ */
3758
+ function injectScript(src) {
3759
+ return new Promise((resolve, reject) => {
3760
+ const s = document.createElement('script');
3761
+ s.async = true;
3762
+ s.src = src;
3763
+ s.setAttribute('data-plugin-asset', pluginId);
3764
+ s.onload = () => resolve();
3765
+ s.onerror = () => reject(new Error('script failed: ' + src));
3766
+ document.head.appendChild(s);
3767
+ })
3768
+ }
3769
+
3770
+ return {
3771
+ hostPluginApiVersion: HOST_PLUGIN_API_VERSION,
3772
+
3773
+ /**
3774
+ * 动态注册路由。Vue Router 3.5+ 推荐 `addRoute`;若不存在则回退已弃用的 `addRoutes`。
3775
+ * @param {import('vue-router').RouteConfig[]} routes
3776
+ */
3777
+ registerRoutes(routes) {
3778
+ const wrapped = routes.map((r) => ({
3779
+ ...r,
3780
+ name: r.name || `__wep_${pluginId}_${routeSynthSeq++}`,
3781
+ meta: { ...(r.meta || {}), pluginId }
3782
+ }));
3783
+ if (typeof router.addRoute === 'function') {
3784
+ for (const r of wrapped) {
3785
+ router.addRoute(r);
3786
+ }
3787
+ } else {
3788
+ router.addRoutes(wrapped);
3789
+ }
3790
+ },
3791
+
3792
+ /**
3793
+ * 写入全局菜单注册表(响应式);按 `order` 升序排列。
3794
+ * @param {object[]} items
3795
+ */
3796
+ registerMenuItems(items) {
3797
+ for (const item of items) {
3798
+ registries.menus.push({ ...item, pluginId });
3799
+ }
3800
+ registries.menus.sort(
3801
+ (a, b) => (a.order != null ? a.order : 0) - (b.order != null ? b.order : 0)
3802
+ );
3803
+ },
3804
+
3805
+ /**
3806
+ * 向指定扩展点 id 注册 Vue 组件;`ExtensionPoint` 按 `priority` 降序渲染。
3807
+ * @param {string} pointId
3808
+ * @param {RegisterSlotEntry[]} components
3809
+ */
3810
+ registerSlotComponents(pointId, components) {
3811
+ if (!pointId) {
3812
+ return
3813
+ }
3814
+ if (!registries.slots[pointId]) {
3815
+ Vue.set(registries.slots, pointId, []);
3816
+ }
3817
+ const list = registries.slots[pointId];
3818
+ for (const c of components) {
3819
+ list.push({
3820
+ pluginId,
3821
+ component: c.component,
3822
+ priority: c.priority != null ? c.priority : 0,
3823
+ key: `${pluginId}-${pointId}-${++slotItemKeySeq}`
3824
+ });
3825
+ }
3826
+ list.sort((a, b) => b.priority - a.priority);
3827
+ registries.slotRevision++;
3828
+ },
3829
+
3830
+ /**
3831
+ * @param {string[]|undefined} urls
3832
+ */
3833
+ registerStylesheetUrls(urls) {
3834
+ for (const u of urls || []) {
3835
+ if (typeof u === 'string' && u) {
3836
+ injectStylesheet(u);
3837
+ }
3838
+ }
3839
+ },
3840
+
3841
+ /**
3842
+ * 串行加载多个脚本,失败仅告警不中断宿主。
3843
+ * @param {string[]|undefined} urls
3844
+ */
3845
+ registerScriptUrls(urls) {
3846
+ const chain = (urls || []).filter((u) => typeof u === 'string' && u).reduce(
3847
+ (p, u) => p.then(() => injectScript(u)),
3848
+ Promise.resolve()
3849
+ );
3850
+ chain.catch((e) => console.warn('[plugins] registerScriptUrls', pluginId, e));
3851
+ },
3852
+
3853
+ registerSanitizedHtmlSnippet() {
3854
+ throw new Error('registerSanitizedHtmlSnippet is not enabled in MVP')
3855
+ },
3856
+
3857
+ getBridge: () => bridge,
3858
+
3859
+ /**
3860
+ * 插件卸载前清理逻辑;第一个参数为预留与协议对齐,实际以创建 API 时的 `pluginId` 为准。
3861
+ * @param {string} _pluginId 预留,与 manifest.id 一致时可传入
3862
+ * @param {() => void} fn
3863
+ */
3864
+ onTeardown(_pluginId, fn) {
3865
+ if (typeof fn === 'function') {
3866
+ registerPluginTeardown(pluginId, fn);
3867
+ }
3868
+ }
3869
+ }
3870
+ }
3871
+
3872
+ /**
3873
+ * 单插件卸载:与 `bootstrapPlugins` / `createHostApi` 对称,清理注册表与 DOM 副作用。
3874
+ *
3875
+ * @module dispose-plugin
3876
+ */
3877
+
3878
+ /**
3879
+ * 卸载指定 id 的插件:依次执行 teardown、移除菜单与扩展点条目、删除 activator、移除带 `data-plugin-asset` 的节点。
3880
+ *
3881
+ * **路由**:Vue Router 3 无公开 `removeRoute`,此处不改动 matcher;动态路由需整页刷新或自行维护路由表。
3882
+ *
3883
+ * @param {string} pluginId 与 manifest.id 一致
3884
+ */
3885
+ function disposeWebPlugin(pluginId) {
3886
+ if (!pluginId || typeof pluginId !== 'string') {
3887
+ return
3888
+ }
3889
+
3890
+ runPluginTeardowns(pluginId);
3891
+
3892
+ for (let i = registries.menus.length - 1; i >= 0; i--) {
3893
+ if (registries.menus[i].pluginId === pluginId) {
3894
+ registries.menus.splice(i, 1);
3895
+ }
3896
+ }
3897
+
3898
+ const slots = registries.slots;
3899
+ for (const pointId of Object.keys(slots)) {
3900
+ const list = slots[pointId];
3901
+ if (!Array.isArray(list)) {
3902
+ continue
3903
+ }
3904
+ const next = list.filter((x) => x.pluginId !== pluginId);
3905
+ if (next.length === 0) {
3906
+ Vue.delete(slots, pointId);
3907
+ } else if (next.length !== list.length) {
3908
+ Vue.set(slots, pointId, next);
3909
+ }
3910
+ }
3911
+ registries.slotRevision++;
3912
+
3913
+ if (typeof window !== 'undefined' && window.__PLUGIN_ACTIVATORS__) {
3914
+ delete window.__PLUGIN_ACTIVATORS__[pluginId];
3915
+ }
3916
+
3917
+ if (typeof document !== 'undefined') {
3918
+ document.querySelectorAll('[data-plugin-asset]').forEach((el) => {
3919
+ if (el.getAttribute('data-plugin-asset') === pluginId) {
3920
+ el.remove();
3921
+ }
3922
+ });
3923
+ }
3924
+ }
3925
+
3926
+ /**
3927
+ * 在宿主布局中声明扩展点;插件通过 `hostApi.registerSlotComponents(pointId, ...)` 注入组件。
3928
+ * 使用纯 render 函数,便于 Rollup 发布 dist,宿主无需再转译 .vue。
3929
+ */
3930
+
3931
+ const SlotErrorBoundary = {
3932
+ name: 'SlotErrorBoundary',
3933
+ props: { label: String },
3934
+ data() {
3935
+ return { error: null }
3936
+ },
3937
+ errorCaptured(err) {
3938
+ this.error = err && err.message ? err.message : String(err);
3939
+ console.error('[ExtensionPoint] render error in', this.label, err);
3940
+ return false
3941
+ },
3942
+ render(h) {
3943
+ if (this.error) {
3944
+ return h(
3945
+ 'div',
3946
+ { class: 'plugin-point-error', style: { color: '#c00', fontSize: '12px' } },
3947
+ `[插件 ${this.label}] 渲染失败`
3948
+ )
3949
+ }
3950
+ const d = this.$slots.default;
3951
+ return d && d[0] ? d[0] : h('span')
3952
+ }
3953
+ };
3954
+
3955
+ var ExtensionPoint = {
3956
+ name: 'ExtensionPoint',
3957
+ components: { SlotErrorBoundary },
3958
+ props: {
3959
+ pointId: { type: String, required: true },
3960
+ slotProps: { type: Object, default: () => ({}) }
3961
+ },
3962
+ computed: {
3963
+ items() {
3964
+ void registries.slotRevision;
3965
+ return registries.slots[this.pointId] || []
3966
+ },
3967
+ forwardProps() {
3968
+ return this.slotProps || {}
3969
+ }
3970
+ },
3971
+ render(h) {
3972
+ return h(
3973
+ 'div',
3974
+ {
3975
+ class: 'extension-point',
3976
+ style: { minHeight: '8px' },
3977
+ attrs: { 'data-point-id': this.pointId }
3978
+ },
3979
+ this.items.map((item) =>
3980
+ h(
3981
+ SlotErrorBoundary,
3982
+ {
3983
+ key: item.key,
3984
+ props: { label: item.pluginId }
3985
+ },
3986
+ [h(item.component, { props: this.forwardProps })]
3987
+ )
3988
+ )
3989
+ )
3990
+ }
3991
+ };
3992
+
3993
+ /**
3994
+ * 一键接入:注册 `ExtensionPoint` 并执行 `bootstrapPlugins`。
3995
+ * @module install
3996
+ */
3997
+
3998
+ /**
3999
+ * 注册全局组件 `ExtensionPoint` 并异步引导插件清单。
4000
+ *
4001
+ * @param {*} Vue
4002
+ * @param {*} router vue-router 实例
4003
+ * @param {Record<string, unknown>} [options] 传给 `resolveRuntimeOptions` 的字段;可含 `env`(Vite 传入 `import.meta.env`)以读取 `VITE_*`。
4004
+ * @returns {Promise<void>}
4005
+ */
4006
+ function installWebExtendPluginVue2(Vue, router, options) {
4007
+ const opts = options || {};
4008
+ const { env: injectedEnv, ...runtimeUser } = opts;
4009
+ if (injectedEnv && typeof injectedEnv === 'object') {
4010
+ setWebExtendPluginEnv(injectedEnv);
4011
+ }
4012
+ if (Vue && ExtensionPoint) {
4013
+ Vue.component('ExtensionPoint', ExtensionPoint);
4014
+ }
4015
+ const runtime = resolveRuntimeOptions(runtimeUser);
4016
+ return bootstrapPlugins(router, (id, r, kit) => createHostApi(id, r, kit), runtime)
4017
+ }
4018
+
4019
+ export { ExtensionPoint, HOST_PLUGIN_API_VERSION, bootstrapPlugins, createHostApi, createRequestBridge, defaultWebExtendPluginRuntime, disposeWebPlugin, installWebExtendPluginVue2, registries, resolveRuntimeOptions, setWebExtendPluginEnv };
4020
+ //# sourceMappingURL=index.mjs.map