@vltpkg/cli-js 1.0.0-rc.24 → 1.0.0-rc.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/{bugs-DIPRXK73.js → bugs-KSVA7QNG.js} +3 -3
  2. package/{build-R53AIRYP.js → build-6QS3HGOJ.js} +2 -2
  3. package/{chunk-A2LFSPYL.js → chunk-2MGFDD5I.js} +2 -2
  4. package/{chunk-K6X4DF6U.js → chunk-37DCI4KG.js} +1 -1
  5. package/{chunk-K4X2TU3S.js → chunk-5QLMU4PR.js} +47 -20
  6. package/{chunk-WEU2II6J.js → chunk-62UYVR5K.js} +2 -2
  7. package/{chunk-EHD7YJKI.js → chunk-HPK6ZLUY.js} +1 -1
  8. package/{chunk-PQJO2HPJ.js → chunk-L2RQA7D5.js} +1 -1
  9. package/{chunk-JGIRYPNR.js → chunk-LU3AIHGI.js} +22 -22
  10. package/{chunk-267FYLJB.js → chunk-NGEVYSHM.js} +1 -1
  11. package/{chunk-DED3ZRSM.js → chunk-P2KTSGDO.js} +1 -1
  12. package/{ci-TH7ZUQ7W.js → ci-LQC3DAMB.js} +2 -2
  13. package/cli-package.json +1 -1
  14. package/{create-P6Q344DA.js → create-5ZYDNLD2.js} +5 -5
  15. package/{docs-VQ3ASW4D.js → docs-QHVT3CAA.js} +3 -3
  16. package/{exec-QNDDSXFJ.js → exec-HH5RPTA6.js} +5 -5
  17. package/{exec-cache-MNOBZGEN.js → exec-cache-Y4VLW2SQ.js} +3 -3
  18. package/{exec-local-X7QTI2RT.js → exec-local-EQXYGOZN.js} +4 -4
  19. package/{help-LEPLLKAZ.js → help-43YDKGLI.js} +1 -1
  20. package/{install-5BBY7G5X.js → install-XWI7ASPS.js} +3 -3
  21. package/{list-O6SW6DH3.js → list-VYD4KGKR.js} +4 -4
  22. package/{pack-VJOIINYL.js → pack-OW6LLMYZ.js} +3 -3
  23. package/package.json +1 -1
  24. package/{pkg-3LKU4JA7.js → pkg-W6TK2OA4.js} +3 -3
  25. package/{publish-MJ6HBVO7.js → publish-HP67RLBR.js} +3 -3
  26. package/{query-NIACPXFM.js → query-XNLBIVQK.js} +4 -4
  27. package/registry-client-package.json +1 -1
  28. package/{repo-ZQS5FCHE.js → repo-V6IHCGHG.js} +3 -3
  29. package/{run-7KKZOV4V.js → run-CZSTEZDA.js} +4 -4
  30. package/{run-exec-SNNLAS7X.js → run-exec-MNR3H4EF.js} +4 -4
  31. package/security-archive-src-update-expired.js +2247 -0
  32. package/{src-MQ7RJS5V.js → src-DYCHGTG4.js} +1 -1
  33. package/{uninstall-IM5T6TS5.js → uninstall-L7JZBHKY.js} +3 -3
  34. package/{update-Z67JWNNP.js → update-5VNZX4RF.js} +2 -2
  35. package/{version-GG5XKQIS.js → version-BG6EEYI7.js} +3 -3
  36. package/{view-2CLEZWZL.js → view-CWHRAR2S.js} +1 -1
  37. package/vlr.js +1 -1
  38. package/vlrx.js +1 -1
  39. package/vlt.js +1 -1
  40. package/vlx.js +1 -1
  41. package/vlxl.js +1 -1
@@ -0,0 +1,2247 @@
1
+ var global = globalThis;
2
+ import {Buffer} from "node:buffer";
3
+ import {setTimeout as _vlt_setTimeout,clearTimeout as _vlt_clearTimeout,setImmediate as _vlt_setImmediate,clearImmediate as _vlt_clearImmediate,setInterval as _vlt_setInterval,clearInterval as _vlt_clearInterval} from "node:timers";
4
+ globalThis.setTimeout = _vlt_setTimeout;
5
+ globalThis.clearTimeout = _vlt_clearTimeout;
6
+ globalThis.setImmediate = _vlt_setImmediate;
7
+ globalThis.clearImmediate = _vlt_clearImmediate;
8
+ globalThis.setInterval = _vlt_setInterval;
9
+ globalThis.clearInterval = _vlt_clearInterval;
10
+ import {createRequire as _vlt_createRequire} from "node:module";
11
+ var require = _vlt_createRequire(import.meta.filename);
12
+
13
+ // ../../src/security-archive/src/update-expired.ts
14
+ import { DatabaseSync } from "node:sqlite";
15
+ import { mkdirSync } from "node:fs";
16
+ import { dirname as dirname2 } from "node:path";
17
+ import { pathToFileURL } from "node:url";
18
+
19
+ // ../../node_modules/.vlt/~npm~is-network-error@1.3.1/node_modules/is-network-error/index.js
20
+ var objectToString = Object.prototype.toString;
21
+ var isError = (value) => objectToString.call(value) === "[object Error]";
22
+ var errorMessages = /* @__PURE__ */ new Set([
23
+ "network error",
24
+ // Chrome
25
+ "NetworkError when attempting to fetch resource.",
26
+ // Firefox
27
+ "The Internet connection appears to be offline.",
28
+ // Safari 16
29
+ "Network request failed",
30
+ // `cross-fetch`
31
+ "fetch failed",
32
+ // Undici (Node.js)
33
+ "terminated",
34
+ // Undici (Node.js)
35
+ " A network error occurred.",
36
+ // Bun (WebKit)
37
+ "Network connection lost"
38
+ // Cloudflare Workers (fetch)
39
+ ]);
40
+ function isNetworkError(error2) {
41
+ const isValid = error2 && isError(error2) && error2.name === "TypeError" && typeof error2.message === "string";
42
+ if (!isValid) {
43
+ return false;
44
+ }
45
+ const { message, stack } = error2;
46
+ if (message === "Load failed") {
47
+ return stack === void 0 || "__sentry_captured__" in error2;
48
+ }
49
+ if (message.startsWith("error sending request for url")) {
50
+ return true;
51
+ }
52
+ if (message === "Failed to fetch" || message.startsWith("Failed to fetch (") && message.endsWith(")")) {
53
+ return true;
54
+ }
55
+ return errorMessages.has(message);
56
+ }
57
+
58
+ // ../../node_modules/.vlt/~npm~p-retry@7.1.1/node_modules/p-retry/index.js
59
+ function validateRetries(retries) {
60
+ if (typeof retries === "number") {
61
+ if (retries < 0) {
62
+ throw new TypeError("Expected `retries` to be a non-negative number.");
63
+ }
64
+ if (Number.isNaN(retries)) {
65
+ throw new TypeError("Expected `retries` to be a valid number or Infinity, got NaN.");
66
+ }
67
+ } else if (retries !== void 0) {
68
+ throw new TypeError("Expected `retries` to be a number or Infinity.");
69
+ }
70
+ }
71
+ function validateNumberOption(name, value, { min = 0, allowInfinity = false } = {}) {
72
+ if (value === void 0) {
73
+ return;
74
+ }
75
+ if (typeof value !== "number" || Number.isNaN(value)) {
76
+ throw new TypeError(`Expected \`${name}\` to be a number${allowInfinity ? " or Infinity" : ""}.`);
77
+ }
78
+ if (!allowInfinity && !Number.isFinite(value)) {
79
+ throw new TypeError(`Expected \`${name}\` to be a finite number.`);
80
+ }
81
+ if (value < min) {
82
+ throw new TypeError(`Expected \`${name}\` to be \u2265 ${min}.`);
83
+ }
84
+ }
85
+ var AbortError = class extends Error {
86
+ constructor(message) {
87
+ super();
88
+ if (message instanceof Error) {
89
+ this.originalError = message;
90
+ ({ message } = message);
91
+ } else {
92
+ this.originalError = new Error(message);
93
+ this.originalError.stack = this.stack;
94
+ }
95
+ this.name = "AbortError";
96
+ this.message = message;
97
+ }
98
+ };
99
+ function calculateDelay(retriesConsumed, options) {
100
+ const attempt = Math.max(1, retriesConsumed + 1);
101
+ const random = options.randomize ? Math.random() + 1 : 1;
102
+ let timeout = Math.round(random * options.minTimeout * options.factor ** (attempt - 1));
103
+ timeout = Math.min(timeout, options.maxTimeout);
104
+ return timeout;
105
+ }
106
+ function calculateRemainingTime(start, max) {
107
+ if (!Number.isFinite(max)) {
108
+ return max;
109
+ }
110
+ return max - (performance.now() - start);
111
+ }
112
+ async function onAttemptFailure({ error: error2, attemptNumber, retriesConsumed, startTime, options }) {
113
+ const normalizedError = error2 instanceof Error ? error2 : new TypeError(`Non-error was thrown: "${error2}". You should only throw errors.`);
114
+ if (normalizedError instanceof AbortError) {
115
+ throw normalizedError.originalError;
116
+ }
117
+ const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
118
+ const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
119
+ const context = Object.freeze({
120
+ error: normalizedError,
121
+ attemptNumber,
122
+ retriesLeft,
123
+ retriesConsumed
124
+ });
125
+ await options.onFailedAttempt(context);
126
+ if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
127
+ throw normalizedError;
128
+ }
129
+ const consumeRetry = await options.shouldConsumeRetry(context);
130
+ const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
131
+ if (remainingTime <= 0 || retriesLeft <= 0) {
132
+ throw normalizedError;
133
+ }
134
+ if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
135
+ if (consumeRetry) {
136
+ throw normalizedError;
137
+ }
138
+ options.signal?.throwIfAborted();
139
+ return false;
140
+ }
141
+ if (!await options.shouldRetry(context)) {
142
+ throw normalizedError;
143
+ }
144
+ if (!consumeRetry) {
145
+ options.signal?.throwIfAborted();
146
+ return false;
147
+ }
148
+ const delayTime = calculateDelay(retriesConsumed, options);
149
+ const finalDelay = Math.min(delayTime, remainingTime);
150
+ options.signal?.throwIfAborted();
151
+ if (finalDelay > 0) {
152
+ await new Promise((resolve3, reject) => {
153
+ const onAbort = () => {
154
+ clearTimeout(timeoutToken);
155
+ options.signal?.removeEventListener("abort", onAbort);
156
+ reject(options.signal.reason);
157
+ };
158
+ const timeoutToken = setTimeout(() => {
159
+ options.signal?.removeEventListener("abort", onAbort);
160
+ resolve3();
161
+ }, finalDelay);
162
+ if (options.unref) {
163
+ timeoutToken.unref?.();
164
+ }
165
+ options.signal?.addEventListener("abort", onAbort, { once: true });
166
+ });
167
+ }
168
+ options.signal?.throwIfAborted();
169
+ return true;
170
+ }
171
+ async function pRetry(input, options = {}) {
172
+ options = { ...options };
173
+ validateRetries(options.retries);
174
+ if (Object.hasOwn(options, "forever")) {
175
+ throw new Error("The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.");
176
+ }
177
+ options.retries ??= 10;
178
+ options.factor ??= 2;
179
+ options.minTimeout ??= 1e3;
180
+ options.maxTimeout ??= Number.POSITIVE_INFINITY;
181
+ options.maxRetryTime ??= Number.POSITIVE_INFINITY;
182
+ options.randomize ??= false;
183
+ options.onFailedAttempt ??= () => {
184
+ };
185
+ options.shouldRetry ??= () => true;
186
+ options.shouldConsumeRetry ??= () => true;
187
+ validateNumberOption("factor", options.factor, { min: 0, allowInfinity: false });
188
+ validateNumberOption("minTimeout", options.minTimeout, { min: 0, allowInfinity: false });
189
+ validateNumberOption("maxTimeout", options.maxTimeout, { min: 0, allowInfinity: true });
190
+ validateNumberOption("maxRetryTime", options.maxRetryTime, { min: 0, allowInfinity: true });
191
+ if (!(options.factor > 0)) {
192
+ options.factor = 1;
193
+ }
194
+ options.signal?.throwIfAborted();
195
+ let attemptNumber = 0;
196
+ let retriesConsumed = 0;
197
+ const startTime = performance.now();
198
+ while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
199
+ attemptNumber++;
200
+ try {
201
+ options.signal?.throwIfAborted();
202
+ const result = await input(attemptNumber);
203
+ options.signal?.throwIfAborted();
204
+ return result;
205
+ } catch (error2) {
206
+ if (await onAttemptFailure({
207
+ error: error2,
208
+ attemptNumber,
209
+ retriesConsumed,
210
+ startTime,
211
+ options
212
+ })) {
213
+ retriesConsumed++;
214
+ }
215
+ }
216
+ }
217
+ throw new Error("Retry attempts exhausted without throwing an error.");
218
+ }
219
+
220
+ // ../../src/error-cause/src/index.ts
221
+ var { captureStackTrace } = Error;
222
+ function create(cls, defaultFrom, message, cause, from = defaultFrom) {
223
+ const er = new cls(message, cause ? { cause } : void 0);
224
+ captureStackTrace?.(er, from);
225
+ return er;
226
+ }
227
+ function error(message, cause, from) {
228
+ return create(Error, error, message, cause, from);
229
+ }
230
+ function typeError(message, cause, from) {
231
+ return create(TypeError, typeError, message, cause, from);
232
+ }
233
+ function syntaxError(message, cause, from) {
234
+ return create(
235
+ SyntaxError,
236
+ syntaxError,
237
+ message,
238
+ cause,
239
+ from
240
+ );
241
+ }
242
+
243
+ // ../../src/spec/src/index.ts
244
+ import { homedir } from "node:os";
245
+ import {
246
+ isAbsolute,
247
+ join,
248
+ resolve,
249
+ win32 as winPath
250
+ } from "node:path";
251
+ import { inspect } from "node:util";
252
+
253
+ // ../../src/fast-split/src/index.ts
254
+ function fastSplit(str, delim, limit = -1, onPart) {
255
+ let i = 0;
256
+ let p = 0;
257
+ const l = delim.length;
258
+ const parts = [];
259
+ while (i !== -1) {
260
+ i = str.indexOf(delim, p);
261
+ const part = i === -1 || parts.length === limit - 1 ? str.substring(p) : str.substring(p, i);
262
+ parts.push(onPart?.(part, parts, i) ?? part);
263
+ if (parts.length === limit) {
264
+ return parts;
265
+ }
266
+ p = i + l;
267
+ }
268
+ return parts;
269
+ }
270
+
271
+ // ../../src/semver/src/version.ts
272
+ var maybeNumber = (s) => {
273
+ if (!/^[0-9]+$/.test(s)) return s;
274
+ const n = Number(s);
275
+ return n <= Number.MAX_SAFE_INTEGER ? n : s;
276
+ };
277
+ var safeNumber = (s, version2, field) => {
278
+ const n = Number(s);
279
+ if (n > Number.MAX_SAFE_INTEGER) {
280
+ throw invalidVersion(
281
+ version2,
282
+ `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`
283
+ );
284
+ }
285
+ return n;
286
+ };
287
+ var re = {
288
+ prefix: /^[ v=]+/,
289
+ main: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/,
290
+ prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\+)/,
291
+ build: /\+([0-9a-zA-Z_.-]+)$/,
292
+ full: /^[ v=]*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\+([0-9a-zA-Z_.-]+))?$/
293
+ };
294
+ var invalidVersion = (version2, message) => {
295
+ const er = syntaxError(
296
+ `invalid version: ${message}`,
297
+ { version: version2 },
298
+ Version
299
+ );
300
+ return er;
301
+ };
302
+ var Version = class _Version {
303
+ /** raw string provided to create this Version */
304
+ raw;
305
+ /** major version number */
306
+ major;
307
+ /** minor version number */
308
+ minor;
309
+ /** patch version number */
310
+ patch;
311
+ /**
312
+ * List of `'.'`-separated strings and numbers indicating that this
313
+ * version is a prerelease.
314
+ *
315
+ * This is undefined if the version does not have a prerelease section.
316
+ */
317
+ prerelease;
318
+ /**
319
+ * List of `'.'`-separated strings in the `build` section.
320
+ *
321
+ * This is undefined if the version does not have a build.
322
+ */
323
+ build;
324
+ /** Canonical strict form of this version */
325
+ toString() {
326
+ return `${this.major}.${this.minor}.${this.patch}${this.prerelease ? "-" + this.prerelease.join(".") : ""}${this.build ? "+" + this.build.join(".") : ""}`;
327
+ }
328
+ /** Generate a `Version` object from a SemVer string */
329
+ static parse(version2) {
330
+ version2 = version2.replace(re.prefix, "").trim();
331
+ if (version2.length > 256) {
332
+ throw invalidVersion(
333
+ version2,
334
+ "must be less than 256 characters"
335
+ );
336
+ }
337
+ const parsed = re.full.exec(version2);
338
+ if (!parsed) {
339
+ const main2 = re.main.exec(version2);
340
+ if (!main2) {
341
+ throw invalidVersion(
342
+ version2,
343
+ "no Major.minor.patch tuple present"
344
+ );
345
+ } else {
346
+ throw invalidVersion(
347
+ version2,
348
+ "invalid build or patch section"
349
+ );
350
+ }
351
+ }
352
+ const [_, major_, minor_, patch_, prerelease, build] = parsed;
353
+ const major = safeNumber(major_, version2, "major");
354
+ const minor = safeNumber(minor_, version2, "minor");
355
+ const patch = safeNumber(patch_, version2, "patch");
356
+ return new _Version(
357
+ version2,
358
+ major,
359
+ minor,
360
+ patch,
361
+ prerelease,
362
+ build
363
+ );
364
+ }
365
+ constructor(version2, major, minor, patch, prerelease, build) {
366
+ this.raw = version2;
367
+ this.major = major;
368
+ this.minor = minor;
369
+ this.patch = patch;
370
+ if (prerelease) {
371
+ this.prerelease = fastSplit(prerelease, ".", -1, (c) => {
372
+ if (!c) {
373
+ throw invalidVersion(
374
+ version2,
375
+ "invalid prerelease, empty identifiers not allowed"
376
+ );
377
+ }
378
+ return maybeNumber(c);
379
+ });
380
+ }
381
+ if (build) {
382
+ this.build = fastSplit(build, ".", -1, (c) => {
383
+ if (!c) {
384
+ throw invalidVersion(
385
+ version2,
386
+ "invalid build metadata, empty identifiers not allowed"
387
+ );
388
+ }
389
+ });
390
+ }
391
+ }
392
+ /**
393
+ * Return 1 if this is > the provided version, -1 if we're less, or 0 if
394
+ * they are equal.
395
+ *
396
+ * No special handling for prerelease versions, this is just a precedence
397
+ * comparison.
398
+ *
399
+ * This can be used to sort a list of versions by precedence:
400
+ *
401
+ * ```ts
402
+ * const versions: Version[] = getVersionsSomehow()
403
+ * const sorted = versions.sort((a, b) => a.compare(b))
404
+ * ```
405
+ */
406
+ compare(v) {
407
+ if (this.major > v.major) return 1;
408
+ if (this.major < v.major) return -1;
409
+ if (this.minor > v.minor) return 1;
410
+ if (this.minor < v.minor) return -1;
411
+ if (this.patch > v.patch) return 1;
412
+ if (this.patch < v.patch) return -1;
413
+ if (!v.prerelease?.length)
414
+ return !this.prerelease?.length ? 0 : -1;
415
+ if (!this.prerelease?.length) return 1;
416
+ const len = Math.max(this.prerelease.length, v.prerelease.length);
417
+ const me = this.prerelease;
418
+ const thee = v.prerelease;
419
+ for (let i = 0; i < len; i++) {
420
+ const m = me[i];
421
+ const t = thee[i];
422
+ if (m === t) continue;
423
+ if (t === void 0) return 1;
424
+ if (m === void 0) return -1;
425
+ if (typeof m !== typeof t) {
426
+ return typeof m === "string" ? 1 : -1;
427
+ }
428
+ return m > t ? 1 : -1;
429
+ }
430
+ return 0;
431
+ }
432
+ /**
433
+ * The inverse of compare, for sorting version lists in reverse order
434
+ */
435
+ rcompare(v) {
436
+ return -1 * this.compare(v);
437
+ }
438
+ /** true if this version is > the argument */
439
+ greaterThan(v) {
440
+ return this.compare(v) === 1;
441
+ }
442
+ /** true if this version is >= the argument */
443
+ greaterThanEqual(v) {
444
+ return this.compare(v) > -1;
445
+ }
446
+ /** true if this version is < the argument */
447
+ lessThan(v) {
448
+ return this.compare(v) === -1;
449
+ }
450
+ /** true if this version is &lt;= the argument */
451
+ lessThanEqual(v) {
452
+ return this.compare(v) < 1;
453
+ }
454
+ /** true if these two versions have equal SemVer precedence */
455
+ equals(v) {
456
+ return this.compare(v) === 0;
457
+ }
458
+ /** just compare the M.m.p parts of the version */
459
+ tupleEquals(v) {
460
+ return this.major === v.major && this.minor === v.minor && this.patch === v.patch;
461
+ }
462
+ /** true if this version satisfies the range */
463
+ satisfies(r) {
464
+ return r.test(this);
465
+ }
466
+ /**
467
+ * Increment the version in place, in the manner specified.
468
+ *
469
+ * Part behaviors:
470
+ *
471
+ * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
472
+ * simply drop the prerelease. Otherwise, set the minor and patch to 0, and
473
+ * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
474
+ * `2.0.0`
475
+ *
476
+ * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
477
+ * simply drop the prerelease. Otherwise, set the patch to 0, and increment the
478
+ * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
479
+ *
480
+ * - `'patch'` If the version has a prerelease, then simply drop the
481
+ * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
482
+ * `1.2.3` and `1.2.3` becomes `1.2.4`.
483
+ *
484
+ * - `'premajor'` Set the patch and minor versions to `0`, increment the major
485
+ * version, and add a prerelease, using the optional identifier.
486
+ *
487
+ * - `'preminor'` Set the patch version to `0`, increment the minor version,
488
+ * and add a prerelease, using the optional identifier.
489
+ *
490
+ * - `'prepatch'` If a prerelease is already present, increment the patch
491
+ * version, otherwise leave it untouched, and add a prerelease, using the
492
+ * optional identifier.
493
+ *
494
+ * - `'prerelease'` If a prerelease version is present, then behave the same as
495
+ * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
496
+ *
497
+ * - `'pre'` This is mostly for use by the other prerelease incrementers.
498
+ *
499
+ * - If a prerelease identifier is provided:
500
+ *
501
+ * Update that named portion of the prerelease. For example,
502
+ * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
503
+ *
504
+ * If there is no prerelease identifier by that name, then replace the
505
+ * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
506
+ * would result in `1.2.3-beta`.
507
+ *
508
+ * If the prerelease identifer is present, but has no numeric value
509
+ * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
510
+ * would result in `1.2.3-beta.0`.
511
+ *
512
+ * - If no prerelease identifier is provided:
513
+ *
514
+ * If there is no current prerelease, then set the prerelease to `0`. So,
515
+ * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
516
+ *
517
+ * If the last item in the prerelease is numeric, then increment it. So,
518
+ * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
519
+ */
520
+ inc(part, prereleaseIdentifier) {
521
+ switch (part) {
522
+ case "premajor":
523
+ this.prerelease = void 0;
524
+ this.patch = 0;
525
+ this.minor = 0;
526
+ this.major++;
527
+ this.inc("pre", prereleaseIdentifier);
528
+ break;
529
+ case "preminor":
530
+ this.prerelease = void 0;
531
+ this.patch = 0;
532
+ this.minor++;
533
+ this.inc("pre", prereleaseIdentifier);
534
+ break;
535
+ case "prepatch":
536
+ this.prerelease = void 0;
537
+ this.inc("patch");
538
+ this.inc("pre", prereleaseIdentifier);
539
+ break;
540
+ case "prerelease":
541
+ if (!this.prerelease?.length)
542
+ this.inc("patch", prereleaseIdentifier);
543
+ this.inc("pre", prereleaseIdentifier);
544
+ break;
545
+ case "pre": {
546
+ if (!prereleaseIdentifier) {
547
+ if (!this.prerelease?.length) {
548
+ this.prerelease = [0];
549
+ break;
550
+ }
551
+ const last = this.prerelease[this.prerelease.length - 1];
552
+ if (typeof last === "number") {
553
+ this.prerelease[this.prerelease.length - 1] = last + 1;
554
+ } else {
555
+ this.prerelease.push(0);
556
+ }
557
+ break;
558
+ }
559
+ if (!this.prerelease?.length) {
560
+ this.prerelease = [prereleaseIdentifier];
561
+ break;
562
+ }
563
+ const i = this.prerelease.indexOf(
564
+ maybeNumber(prereleaseIdentifier)
565
+ );
566
+ if (i === -1) {
567
+ this.prerelease = [prereleaseIdentifier];
568
+ break;
569
+ }
570
+ const baseValue = this.prerelease[i + 1];
571
+ if (typeof baseValue === "number") {
572
+ this.prerelease[i + 1] = baseValue + 1;
573
+ break;
574
+ }
575
+ if (i === this.prerelease.length - 1) {
576
+ this.prerelease.push(0);
577
+ break;
578
+ }
579
+ this.prerelease.splice(i + 1, 0, 0);
580
+ break;
581
+ }
582
+ case "major":
583
+ if (!this.prerelease?.length || this.minor || this.patch)
584
+ this.major++;
585
+ this.prerelease = void 0;
586
+ this.patch = 0;
587
+ this.minor = 0;
588
+ break;
589
+ case "minor":
590
+ if (!this.prerelease?.length || this.patch) this.minor++;
591
+ this.prerelease = void 0;
592
+ this.patch = 0;
593
+ break;
594
+ case "patch":
595
+ if (!this.prerelease?.length) this.patch++;
596
+ this.prerelease = void 0;
597
+ break;
598
+ default:
599
+ throw typeError(
600
+ "Invalid increment identifier",
601
+ {
602
+ version: this,
603
+ found: part,
604
+ validOptions: [
605
+ "major",
606
+ "minor",
607
+ "patch",
608
+ "premajor",
609
+ "preminor",
610
+ "prepatch",
611
+ "prerelease",
612
+ "pre"
613
+ ]
614
+ },
615
+ this.inc
616
+ );
617
+ }
618
+ this.raw = this.toString();
619
+ return this;
620
+ }
621
+ };
622
+
623
+ // ../../src/semver/src/comparator.ts
624
+ var isOperator = (o) => !!o && (o === ">" || o === "<" || o === ">=" || o === "<=" || o === "" || o === "~" || o === "^" || o === "~>");
625
+ var preJunk = new Set("=v ");
626
+ var invalidComp = (c, message) => syntaxError(
627
+ `invalid comparator: '${c}' ${message}`,
628
+ { found: c },
629
+ Comparator
630
+ );
631
+ var assertNumber = (value, c, field) => {
632
+ const n = Number(value);
633
+ if (n !== n) {
634
+ throw invalidComp(
635
+ c,
636
+ `${field} must be numeric or 'x', got: '${value}'`
637
+ );
638
+ }
639
+ return n;
640
+ };
641
+ var assertVersion = (v, comp) => {
642
+ if (!v) {
643
+ throw invalidComp(comp, "no value provided for operator");
644
+ }
645
+ };
646
+ var assertMissing = (value, c, field) => {
647
+ if (value && !isX(value)) {
648
+ throw invalidComp(
649
+ c,
650
+ `cannot omit '${field}' and include subsequent fields`
651
+ );
652
+ }
653
+ };
654
+ var MAJOR = 0;
655
+ var MINOR = 1;
656
+ var PATCH = 2;
657
+ var isX = (c) => !c || c === "X" || c === "x" || c === "*";
658
+ var isFullVersion = (parsed) => void 0 !== parsed[PATCH];
659
+ var isXPatch = (parsed) => void 0 !== parsed[MINOR] && void 0 === parsed[PATCH];
660
+ var isXMinor = (parsed) => void 0 !== parsed[MAJOR] && void 0 === parsed[MINOR];
661
+ var isXMajor = (parsed) => void 0 === parsed[MAJOR];
662
+ var Comparator = class {
663
+ /**
664
+ * does this range include prereleases, even when they do not
665
+ * match the tuple in the comparator?
666
+ */
667
+ includePrerelease;
668
+ /** raw string used to create this comparator */
669
+ raw;
670
+ /** tokens extracted from the raw string input */
671
+ tokens;
672
+ /**
673
+ * Either the `any` comparator, the `none` comparator, or an operator
674
+ * and a {@link ParsedXRange}
675
+ */
676
+ tuples = [];
677
+ /** true if this comparator can not match anything */
678
+ isNone = false;
679
+ /**
680
+ * true if this comparator is a `'*'` type of range.
681
+ *
682
+ * Note that it still will not match versions with a prerelease value,
683
+ * unless the tuple in the version matches the tuple provided to the
684
+ * comparator, and the comparator version also has a prerelease value,
685
+ * unless `includePrerelease` is set.
686
+ */
687
+ isAny = false;
688
+ /** the canonical strict simplified parsed form of this constructor */
689
+ toString() {
690
+ return this.isNone ? "<0.0.0-0" : this.isAny ? "*" : (
691
+ /* c8 ignore next */
692
+ this.tuples.map((c) => isAny(c) ? "*" : c.join("")).join(" ")
693
+ );
694
+ }
695
+ constructor(comp, includePrerelease = false) {
696
+ this.includePrerelease = includePrerelease;
697
+ comp = comp.trim();
698
+ this.raw = comp;
699
+ let hyphen = false;
700
+ const rawComps = fastSplit(comp, " ", -1, (part, parts, i) => {
701
+ if (part === "-") {
702
+ if (hyphen) {
703
+ throw invalidComp(
704
+ comp,
705
+ "multiple hyphen ranges not allowed"
706
+ );
707
+ }
708
+ if (parts.length !== 1 || i === -1) {
709
+ throw invalidComp(
710
+ comp,
711
+ "hyphen must be between two versions"
712
+ );
713
+ }
714
+ hyphen = true;
715
+ } else if (hyphen && parts.length !== 2) {
716
+ throw invalidComp(comp, "hyphen range must be alone");
717
+ }
718
+ });
719
+ const comps = [];
720
+ let followingOperator = false;
721
+ let l = 0;
722
+ for (const c of rawComps) {
723
+ if (c === "") continue;
724
+ if (!followingOperator) {
725
+ followingOperator = isOperator(c);
726
+ comps.push(c);
727
+ l++;
728
+ continue;
729
+ }
730
+ comps[l - 1] += c;
731
+ followingOperator = false;
732
+ }
733
+ if (hyphen) {
734
+ const [min, _, max] = comps;
735
+ if (!min || !max) {
736
+ throw invalidComp(comp, "hyphen must be between two versions");
737
+ }
738
+ this.#parseHyphenRange(min, max);
739
+ } else if (!comps.length || comps.length === 1 && isX(comps[0])) {
740
+ this.tuples.push(this.#getComparatorAny());
741
+ } else {
742
+ for (const c of comps) {
743
+ this.#parse(c);
744
+ if (this.isNone) break;
745
+ }
746
+ }
747
+ this.tokens = comps;
748
+ this.isAny = true;
749
+ for (const c of this.tuples) {
750
+ if (Array.isArray(c) || !c.isAny) {
751
+ this.isAny = false;
752
+ break;
753
+ }
754
+ }
755
+ }
756
+ // inclusive min
757
+ #xInclusiveMin(raw) {
758
+ const z = this.includePrerelease ? "0" : void 0;
759
+ const [M, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
760
+ return M === void 0 ? this.#getComparatorAny() : [">=", new Version(raw, M, m, p, pr, build)];
761
+ }
762
+ // exclusive min
763
+ #xExclusiveMin(raw) {
764
+ const parsed = this.#parseX(raw);
765
+ if (isFullVersion(parsed)) {
766
+ return [">", new Version(raw, ...parsed)];
767
+ }
768
+ const z = this.includePrerelease ? "0" : void 0;
769
+ if (isXPatch(parsed)) {
770
+ return [
771
+ ">=",
772
+ new Version(
773
+ raw,
774
+ parsed[MAJOR],
775
+ parsed[MINOR] + 1,
776
+ 0,
777
+ z,
778
+ void 0
779
+ )
780
+ ];
781
+ }
782
+ if (isXMinor(parsed)) {
783
+ return [
784
+ ">=",
785
+ new Version(raw, parsed[MAJOR] + 1, 0, 0, z, void 0)
786
+ ];
787
+ }
788
+ this.isNone = true;
789
+ this.tuples.length = 0;
790
+ return comparatorNone;
791
+ }
792
+ #xInclusiveMax(raw) {
793
+ const parsed = this.#parseX(raw);
794
+ return isFullVersion(parsed) ? ["<=", new Version(raw, ...parsed)] : isXPatch(parsed) ? [
795
+ "<",
796
+ new Version(
797
+ raw,
798
+ parsed[MAJOR],
799
+ parsed[MINOR] + 1,
800
+ 0,
801
+ "0",
802
+ void 0
803
+ )
804
+ ] : isXMinor(parsed) ? [
805
+ "<",
806
+ new Version(raw, parsed[MAJOR] + 1, 0, 0, "0", void 0)
807
+ ] : this.#getComparatorAny();
808
+ }
809
+ #xExclusiveMax(raw) {
810
+ const z = this.includePrerelease ? "0" : void 0;
811
+ const [M = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
812
+ if (M === 0 && m === 0 && p === 0 && pr === "0") {
813
+ this.isNone = true;
814
+ this.tuples.length = 0;
815
+ return comparatorNone;
816
+ }
817
+ return ["<", new Version(raw, M, m, p, pr, build)];
818
+ }
819
+ #validXM(raw, m, p) {
820
+ assertMissing(m, raw, "major");
821
+ assertMissing(p, raw, "major");
822
+ if (m === "" || p === "") {
823
+ throw invalidComp(raw, `(Did you mean '*'?)`);
824
+ }
825
+ return [];
826
+ }
827
+ #validXm(raw, M, m, p) {
828
+ assertMissing(p, raw, "major");
829
+ if (m === "" || p === "") {
830
+ throw invalidComp(raw, `(Did you mean '${M}'?)`);
831
+ }
832
+ return [assertNumber(M, raw, "major")];
833
+ }
834
+ #validXp(raw, M, m, p) {
835
+ if (p === "") {
836
+ throw invalidComp(raw, `(Did you mean '${M}.${m}'?)`);
837
+ }
838
+ return [
839
+ assertNumber(M, raw, "major"),
840
+ assertNumber(m, raw, "minor")
841
+ ];
842
+ }
843
+ #validTuple(raw, M, m, p) {
844
+ return [
845
+ assertNumber(M, raw, "major"),
846
+ assertNumber(m, raw, "minor"),
847
+ assertNumber(p, raw, "patch")
848
+ ];
849
+ }
850
+ #validXbuild(raw, M, m, p, pl) {
851
+ const patch = p.substring(0, pl);
852
+ const build = p.substring(pl + 1);
853
+ if (!patch) {
854
+ throw invalidComp(raw, "cannot specify build without patch");
855
+ }
856
+ if (!build) {
857
+ throw invalidComp(raw, `encountered '+', but no build value`);
858
+ }
859
+ return [
860
+ assertNumber(M, raw, "major"),
861
+ assertNumber(m, raw, "minor"),
862
+ assertNumber(patch, raw, "patch"),
863
+ void 0,
864
+ build
865
+ ];
866
+ }
867
+ #validXpr(raw, M, m, p, hy) {
868
+ {
869
+ const patch = p.substring(0, hy);
870
+ const pr = p.substring(hy + 1);
871
+ if (!patch) {
872
+ throw invalidComp(
873
+ raw,
874
+ "cannot specify prerelease without patch"
875
+ );
876
+ }
877
+ if (!pr) {
878
+ throw invalidComp(
879
+ raw,
880
+ `encountered '-', but no prerelease value`
881
+ );
882
+ }
883
+ return [
884
+ assertNumber(M, raw, "major"),
885
+ assertNumber(m, raw, "minor"),
886
+ assertNumber(patch, raw, "patch"),
887
+ pr,
888
+ void 0
889
+ ];
890
+ }
891
+ }
892
+ #validXprbuild(raw, M, m, p, hy, pl) {
893
+ const patch = p.substring(0, hy);
894
+ const pr = p.substring(hy + 1, pl);
895
+ const build = p.substring(pl + 1);
896
+ if (!patch) {
897
+ throw invalidComp(
898
+ raw,
899
+ "cannot specify prerelease without patch"
900
+ );
901
+ }
902
+ if (!pr) {
903
+ throw invalidComp(
904
+ raw,
905
+ `encountered '-', but no prerelease value`
906
+ );
907
+ }
908
+ if (!build) {
909
+ throw invalidComp(raw, `encountered '+', but no build value`);
910
+ }
911
+ return [
912
+ assertNumber(M, raw, "major"),
913
+ assertNumber(m, raw, "minor"),
914
+ assertNumber(patch, raw, "patch"),
915
+ pr,
916
+ build
917
+ ];
918
+ }
919
+ // pull the relevant values out of an X-range or version
920
+ // return the fields for creating a Version object.
921
+ // only call once operator is stripped off
922
+ #parseX(raw) {
923
+ let [M, m, p] = fastSplit(raw, ".", 3);
924
+ let prune = 0;
925
+ while (M && preJunk.has(M.charAt(prune))) prune++;
926
+ if (M !== void 0 && prune !== 0) M = M.substring(prune);
927
+ if (!M || isX(M)) return this.#validXM(raw, m, p);
928
+ if (!m || isX(m)) return this.#validXm(raw, M, m, p);
929
+ if (!p || isX(p)) return this.#validXp(raw, M, m, p);
930
+ const hy = p.indexOf("-");
931
+ const pl = p.indexOf("+");
932
+ if (pl === -1 && hy === -1) return this.#validTuple(raw, M, m, p);
933
+ if (pl === -1) return this.#validXpr(raw, M, m, p, hy);
934
+ if (hy === -1) return this.#validXbuild(raw, M, m, p, pl);
935
+ return this.#validXprbuild(raw, M, m, p, hy, pl);
936
+ }
937
+ #parseHyphenRange(min, max) {
938
+ const minv = this.#xInclusiveMin(min);
939
+ const maxv = this.#xInclusiveMax(max);
940
+ const minAny = isAny(minv);
941
+ const maxAny = isAny(maxv);
942
+ if (minAny && maxAny) this.tuples.push(this.#getComparatorAny());
943
+ else if (minAny) this.tuples.push(maxv);
944
+ else if (maxAny) this.tuples.push(minv);
945
+ else this.tuples.push(minv, maxv);
946
+ }
947
+ #parse(comp) {
948
+ const first = comp.charAt(0);
949
+ const first2 = comp.substring(0, 2);
950
+ const v1 = comp.substring(1);
951
+ const v2 = comp.substring(2);
952
+ switch (first2) {
953
+ case "~>":
954
+ assertVersion(v2, comp);
955
+ return this.#parseTilde(v2);
956
+ case ">=":
957
+ assertVersion(v2, comp);
958
+ return this.tuples.push(this.#xInclusiveMin(v2));
959
+ case "<=":
960
+ assertVersion(v2, comp);
961
+ return this.tuples.push(this.#xInclusiveMax(v2));
962
+ }
963
+ switch (first) {
964
+ case "~":
965
+ assertVersion(v1, comp);
966
+ return this.#parseTilde(v1);
967
+ case "^":
968
+ assertVersion(v1, comp);
969
+ return this.#parseCaret(v1);
970
+ case ">":
971
+ assertVersion(v1, comp);
972
+ return this.tuples.push(this.#xExclusiveMin(v1));
973
+ case "<":
974
+ assertVersion(v1, comp);
975
+ return this.tuples.push(this.#xExclusiveMax(v1));
976
+ }
977
+ return this.#parseEq(comp);
978
+ }
979
+ #parseTilde(comp) {
980
+ const parsed = this.#parseX(comp);
981
+ if (isXMajor(parsed)) {
982
+ this.tuples.push(this.#getComparatorAny());
983
+ return;
984
+ }
985
+ const z = this.includePrerelease ? "0" : void 0;
986
+ if (isXMinor(parsed)) {
987
+ const [M2] = parsed;
988
+ this.tuples.push(
989
+ [">=", new Version(comp, M2, 0, 0, z, void 0)],
990
+ ["<", new Version(comp, M2 + 1, 0, 0, "0", void 0)]
991
+ );
992
+ return;
993
+ }
994
+ if (isXPatch(parsed)) {
995
+ const [M2, m2] = parsed;
996
+ const z2 = this.includePrerelease ? "0" : void 0;
997
+ this.tuples.push(
998
+ [">=", new Version(comp, M2, m2, 0, z2, void 0)],
999
+ ["<", new Version(comp, M2, m2 + 1, 0, "0", void 0)]
1000
+ );
1001
+ return;
1002
+ }
1003
+ const [M, m, p, pr = z, build] = parsed;
1004
+ this.tuples.push(
1005
+ [">=", new Version(comp, M, m, p, pr, build)],
1006
+ ["<", new Version(comp, M, m + 1, 0, "0", build)]
1007
+ );
1008
+ }
1009
+ #parseCaret(comp) {
1010
+ const min = this.#xInclusiveMin(comp);
1011
+ if (isAny(min)) {
1012
+ this.tuples.push(min);
1013
+ return;
1014
+ }
1015
+ const minv = min[1];
1016
+ if (minv.major !== 0) {
1017
+ this.tuples.push(min, [
1018
+ "<",
1019
+ new Version(comp, minv.major + 1, 0, 0, "0", void 0)
1020
+ ]);
1021
+ } else if (minv.minor !== 0) {
1022
+ this.tuples.push(min, [
1023
+ "<",
1024
+ new Version(
1025
+ comp,
1026
+ minv.major,
1027
+ minv.minor + 1,
1028
+ 0,
1029
+ "0",
1030
+ void 0
1031
+ )
1032
+ ]);
1033
+ } else if (!minv.prerelease?.length) {
1034
+ this.tuples.push(["", minv]);
1035
+ } else {
1036
+ this.tuples.push(min, [
1037
+ "<",
1038
+ new Version(
1039
+ comp,
1040
+ minv.major,
1041
+ minv.minor,
1042
+ minv.patch + 1,
1043
+ "0",
1044
+ void 0
1045
+ )
1046
+ ]);
1047
+ }
1048
+ }
1049
+ #parseEq(comp) {
1050
+ const parsed = this.#parseX(comp);
1051
+ const z = this.includePrerelease ? "0" : void 0;
1052
+ if (isFullVersion(parsed)) {
1053
+ this.tuples.push(["", new Version(comp, ...parsed)]);
1054
+ } else if (isXMajor(parsed)) {
1055
+ this.tuples.push(this.#getComparatorAny());
1056
+ } else if (isXMinor(parsed)) {
1057
+ this.tuples.push([
1058
+ ">=",
1059
+ new Version(comp, parsed[MAJOR], 0, 0, z, void 0)
1060
+ ]);
1061
+ this.tuples.push([
1062
+ "<",
1063
+ new Version(comp, parsed[MAJOR] + 1, 0, 0, "0", void 0)
1064
+ ]);
1065
+ } else if (isXPatch(parsed)) {
1066
+ this.tuples.push(
1067
+ [
1068
+ ">=",
1069
+ new Version(
1070
+ comp,
1071
+ parsed[MAJOR],
1072
+ parsed[MINOR],
1073
+ 0,
1074
+ z,
1075
+ void 0
1076
+ )
1077
+ ],
1078
+ [
1079
+ "<",
1080
+ new Version(
1081
+ comp,
1082
+ parsed[MAJOR],
1083
+ parsed[MINOR] + 1,
1084
+ 0,
1085
+ "0",
1086
+ void 0
1087
+ )
1088
+ ]
1089
+ );
1090
+ }
1091
+ }
1092
+ /** return true if the version is a match for this comparator */
1093
+ test(v) {
1094
+ if (this.isNone) return false;
1095
+ const ip = this.includePrerelease;
1096
+ const hasPR = !!v.prerelease?.length;
1097
+ let prOK = ip || !hasPR;
1098
+ for (const c of this.tuples) {
1099
+ if (isAny(c)) {
1100
+ continue;
1101
+ }
1102
+ const [op, cv] = c;
1103
+ prOK ||= !!cv.prerelease?.length && v.tupleEquals(cv);
1104
+ switch (op) {
1105
+ case "":
1106
+ if (!v.equals(cv)) return false;
1107
+ continue;
1108
+ case ">":
1109
+ if (!v.greaterThan(cv)) return false;
1110
+ continue;
1111
+ case ">=":
1112
+ if (!v.greaterThanEqual(cv)) return false;
1113
+ continue;
1114
+ case "<":
1115
+ if (!v.lessThan(cv)) return false;
1116
+ continue;
1117
+ case "<=":
1118
+ if (!v.lessThanEqual(cv)) return false;
1119
+ continue;
1120
+ }
1121
+ }
1122
+ return prOK;
1123
+ }
1124
+ #getComparatorAny() {
1125
+ return this.includePrerelease ? comparatorAnyPR : comparatorAny;
1126
+ }
1127
+ };
1128
+ var isAny = (c) => c === comparatorAny || c === comparatorAnyPR;
1129
+ var comparatorAny = {
1130
+ isAny: true,
1131
+ toString: () => "*",
1132
+ includePrerelease: false,
1133
+ test: (v) => !v.prerelease?.length
1134
+ };
1135
+ var comparatorAnyPR = {
1136
+ isAny: true,
1137
+ toString: () => "*",
1138
+ includePrerelease: true,
1139
+ test: (_) => true
1140
+ };
1141
+ var comparatorNone = {
1142
+ isNone: true,
1143
+ toString: () => "<0.0.0-0",
1144
+ includePrerelease: false,
1145
+ test: (_) => false
1146
+ };
1147
+
1148
+ // ../../src/types/src/index.ts
1149
+ var asError = (er, fallbackMessage = "Unknown error") => er instanceof Error ? er : new Error(String(er) || fallbackMessage);
1150
+
1151
+ // ../../src/semver/src/range.ts
1152
+ var Range = class {
1153
+ /** raw string used to create this Range */
1154
+ raw;
1155
+ /** true if the range is `*` */
1156
+ isAny;
1157
+ /** true if the range is a single semver version */
1158
+ isSingle;
1159
+ /** true if the range cannot match anything */
1160
+ /**
1161
+ * set of {@link Comparator} objects representing the `||`-separated sections
1162
+ * of the range. If at least one of these matches, then the version is a
1163
+ * match.
1164
+ */
1165
+ set = [];
1166
+ /** true if all prerelease versions should be included */
1167
+ includePrerelease;
1168
+ /** cached toString */
1169
+ #toString;
1170
+ constructor(range, includePrerelease = false) {
1171
+ this.raw = range;
1172
+ this.includePrerelease = includePrerelease;
1173
+ this.isAny = false;
1174
+ let isFirst = true;
1175
+ this.isSingle = false;
1176
+ const comparatorErrors = [];
1177
+ fastSplit(range, "||", -1, (part) => {
1178
+ if (this.isAny) return;
1179
+ const cmp = this.#maybeComparator(part, this.includePrerelease);
1180
+ if (cmp instanceof Error) {
1181
+ comparatorErrors.push(cmp);
1182
+ return;
1183
+ }
1184
+ if (cmp.isAny) {
1185
+ this.set = [cmp];
1186
+ this.isAny = true;
1187
+ return;
1188
+ }
1189
+ this.set.push(cmp);
1190
+ if (!isFirst) this.isSingle = false;
1191
+ else if (Array.isArray(cmp.tuples) && cmp.tuples.length === 1 && Array.isArray(cmp.tuples[0]) && cmp.tuples[0][0] === "") {
1192
+ this.isSingle = true;
1193
+ }
1194
+ isFirst = false;
1195
+ });
1196
+ if (!this.set.length && comparatorErrors.length) {
1197
+ if (comparatorErrors.length === 1 && comparatorErrors[0]) {
1198
+ throw comparatorErrors[0];
1199
+ }
1200
+ throw new AggregateError(comparatorErrors);
1201
+ }
1202
+ }
1203
+ #maybeComparator(part, includePrerelease) {
1204
+ try {
1205
+ return new Comparator(part, includePrerelease);
1206
+ } catch (er) {
1207
+ return asError(er);
1208
+ }
1209
+ }
1210
+ /**
1211
+ * test a {@link Version} against the range
1212
+ */
1213
+ test(v) {
1214
+ return this.set.some((c) => c.test(v));
1215
+ }
1216
+ /** return the simplified canonical form of this range */
1217
+ toString() {
1218
+ if (this.#toString) return this.#toString;
1219
+ if (this.isSingle) {
1220
+ this.#toString = String(this.set[0]);
1221
+ return this.#toString;
1222
+ }
1223
+ this.#toString = this.set.map((c) => String(c)).join(" || ");
1224
+ return this.#toString;
1225
+ }
1226
+ };
1227
+
1228
+ // ../../src/semver/src/index.ts
1229
+ var parseRange = (range, includePrerelease = false) => {
1230
+ if (typeof range === "object") {
1231
+ if (range.includePrerelease === includePrerelease) return range;
1232
+ range = range.raw;
1233
+ }
1234
+ try {
1235
+ return new Range(range, includePrerelease);
1236
+ } catch {
1237
+ return void 0;
1238
+ }
1239
+ };
1240
+
1241
+ // ../../src/spec/src/browser.ts
1242
+ var kCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
1243
+ var defaultRegistry = "https://registry.npmjs.org/";
1244
+ var defaultRegistryName = "npm";
1245
+ var defaultRegistries = {
1246
+ npm: defaultRegistry,
1247
+ gh: "https://npm.pkg.github.com/"
1248
+ };
1249
+ var defaultJsrRegistries = { jsr: "https://npm.jsr.io/" };
1250
+ var defaultGitHosts = {
1251
+ github: "git+ssh://git@github.com:$1/$2.git",
1252
+ bitbucket: "git+ssh://git@bitbucket.org:$1/$2.git",
1253
+ gitlab: "git+ssh://git@gitlab.com:$1/$2.git",
1254
+ gist: "git+ssh://git@gist.github.com/$1.git"
1255
+ };
1256
+ var defaultGitHostArchives = {
1257
+ github: "https://api.github.com/repos/$1/$2/tarball/$committish",
1258
+ bitbucket: "https://bitbucket.org/$1/$2/get/$committish.tar.gz",
1259
+ gist: "https://codeload.github.com/gist/$1/tar.gz/$committish",
1260
+ gitlab: "https://gitlab.com/$1/$2/repository/archive.tar.gz?ref=$committish"
1261
+ };
1262
+ var gitHostWebsites = {
1263
+ github: "https://github.com/",
1264
+ bitbucket: "https://bitbucket.org/",
1265
+ gist: "https://gist.github.com/",
1266
+ gitlab: "https://gitlab.com/"
1267
+ };
1268
+ var getOptions = (options) => ({
1269
+ catalog: {},
1270
+ catalogs: {},
1271
+ ...options,
1272
+ "jsr-registries": {
1273
+ ...options?.["jsr-registries"] ?? {},
1274
+ ...defaultJsrRegistries
1275
+ },
1276
+ registry: options?.registry ?? defaultRegistry,
1277
+ "scope-registries": options?.["scope-registries"] ?? {},
1278
+ "git-hosts": options?.["git-hosts"] ? {
1279
+ ...defaultGitHosts,
1280
+ ...options["git-hosts"]
1281
+ } : defaultGitHosts,
1282
+ registries: {
1283
+ ...options?.registries ?? {},
1284
+ ...defaultRegistries
1285
+ },
1286
+ "git-host-archives": options?.["git-host-archives"] ? {
1287
+ ...defaultGitHostArchives,
1288
+ ...options["git-host-archives"]
1289
+ } : defaultGitHostArchives
1290
+ });
1291
+ var startsWithSpecIdentifier = (spec, options) => spec.startsWith("/") || spec.startsWith("./") || spec.startsWith("../") || spec.startsWith("file:") || spec.startsWith("http:") || spec.startsWith("https:") || spec.startsWith("workspace:") || spec.startsWith("catalog:") || spec.startsWith("git@") || spec.startsWith("git://") || spec.startsWith("git+ssh://") || spec.startsWith("git+http://") || spec.startsWith("git+https://") || spec.startsWith("git+file://") || spec.startsWith("git@github.com") || spec.startsWith("registry:") || spec.startsWith("npm:") || spec.startsWith("jsr:") || spec.startsWith("gh:") || // anything that starts with a known git host key, or a
1292
+ // custom registered registry protocol e.g: `github:`, `custom:`
1293
+ [
1294
+ ...Object.keys(options["git-hosts"]),
1295
+ ...Object.keys(options.registries),
1296
+ ...Object.keys(options["jsr-registries"])
1297
+ ].some((key) => spec.startsWith(`${key}:`));
1298
+ var findFirstAt = (spec, hasScope) => spec.indexOf("@", hasScope ? 1 : 0);
1299
+ var findGitIdentifier = (spec) => spec.indexOf("#") > 2;
1300
+ var findFileIdentifier = (spec) => spec.includes("/");
1301
+ var Spec = class _Spec {
1302
+ static parse(spec, bareOrOptions, options) {
1303
+ return typeof spec === "object" ? spec : new this(spec, bareOrOptions, options);
1304
+ }
1305
+ static parseArgs(specOrBareSpec, opts) {
1306
+ const options = getOptions(opts ?? {});
1307
+ if (startsWithSpecIdentifier(specOrBareSpec, options)) {
1308
+ const parsed = this.parse("(unknown)", specOrBareSpec, options);
1309
+ if (parsed.subspec) {
1310
+ const { namedJsrRegistry: jsrHost } = parsed;
1311
+ if (!jsrHost) {
1312
+ parsed.name = parsed.subspec.name;
1313
+ }
1314
+ parsed.spec = `${parsed.name}@${parsed.bareSpec}`;
1315
+ }
1316
+ return parsed;
1317
+ } else {
1318
+ const hasScope = specOrBareSpec.startsWith("@");
1319
+ const at = findFirstAt(specOrBareSpec, hasScope);
1320
+ if (at > -1) {
1321
+ return this.parse(
1322
+ specOrBareSpec.substring(0, at),
1323
+ specOrBareSpec.substring(at + 1),
1324
+ options
1325
+ );
1326
+ } else if (findGitIdentifier(specOrBareSpec) || !hasScope && findFileIdentifier(specOrBareSpec)) {
1327
+ return this.parse("(unknown)", specOrBareSpec, options);
1328
+ } else {
1329
+ return this.parse(`${specOrBareSpec}@`, options);
1330
+ }
1331
+ }
1332
+ }
1333
+ static nodejsDependencies;
1334
+ type;
1335
+ spec;
1336
+ options;
1337
+ name;
1338
+ scope;
1339
+ scopeRegistry;
1340
+ bareSpec;
1341
+ gitRemote;
1342
+ gitSelector;
1343
+ gitSelectorParsed;
1344
+ gitCommittish;
1345
+ namedGitHost;
1346
+ namedGitHostPath;
1347
+ workspaceSpec;
1348
+ workspace;
1349
+ namedRegistry;
1350
+ namedJsrRegistry;
1351
+ registry;
1352
+ registrySpec;
1353
+ conventionalRegistryTarball;
1354
+ semver;
1355
+ range;
1356
+ distTag;
1357
+ remoteURL;
1358
+ file;
1359
+ catalog;
1360
+ subspec;
1361
+ overridden = false;
1362
+ #final;
1363
+ #toString;
1364
+ /**
1365
+ * Return the final entry in the chain of subspecs
1366
+ * When deciding which thing to actually fetch, spec.final is the thing
1367
+ * to look at.
1368
+ */
1369
+ get final() {
1370
+ if (this.#final) return this.#final;
1371
+ const final = this.subspec ? this.subspec.final : this;
1372
+ if (final.type === "catalog") {
1373
+ throw error('invalid Spec.final value, type is "catalog"');
1374
+ }
1375
+ return this.#final = final;
1376
+ }
1377
+ /**
1378
+ * Normally, the string value of a Spec is just the string passed in to
1379
+ * be parsed. However, in the case of a chain of subspecs, like
1380
+ * `foo@npm:bar@npm:baz@npm:quux@latest`, this simplifies out the middle
1381
+ * parts of the chain, returning just `foo@npm:quux@latest`
1382
+ */
1383
+ toString() {
1384
+ if (this.#toString !== void 0) return this.#toString;
1385
+ let sub = this;
1386
+ while (sub.subspec?.subspec) sub = sub.subspec;
1387
+ if (sub.subspec && sub.subspec.type !== "registry")
1388
+ sub = sub.subspec;
1389
+ return this.#toString = this.name + "@" + sub.bareSpec;
1390
+ }
1391
+ constructor(spec, bareOrOptions, options = {}) {
1392
+ if (bareOrOptions && typeof bareOrOptions === "object") {
1393
+ options = bareOrOptions;
1394
+ bareOrOptions = void 0;
1395
+ }
1396
+ this.options = getOptions(options);
1397
+ if (typeof bareOrOptions === "string") {
1398
+ this.name = spec;
1399
+ this.#parseScope(spec);
1400
+ this.bareSpec = bareOrOptions;
1401
+ this.spec = `${this.name}@${bareOrOptions}`;
1402
+ } else {
1403
+ this.spec = spec;
1404
+ if (!spec.startsWith("git@") && startsWithSpecIdentifier(spec, this.options) && spec.includes(":") && [
1405
+ ...Object.keys(this.options.registries),
1406
+ ...Object.keys(defaultRegistries)
1407
+ ].some((key) => spec.startsWith(`${key}:`))) {
1408
+ this.name = spec;
1409
+ this.bareSpec = spec;
1410
+ } else {
1411
+ const hasScope = spec.startsWith("@");
1412
+ let at = findFirstAt(spec, hasScope);
1413
+ if (at === -1) {
1414
+ at = spec.length;
1415
+ spec += "@";
1416
+ }
1417
+ this.name = spec.substring(0, at);
1418
+ if (hasScope) this.#parseScope(this.name);
1419
+ this.bareSpec = spec.substring(at + 1);
1420
+ }
1421
+ }
1422
+ if (this.bareSpec.startsWith("catalog:")) {
1423
+ this.catalog = this.bareSpec.substring("catalog:".length);
1424
+ const catalog = this.catalog ? this.options.catalogs?.[this.catalog] : this.options.catalog;
1425
+ if (!catalog) {
1426
+ throw this.#error("Named catalog not found", {
1427
+ name: this.catalog,
1428
+ validOptions: this.options.catalogs && Object.keys(this.options.catalogs)
1429
+ });
1430
+ }
1431
+ const sub = catalog[this.name];
1432
+ if (!sub) {
1433
+ throw this.#error("Name not found in catalog", {
1434
+ name: this.name,
1435
+ validOptions: Object.keys(catalog)
1436
+ });
1437
+ }
1438
+ this.subspec = _Spec.parse(this.name, sub);
1439
+ this.type = "catalog";
1440
+ return;
1441
+ }
1442
+ if (this.bareSpec.startsWith("https://")) {
1443
+ for (const [name, origin] of Object.entries(gitHostWebsites)) {
1444
+ if (this.bareSpec.startsWith(origin)) {
1445
+ const parsed = new URL(this.bareSpec);
1446
+ const [user, project] = parsed.pathname.replace(/\.git$/, "").replace(/\/+/g, " ").trim().split(" ");
1447
+ if (user && project) {
1448
+ this.bareSpec = `${name}:${user}/${project}${parsed.hash}`;
1449
+ this.spec = `${this.name}@${this.bareSpec}`;
1450
+ break;
1451
+ }
1452
+ }
1453
+ }
1454
+ }
1455
+ if (this.bareSpec.startsWith("workspace:")) {
1456
+ this.type = "workspace";
1457
+ const ws = this.bareSpec.substring("workspace:".length).trim();
1458
+ const w = ws.lastIndexOf("@");
1459
+ if (w === -1) {
1460
+ this.workspace = this.name;
1461
+ } else {
1462
+ const wsName = ws.substring(0, w);
1463
+ if (!wsName || wsName === "*" || wsName === "~" || wsName === "^" || (wsName.startsWith("@") ? wsName.split("/").length !== 2 || wsName.substring(1).includes("@") : wsName.includes("@"))) {
1464
+ throw this.#error(
1465
+ "workspace: name must be a path or valid package name",
1466
+ { found: wsName }
1467
+ );
1468
+ }
1469
+ this.workspace = wsName;
1470
+ }
1471
+ const wss = w === -1 ? ws : ws.substring(w + 1) || "*";
1472
+ const range2 = wss === "*" ? void 0 : parseRange(wss);
1473
+ if (wss !== "*" && wss !== "~" && wss !== "^" && !range2) {
1474
+ throw this.#error(
1475
+ "workspace: spec must be one of *, ~, or ^, or a valid semver range",
1476
+ {
1477
+ found: wss,
1478
+ wanted: `'*'|'~'|'^'|SemverRange`
1479
+ }
1480
+ );
1481
+ }
1482
+ this.workspaceSpec = wss;
1483
+ if (range2) {
1484
+ this.semver = wss;
1485
+ this.range = range2;
1486
+ }
1487
+ return;
1488
+ }
1489
+ if (this.bareSpec.startsWith("git://") || this.bareSpec.startsWith("git+ssh://") || this.bareSpec.startsWith("git+http://") || this.bareSpec.startsWith("git+https://") || this.bareSpec.startsWith("git+file://") || // legacy affordance
1490
+ this.bareSpec.startsWith("git@github.com")) {
1491
+ if (this.bareSpec.startsWith("git@")) {
1492
+ this.bareSpec = `git+ssh://${this.bareSpec}`;
1493
+ this.spec = `${this.name}@${this.bareSpec}`;
1494
+ }
1495
+ this.type = "git";
1496
+ for (const [name, host] of Object.entries(
1497
+ this.options["git-hosts"]
1498
+ )) {
1499
+ const s = host.indexOf("$");
1500
+ if (s > 0 && this.bareSpec.startsWith(host.substring(0, s))) {
1501
+ const p = this.bareSpec.substring(s).replace(/\.git(#.*)?$/, "$1");
1502
+ this.bareSpec = `${name}:${p}`;
1503
+ this.spec = `${this.name}@${this.bareSpec}`;
1504
+ this.#parseHostedGit(name, host);
1505
+ this.type = "git";
1506
+ return;
1507
+ }
1508
+ }
1509
+ this.#parseGitSelector(this.bareSpec);
1510
+ return;
1511
+ }
1512
+ const regs = Object.entries(this.options.registries);
1513
+ if (this.bareSpec.startsWith("registry:")) {
1514
+ const reg = this.bareSpec.substring("registry:".length);
1515
+ const h = reg.indexOf("#");
1516
+ if (h === -1) {
1517
+ throw this.#error("registry: must include name/version");
1518
+ }
1519
+ this.type = "registry";
1520
+ let url = reg.substring(0, h);
1521
+ if (!url.endsWith("/")) url += "/";
1522
+ const regSpec = reg.substring(h + 1);
1523
+ for (let [name, u] of regs) {
1524
+ if (!u.endsWith("/")) {
1525
+ u += "/";
1526
+ this.options.registries[name] = u;
1527
+ }
1528
+ if (u === url) this.namedRegistry = name;
1529
+ }
1530
+ this.#parseRegistrySpec(regSpec, url);
1531
+ this.#guessRegistryTarball();
1532
+ return;
1533
+ }
1534
+ for (const [host, url] of regs) {
1535
+ const h = `${host}:`;
1536
+ if (this.bareSpec.startsWith(h)) {
1537
+ this.type = "registry";
1538
+ this.namedRegistry = host;
1539
+ this.#parseRegistrySpec(
1540
+ this.bareSpec.substring(h.length),
1541
+ url
1542
+ ).namedRegistry ??= host;
1543
+ if (this.subspec && this.name === this.bareSpec) {
1544
+ this.name = this.subspec.name;
1545
+ this.spec = `${this.name}@${this.bareSpec}`;
1546
+ }
1547
+ this.#guessRegistryTarball();
1548
+ return;
1549
+ }
1550
+ }
1551
+ const ghosts = Object.entries(this.options["git-hosts"]);
1552
+ for (const [name, template] of ghosts) {
1553
+ if (this.#parseHostedGit(name, template)) {
1554
+ this.type = "git";
1555
+ return;
1556
+ }
1557
+ }
1558
+ const jsrs = Object.entries(this.options["jsr-registries"]);
1559
+ for (const [host, url] of jsrs) {
1560
+ const h = `${host}:`;
1561
+ if (this.bareSpec.startsWith(h)) {
1562
+ this.type = "registry";
1563
+ this.namedJsrRegistry = host;
1564
+ this.#parseJsrRegistrySpec(
1565
+ this.bareSpec.substring(h.length),
1566
+ url
1567
+ ).namedJsrRegistry ??= host;
1568
+ return;
1569
+ }
1570
+ }
1571
+ if (this.bareSpec.startsWith("https://") || this.bareSpec.startsWith("http://")) {
1572
+ this.remoteURL = this.bareSpec;
1573
+ this.type = "remote";
1574
+ return;
1575
+ }
1576
+ if (this.bareSpec.startsWith("file:")) {
1577
+ this.type = "file";
1578
+ const [path, uri] = getNormalizeFile(
1579
+ this.constructor.nodejsDependencies
1580
+ )(this.bareSpec, this);
1581
+ this.file = path;
1582
+ this.bareSpec = uri.replace(/\/+$/, "");
1583
+ this.spec = `${this.name}@${this.bareSpec}`;
1584
+ return;
1585
+ }
1586
+ if (!this.bareSpec.startsWith("./") && !this.bareSpec.startsWith("../") && this.options["git-hosts"].github) {
1587
+ const hash = this.bareSpec.indexOf("#");
1588
+ const up = hash === -1 ? this.bareSpec : this.bareSpec.substring(0, hash);
1589
+ if (up.split("/").length === 2) {
1590
+ this.bareSpec = `github:${this.bareSpec}`;
1591
+ this.spec = `${this.name}@${this.bareSpec}`;
1592
+ this.#parseHostedGit(
1593
+ "github",
1594
+ this.options["git-hosts"].github
1595
+ );
1596
+ this.type = "git";
1597
+ return;
1598
+ }
1599
+ }
1600
+ if (this.bareSpec.includes("/") || this.bareSpec === "." || this.bareSpec === "..") {
1601
+ this.type = "file";
1602
+ const [file, uri] = getNormalizeFile(
1603
+ this.constructor.nodejsDependencies
1604
+ )(`file:${this.bareSpec}`, this);
1605
+ this.bareSpec = uri;
1606
+ this.spec = `${this.name}@${this.bareSpec}`;
1607
+ this.file = file;
1608
+ return;
1609
+ }
1610
+ this.type = "registry";
1611
+ const range = parseRange(this.bareSpec);
1612
+ if (range) {
1613
+ this.semver = this.bareSpec.trim();
1614
+ this.range = range;
1615
+ } else {
1616
+ this.distTag = this.bareSpec;
1617
+ }
1618
+ this.registrySpec = this.bareSpec;
1619
+ const { "scope-registries": scopeRegs, registry } = this.options;
1620
+ const scopeReg = this.scope && scopeRegs[this.scope];
1621
+ this.registry = scopeReg ?? registry;
1622
+ for (const r of Object.values(this.options["jsr-registries"])) {
1623
+ if (this.registry === r) return;
1624
+ }
1625
+ this.#guessRegistryTarball();
1626
+ }
1627
+ #parseScope(name) {
1628
+ if (!name.startsWith("@")) return;
1629
+ const s = name.indexOf("/");
1630
+ if (s > 1 && s < name.length - 1) {
1631
+ const scope = name.substring(0, s);
1632
+ this.registry = this.scopeRegistry = this.options["scope-registries"][scope];
1633
+ this.scope = scope;
1634
+ }
1635
+ }
1636
+ #parseHostedGit(name, template) {
1637
+ if (this.bareSpec.startsWith(`${name}:`)) {
1638
+ const h = this.bareSpec.indexOf("#");
1639
+ const bare = h === -1 ? this.bareSpec : this.bareSpec.substring(0, h);
1640
+ const hash = h === -1 ? "" : this.bareSpec.substring(h);
1641
+ const hostPath = bare.substring(name.length + 1);
1642
+ if (!hostPath) {
1643
+ throw this.#error("invalid named git host specifier");
1644
+ }
1645
+ const split = hostPath.split("/");
1646
+ let t = template;
1647
+ for (let i = 0; i < split.length; i++) {
1648
+ t = t.split(`$${i + 1}`).join(split[i]);
1649
+ }
1650
+ t += hash;
1651
+ this.namedGitHost = name;
1652
+ this.namedGitHostPath = hostPath;
1653
+ this.#parseGitSelector(t);
1654
+ if (this.gitCommittish && !this.gitSelectorParsed?.path) {
1655
+ const archiveHost = this.options["git-host-archives"][name];
1656
+ if (name === "github" && this.gitCommittish.startsWith("pull/") && this.gitCommittish.match(/\//g)?.length === 1) {
1657
+ this.gitCommittish += "/head";
1658
+ }
1659
+ if (archiveHost) {
1660
+ this.type = "remote";
1661
+ let t2 = archiveHost;
1662
+ t2 = t2.split("$committish").join(this.gitCommittish);
1663
+ for (let i = 0; i < split.length; i++) {
1664
+ t2 = t2.split(`$${i + 1}`).join(split[i]);
1665
+ }
1666
+ this.remoteURL = t2;
1667
+ }
1668
+ }
1669
+ return true;
1670
+ }
1671
+ return false;
1672
+ }
1673
+ /* c8 ignore start */
1674
+ [kCustomInspect]() {
1675
+ return `@vltpkg/spec.Spec ${String(this)}`;
1676
+ }
1677
+ /* c8 ignore stop */
1678
+ #guessRegistryTarball() {
1679
+ const { name, registry, range } = this.final;
1680
+ if (!registry || !range?.isSingle) return;
1681
+ const stripScope = /^@[^/]+\//;
1682
+ this.conventionalRegistryTarball = String(
1683
+ new URL(
1684
+ `/${name}/-/${name.replace(stripScope, "")}-${range}.tgz`,
1685
+ registry
1686
+ )
1687
+ );
1688
+ }
1689
+ #parseRegistrySpec(s, url) {
1690
+ this.registry = url;
1691
+ this.subspec = this.constructor.parse(s, {
1692
+ ...this.options,
1693
+ registry: url
1694
+ });
1695
+ return this.subspec;
1696
+ }
1697
+ #parseJsrRegistrySpec(s, url) {
1698
+ this.registry = url;
1699
+ if (!s.startsWith("@")) s = `${this.name}@${s}`;
1700
+ const name = s.startsWith("@jsr/") ? s : `@jsr/${s.replace(/^@/, "").replace(/\//, "__")}`;
1701
+ this.subspec = this.constructor.parse(name, {
1702
+ ...this.options,
1703
+ "scope-registries": {
1704
+ ...this.options["scope-registries"],
1705
+ "@jsr": url
1706
+ }
1707
+ });
1708
+ if (this.name === "(unknown)") {
1709
+ const nextAt = s.indexOf("@", 1);
1710
+ if (nextAt === -1) {
1711
+ this.name = s;
1712
+ } else {
1713
+ this.name = s.substring(0, s.indexOf("@", 1));
1714
+ }
1715
+ }
1716
+ const reg = `${this.namedJsrRegistry}:`;
1717
+ const n = `${reg}${this.name}`;
1718
+ if (this.bareSpec.startsWith(n + "@")) {
1719
+ this.bareSpec = reg + this.bareSpec.substring(n.length + 1);
1720
+ } else if (this.bareSpec === n) {
1721
+ this.bareSpec = reg;
1722
+ }
1723
+ this.spec = this.name + "@" + this.bareSpec;
1724
+ return this.subspec;
1725
+ }
1726
+ #error(message, extra = {}) {
1727
+ return error(message, { spec: this.spec, ...extra }, this.#error);
1728
+ }
1729
+ #parseGitSelector(s) {
1730
+ const h = s.indexOf("#");
1731
+ if (h === -1) {
1732
+ this.gitRemote = s;
1733
+ return;
1734
+ }
1735
+ this.gitRemote = s.substring(0, h);
1736
+ this.gitSelector = s.substring(h + 1);
1737
+ const [selectorParsed, committish, range] = this.constructor.parseGitSelector(this.gitSelector, this);
1738
+ this.range = range;
1739
+ this.gitCommittish = committish;
1740
+ this.gitSelectorParsed = selectorParsed;
1741
+ }
1742
+ /**
1743
+ * Should only ever be called with the bit that comes AFTER the #
1744
+ * in the git remote url.
1745
+ */
1746
+ static parseGitSelector(selector, spec) {
1747
+ if (!selector) return [{}];
1748
+ const split = selector.split("::");
1749
+ const first = split[0];
1750
+ let committish = void 0;
1751
+ let range = void 0;
1752
+ const parsed = {};
1753
+ if (typeof first !== "string") {
1754
+ throw typeError("impossible", {
1755
+ found: first,
1756
+ wanted: String
1757
+ });
1758
+ }
1759
+ if (!first.includes(":")) {
1760
+ committish = first;
1761
+ split.shift();
1762
+ }
1763
+ for (const kv of split) {
1764
+ const c = kv.indexOf(":");
1765
+ if (c === -1) continue;
1766
+ const k = kv.substring(0, c);
1767
+ const v = kv.substring(c + 1);
1768
+ if (k === "semver") {
1769
+ if (committish) {
1770
+ throw error(
1771
+ "Cannot specify a semver range and committish value",
1772
+ { spec }
1773
+ );
1774
+ }
1775
+ range = parseRange(v);
1776
+ if (!range) {
1777
+ throw error(`Invalid git tag semver range: ${v}`, { spec });
1778
+ }
1779
+ }
1780
+ if (k === "semver" || k === "path") {
1781
+ if (k === "path") {
1782
+ if (
1783
+ /* c8 ignore next */
1784
+ this.nodejsDependencies?.isAbsolute(
1785
+ v
1786
+ ) || /(^|\/|\\)\.\.($|\\|\/)/.test(v)
1787
+ ) {
1788
+ throw error("Invalid path in git selector", { spec });
1789
+ }
1790
+ parsed.path = (this.nodejsDependencies ? this.nodejsDependencies.join("/", v).substring(1) : v).replace(/\\/g, "/");
1791
+ } else {
1792
+ parsed[k] = v;
1793
+ }
1794
+ }
1795
+ }
1796
+ return [parsed, committish, range];
1797
+ }
1798
+ };
1799
+ var getNormalizeFile = (opts) => (bareSpec, spec) => {
1800
+ const slashes = bareSpec.substring(
1801
+ "file:".length,
1802
+ "file://".length
1803
+ );
1804
+ const pref = `file:${slashes === "//" ? slashes : ""}`;
1805
+ const rest = bareSpec.substring(pref.length);
1806
+ const [a = "", b = "/", c = "/", d = "/"] = rest.split("", 4);
1807
+ if (!a) {
1808
+ return [".", "file:."];
1809
+ }
1810
+ if (a === "/" && b === "~" && c !== "/" || a === "~" && b !== "/") {
1811
+ throw error(
1812
+ `invalid file: specifier. '~username' not supported`,
1813
+ { spec }
1814
+ );
1815
+ }
1816
+ if (a === "~") {
1817
+ return (
1818
+ /* c8 ignore start */
1819
+ opts ? [
1820
+ opts.resolve(opts.homedir(), rest.substring(2)),
1821
+ `file:${rest}`
1822
+ ] : [rest, `file:${rest}`]
1823
+ );
1824
+ }
1825
+ if (a === "/" && b === "~") {
1826
+ return opts ? [
1827
+ opts.resolve(opts.homedir(), rest.substring(3)),
1828
+ `file:${rest.substring(1)}`
1829
+ ] : (
1830
+ /* c8 ignore stop */
1831
+ [rest.substring(1), `file:${rest.substring(1)}`]
1832
+ );
1833
+ }
1834
+ if (a === "/" && b === "." && (c === "/" || c === "." && d === "/")) {
1835
+ return [rest.substring(1), `file:${rest.substring(1)}`];
1836
+ }
1837
+ if (a === "." && (b === "/" || b === "." && c === "/")) {
1838
+ return [rest, `file:${rest}`];
1839
+ }
1840
+ if (slashes === "//") {
1841
+ try {
1842
+ const parsed = new URL(bareSpec);
1843
+ if (parsed.host) {
1844
+ if (parsed.host !== "localhost") {
1845
+ throw error(
1846
+ `invalid file:// specifier. host must be empty or 'localhost'`,
1847
+ {
1848
+ spec,
1849
+ found: parsed.host,
1850
+ validOptions: ["", "localhost"]
1851
+ }
1852
+ );
1853
+ }
1854
+ }
1855
+ return [
1856
+ parsed.pathname.replace(/^\/([a-zA-Z]:\/)/, "$1"),
1857
+ `file://${parsed.pathname}`
1858
+ ];
1859
+ } catch (er) {
1860
+ throw error("invalid file:// specifier", {
1861
+ spec,
1862
+ cause: er
1863
+ });
1864
+ }
1865
+ }
1866
+ if (opts?.winPath.isAbsolute(rest)) {
1867
+ return [rest, `file://${rest}`];
1868
+ }
1869
+ return [`./${rest}`, `file:./${rest}`];
1870
+ };
1871
+
1872
+ // ../../src/spec/src/index.ts
1873
+ var Spec2 = class extends Spec {
1874
+ [kCustomInspect](_depth, options) {
1875
+ const str = inspect(
1876
+ Object.fromEntries(
1877
+ Object.entries(this).filter(([k, v]) => {
1878
+ return k !== "options" && v !== void 0;
1879
+ })
1880
+ ),
1881
+ options
1882
+ );
1883
+ return `@vltpkg/spec.Spec ${str}`;
1884
+ }
1885
+ };
1886
+ Spec2.nodejsDependencies = {
1887
+ homedir,
1888
+ isAbsolute,
1889
+ join,
1890
+ resolve,
1891
+ winPath
1892
+ };
1893
+
1894
+ // ../../src/dep-id/src/browser.ts
1895
+ var delimiter = "~";
1896
+ var depIDRegExp = new RegExp(
1897
+ `^((git)?${delimiter}[^${delimiter}]*${delimiter}[^${delimiter}]*(${delimiter}[^${delimiter}]*)?$|^(file|remote|workspace)${delimiter}[^${delimiter}]*)(${delimiter}[^${delimiter}]*)?$`
1898
+ );
1899
+ var isDepID = (str) => typeof str === "string" && depIDRegExp.test(str);
1900
+ var asDepID = (str) => {
1901
+ if (!isDepID(str)) {
1902
+ throw error("Expected dep id", {
1903
+ found: str
1904
+ });
1905
+ }
1906
+ return str;
1907
+ };
1908
+ var joinDepIDTuple = (list) => {
1909
+ const [type, first, second, extra] = list;
1910
+ const f = encode(first);
1911
+ switch (type) {
1912
+ case "registry":
1913
+ return `${delimiter}${f || defaultRegistryName}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ""}`;
1914
+ case "git":
1915
+ return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ""}`;
1916
+ default:
1917
+ return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ""}`;
1918
+ }
1919
+ };
1920
+ var ESCAPE = {
1921
+ _: "__",
1922
+ "+": "_p",
1923
+ "\\": "_b",
1924
+ ":": "_c",
1925
+ "~": "_t",
1926
+ "<": "_l",
1927
+ ">": "_g",
1928
+ '"': "_q",
1929
+ "|": "_i",
1930
+ "?": "_m",
1931
+ "*": "_a",
1932
+ " ": "_s"
1933
+ };
1934
+ var UNESCAPE = {
1935
+ __: "_",
1936
+ _p: "+",
1937
+ _b: "\\",
1938
+ _c: ":",
1939
+ _t: "~",
1940
+ _l: "<",
1941
+ _g: ">",
1942
+ _q: '"',
1943
+ _i: "|",
1944
+ _m: "?",
1945
+ _a: "*",
1946
+ _d: ".",
1947
+ _s: " "
1948
+ };
1949
+ var isControl = (code) => code >= 0 && code <= 31;
1950
+ var toHex2Upper = (code) => code.toString(16).toUpperCase().padStart(2, "0");
1951
+ var isHexDigit = (c) => c >= "0" && c <= "9" || c >= "A" && c <= "F" || c >= "a" && c <= "f";
1952
+ var encode = (s) => {
1953
+ if (!s) return s;
1954
+ let out = "";
1955
+ for (const ch of s) {
1956
+ if (!ch) continue;
1957
+ if (ch === "/") {
1958
+ out += "+";
1959
+ continue;
1960
+ }
1961
+ const mapped = ESCAPE[ch];
1962
+ if (mapped) {
1963
+ out += mapped;
1964
+ continue;
1965
+ }
1966
+ const code = ch.charCodeAt(0);
1967
+ if (isControl(code)) {
1968
+ out += "_" + toHex2Upper(code);
1969
+ continue;
1970
+ }
1971
+ out += ch;
1972
+ }
1973
+ if (out.endsWith(".")) out = out.slice(0, -1) + "_d";
1974
+ return out;
1975
+ };
1976
+ var decode = (s) => {
1977
+ if (!s) return s;
1978
+ let out = "";
1979
+ for (let i = 0; i < s.length; i++) {
1980
+ const ch = s[i];
1981
+ if (!ch) continue;
1982
+ if (ch === "+") {
1983
+ out += "/";
1984
+ continue;
1985
+ }
1986
+ if (ch !== "_") {
1987
+ out += ch;
1988
+ continue;
1989
+ }
1990
+ const next = s[i + 1];
1991
+ if (next === void 0) {
1992
+ out += "_";
1993
+ continue;
1994
+ }
1995
+ if (next === "_") {
1996
+ out += "_";
1997
+ i += 1;
1998
+ continue;
1999
+ }
2000
+ const two = s.slice(i, i + 2);
2001
+ const mapped = UNESCAPE[two];
2002
+ if (mapped) {
2003
+ out += mapped;
2004
+ i += 1;
2005
+ continue;
2006
+ }
2007
+ const h1 = s[i + 1];
2008
+ const h2 = s[i + 2];
2009
+ if ((h1 === "0" || h1 === "1") && h2 !== void 0 && isHexDigit(h2)) {
2010
+ const hex = s.slice(i + 1, i + 3);
2011
+ out += String.fromCharCode(parseInt(hex, 16));
2012
+ i += 2;
2013
+ continue;
2014
+ }
2015
+ out += "_";
2016
+ }
2017
+ return out;
2018
+ };
2019
+ var seenSplitDepIDs = /* @__PURE__ */ new Map();
2020
+ var splitDepID = (id) => {
2021
+ const seen = seenSplitDepIDs.get(id);
2022
+ if (seen) return seen;
2023
+ let res;
2024
+ const [type, first = "", second, extra] = id.split(delimiter, 4);
2025
+ const f = decode(first) || "";
2026
+ switch (type) {
2027
+ case "git":
2028
+ case "": {
2029
+ if (second === void 0) {
2030
+ throw error(`invalid ${type} id`, { found: id });
2031
+ }
2032
+ const decodedSecond = decode(second) || "";
2033
+ res = [
2034
+ type || "registry",
2035
+ f || defaultRegistryName,
2036
+ decodedSecond,
2037
+ decode(extra)
2038
+ ];
2039
+ break;
2040
+ }
2041
+ case "file":
2042
+ case "remote":
2043
+ case "workspace": {
2044
+ res = [type, f, decode(second)];
2045
+ break;
2046
+ }
2047
+ default: {
2048
+ throw error("invalid DepID type", {
2049
+ found: type,
2050
+ validOptions: ["git", "file", "workspace", "remote", ""]
2051
+ });
2052
+ }
2053
+ }
2054
+ seenSplitDepIDs.set(id, res);
2055
+ return res;
2056
+ };
2057
+ var baseDepID = (id) => {
2058
+ const [type, first, second] = splitDepID(id);
2059
+ switch (type) {
2060
+ case "git":
2061
+ case "registry":
2062
+ return joinDepIDTuple([type, first, second]);
2063
+ default:
2064
+ return joinDepIDTuple([type, first]);
2065
+ }
2066
+ };
2067
+
2068
+ // ../../node_modules/.vlt/~npm~package-json-from-dist@1.0.1/node_modules/package-json-from-dist/dist/esm/index.js
2069
+ import { readFileSync } from "node:fs";
2070
+ import { dirname, resolve as resolve2, sep } from "node:path";
2071
+ import { fileURLToPath } from "node:url";
2072
+ var NM = `${sep}node_modules${sep}`;
2073
+ var STORE = `.store${sep}`;
2074
+ var PKG = `${sep}package${sep}`;
2075
+ var DIST = `${sep}dist${sep}`;
2076
+ var findPackageJson = (from, pathFromSrc = "../package.json") => {
2077
+ const f = typeof from === "object" || from.startsWith("file://") ? fileURLToPath(from) : from;
2078
+ const __dirname = dirname(f);
2079
+ const nms = __dirname.lastIndexOf(NM);
2080
+ if (nms !== -1) {
2081
+ const nm = __dirname.substring(0, nms + NM.length);
2082
+ const pkgDir = __dirname.substring(nms + NM.length);
2083
+ if (pkgDir.startsWith(STORE)) {
2084
+ const pkg = pkgDir.indexOf(PKG, STORE.length);
2085
+ if (pkg) {
2086
+ return resolve2(nm, pkgDir.substring(0, pkg + PKG.length), "package.json");
2087
+ }
2088
+ }
2089
+ const pkgName = pkgDir.startsWith("@") ? pkgDir.split(sep, 2).join(sep) : String(pkgDir.split(sep)[0]);
2090
+ return resolve2(nm, pkgName, "package.json");
2091
+ } else {
2092
+ const d = __dirname.lastIndexOf(DIST);
2093
+ if (d !== -1) {
2094
+ return resolve2(__dirname.substring(0, d), "package.json");
2095
+ } else {
2096
+ return resolve2(__dirname, pathFromSrc);
2097
+ }
2098
+ }
2099
+ };
2100
+ var loadPackageJson = (from, pathFromSrc = "../package.json") => JSON.parse(readFileSync(findPackageJson(from, pathFromSrc), "utf8"));
2101
+
2102
+ // ../../src/security-archive/src/types.ts
2103
+ var isPackageReportData = (o) => typeof o === "object" && o != null && "id" in o && "type" in o && "name" in o && "version" in o && "alerts" in o && "score" in o && o.type === "npm";
2104
+ var asPackageReportData = (o) => {
2105
+ if (!isPackageReportData(o)) {
2106
+ throw error("Invalid package report data", { found: o });
2107
+ }
2108
+ return o;
2109
+ };
2110
+
2111
+ // ../../src/security-archive/src/update-expired.ts
2112
+ var __CODE_SPLIT_SCRIPT_NAME = import.meta.filename;
2113
+ var SOCKET_API_V0_URL = "https://api.socket.dev/v0/purl?alerts=true";
2114
+ var SOCKET_PUBLIC_API_TOKEN = "sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api";
2115
+ var { version } = loadPackageJson(
2116
+ import.meta.filename,
2117
+ "cli-package.json"
2118
+ );
2119
+ var isMain = (path) => path === __CODE_SPLIT_SCRIPT_NAME || path === pathToFileURL(__CODE_SPLIT_SCRIPT_NAME).toString();
2120
+ var retrieveRemoteData = async (queue, retries) => {
2121
+ return pRetry(
2122
+ async () => {
2123
+ const req = await fetch(SOCKET_API_V0_URL, {
2124
+ method: "POST",
2125
+ headers: {
2126
+ Authorization: `Basic ${Buffer.from(`${SOCKET_PUBLIC_API_TOKEN}:`).toString("base64url")}`,
2127
+ "User-Agent": `@vltpkg/security-archive/${version}`
2128
+ },
2129
+ body: JSON.stringify({
2130
+ components: Array.from(queue)
2131
+ })
2132
+ });
2133
+ if (req.status === 404) {
2134
+ throw new AbortError("Missing API");
2135
+ }
2136
+ if (!req.ok || !(req.status >= 200 && req.status <= 299)) {
2137
+ throw error("Failed to fetch security data", {
2138
+ response: req
2139
+ });
2140
+ }
2141
+ const str = await req.text();
2142
+ return str.trim() + "\n";
2143
+ },
2144
+ { retries }
2145
+ );
2146
+ };
2147
+ var main = async (input = process.stdin) => {
2148
+ const payload = await new Promise(
2149
+ (resolve3, reject) => {
2150
+ const chunks = [];
2151
+ let chunkLen = 0;
2152
+ input.on("data", (chunk) => {
2153
+ chunks.push(chunk);
2154
+ chunkLen += chunk.length;
2155
+ });
2156
+ input.on("end", () => {
2157
+ try {
2158
+ const raw = Buffer.concat(chunks, chunkLen).toString();
2159
+ resolve3(JSON.parse(raw));
2160
+ } catch (err) {
2161
+ reject(err);
2162
+ }
2163
+ });
2164
+ input.on("error", reject);
2165
+ }
2166
+ );
2167
+ const { dbPath, retries, ttl, expired } = payload;
2168
+ if (!expired.length) {
2169
+ return false;
2170
+ }
2171
+ const expiredQueue = /* @__PURE__ */ new Set();
2172
+ const entryByNameVersion = /* @__PURE__ */ new Map();
2173
+ for (const entry of expired) {
2174
+ const purl = `pkg:npm/${entry.name}@${entry.version}`;
2175
+ expiredQueue.add({ purl });
2176
+ entryByNameVersion.set(`${entry.name}@${entry.version}`, entry);
2177
+ }
2178
+ const res = await retrieveRemoteData(expiredQueue, retries);
2179
+ const now = Date.now();
2180
+ const results = [];
2181
+ const json = res.split("}\n");
2182
+ for (const line of json) {
2183
+ if (!line.trim()) continue;
2184
+ const data = JSON.parse(line + "}");
2185
+ const scope = data.namespace ? `${data.namespace}/` : "";
2186
+ const name = `${scope}${data.name}`;
2187
+ const key = `${name}@${data.version}`;
2188
+ const entry = entryByNameVersion.get(key);
2189
+ if (!entry) {
2190
+ console.warn(
2191
+ `security-archive: failed to find entry for ${key} found in the response.`
2192
+ );
2193
+ continue;
2194
+ }
2195
+ const scoreComponents = [
2196
+ data.score.license,
2197
+ data.score.maintenance,
2198
+ data.score.quality,
2199
+ data.score.supplyChain,
2200
+ data.score.vulnerability
2201
+ ];
2202
+ const newAverageScore = Number(
2203
+ (scoreComponents.reduce((sum, score) => sum + score, 0) / scoreComponents.length).toFixed(2)
2204
+ );
2205
+ const reportData = asPackageReportData({
2206
+ ...data,
2207
+ score: { ...data.score, overall: newAverageScore }
2208
+ });
2209
+ results.push({
2210
+ depID: baseDepID(asDepID(entry.depID)),
2211
+ report: JSON.stringify(reportData),
2212
+ start: now,
2213
+ ttl
2214
+ });
2215
+ }
2216
+ if (!results.length) {
2217
+ return false;
2218
+ }
2219
+ mkdirSync(dirname2(dbPath), { recursive: true });
2220
+ const db = new DatabaseSync(dbPath);
2221
+ db.exec(
2222
+ "CREATE TABLE IF NOT EXISTS cache (depID TEXT PRIMARY KEY, report TEXT, ttl INTEGER, start INTEGER) WITHOUT ROWID"
2223
+ );
2224
+ db.exec("PRAGMA journal_mode = WAL");
2225
+ db.exec("PRAGMA synchronous = NORMAL");
2226
+ const dbWrite = db.prepare(
2227
+ "INSERT OR REPLACE INTO cache (depID, report, start, ttl) VALUES (?, ?, ?, ?)"
2228
+ );
2229
+ for (const { depID, report, start, ttl: entryTtl } of results) {
2230
+ dbWrite.run(depID, report, start, entryTtl);
2231
+ }
2232
+ db.exec("PRAGMA optimize");
2233
+ db.close();
2234
+ return true;
2235
+ };
2236
+ if (isMain(process.argv[1])) {
2237
+ process.title = "vlt-security-archive-update";
2238
+ const res = await main(process.stdin);
2239
+ if (!res) {
2240
+ process.exit(1);
2241
+ }
2242
+ }
2243
+ export {
2244
+ __CODE_SPLIT_SCRIPT_NAME,
2245
+ main,
2246
+ version
2247
+ };