@vltpkg/cli-js 1.1.1 → 1.3.0

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 (85) hide show
  1. package/{access-YYMAAPHV.js → access-HIVJOWXZ.js} +10 -10
  2. package/{bugs-RK5JBPSC.js → bugs-2KFUYMPS.js} +19 -19
  3. package/{build-DVJSYCNF.js → build-CX6YZ4LS.js} +12 -12
  4. package/{cache-JKQNGZ7L.js → cache-I6L5ZRGD.js} +145 -16
  5. package/cache-unzip-src-unzip.js +2953 -164
  6. package/{src-MOKZQTH2.js → chunk-263MHLR3.js} +299 -43
  7. package/{chunk-3LUM7NX5.js → chunk-2HXJ4ZSF.js} +3 -3
  8. package/{chunk-GDJ7JT2R.js → chunk-33HBY5CF.js} +1 -1
  9. package/{chunk-MZA6N2TA.js → chunk-C6LK7C3L.js} +4 -4
  10. package/{chunk-34TE4HZS.js → chunk-CU752KW7.js} +2 -2
  11. package/{chunk-2PWSMJD7.js → chunk-D2LEK7VS.js} +1 -1
  12. package/{chunk-CEHPRPGQ.js → chunk-ENSGPOLR.js} +46 -0
  13. package/{chunk-V4YCZZHY.js → chunk-EP7AVBIO.js} +16 -8
  14. package/{chunk-DS7YMIHP.js → chunk-FHMIECHI.js} +158 -59
  15. package/chunk-GDV5LSQ2.js +75 -0
  16. package/{chunk-BWEH7DHQ.js → chunk-HCZOVC3Y.js} +1 -1
  17. package/{chunk-CBASIDQH.js → chunk-I6QGYSB4.js} +1 -1
  18. package/{chunk-KDF7PEBY.js → chunk-ILRJWH6A.js} +5 -5
  19. package/{chunk-JZJWASXL.js → chunk-J2WL3A3C.js} +134 -68
  20. package/{chunk-YOE3VZFX.js → chunk-J3R4XWB3.js} +2 -2
  21. package/{chunk-DF5K4CYR.js → chunk-JFHEXCG5.js} +5 -5
  22. package/{chunk-LR42WTKN.js → chunk-MJWUULO6.js} +14 -12
  23. package/{chunk-QQYTPGIL.js → chunk-N4RCKCHY.js} +1 -1
  24. package/{chunk-X2AWQGYG.js → chunk-P4LLYWCG.js} +112 -23
  25. package/{chunk-BHJT53TP.js → chunk-PDWPFR5T.js} +1 -1
  26. package/{chunk-XIF734VO.js → chunk-QETVMIIT.js} +4 -4
  27. package/{chunk-WE2TQN32.js → chunk-QWJDHBV7.js} +4 -3
  28. package/{chunk-VFBCWAOC.js → chunk-RH2Y7MPW.js} +29 -0
  29. package/{chunk-LN2A74PF.js → chunk-SVMH3NDM.js} +277 -50
  30. package/{chunk-DR4Z63B6.js → chunk-TYLYZKVA.js} +14 -11
  31. package/{chunk-XKVU23NC.js → chunk-V7EQZOO5.js} +1 -1
  32. package/{chunk-YBVTY6ZW.js → chunk-VBADA6QU.js} +1 -1
  33. package/{chunk-GDT6KI4I.js → chunk-W6UMN2YJ.js} +4 -4
  34. package/{chunk-VE6CCH33.js → chunk-Y5PA7DVK.js} +1 -0
  35. package/{chunk-6FT6K5YN.js → chunk-YZWFWSY7.js} +25 -7
  36. package/{chunk-SNOBGFNM.js → chunk-ZNUXDX6R.js} +50 -8
  37. package/{ci-WVYVR4XK.js → ci-BX54SEU3.js} +12 -12
  38. package/cli-package.json +3 -2
  39. package/{config-VYOTYBGS.js → config-HFF6XDCV.js} +9 -9
  40. package/{config-2MFZVP2N.js → config-WBVJX42R.js} +12 -12
  41. package/{create-OJPLHBRR.js → create-W67HRHWZ.js} +20 -20
  42. package/{deprecate-V4PKGFF7.js → deprecate-5T6JTGJ3.js} +14 -14
  43. package/{devtools-UEMPW5GG.js → devtools-UMJUK42W.js} +2 -2
  44. package/{dist-tag-DNLV4VDE.js → dist-tag-YIZTS7GF.js} +10 -10
  45. package/{docs-LXHDCGL5.js → docs-G7CKMPCL.js} +19 -19
  46. package/{exec-P32YSP44.js → exec-YYCAZZ6Z.js} +20 -20
  47. package/{exec-cache-JZ5PDTOY.js → exec-cache-6ENHAGC6.js} +18 -18
  48. package/{exec-local-HHA464H4.js → exec-local-OXG3PSLF.js} +17 -17
  49. package/{help-GVTTOYUL.js → help-RMOIAILM.js} +4 -4
  50. package/{init-RENGG74N.js → init-UPEQXC4D.js} +12 -12
  51. package/{install-V6VXOBH2.js → install-U7LLEQU6.js} +18 -18
  52. package/{list-7N7Y5OXB.js → list-N6CKPXTK.js} +20 -20
  53. package/{login-D2QSAUJC.js → login-MCO4ZLVF.js} +14 -14
  54. package/{logout-QPOYBQNF.js → logout-BJ4QRZYG.js} +10 -10
  55. package/{pack-4YYGXP3A.js → pack-U6PYRFZ6.js} +13 -13
  56. package/package.json +1 -1
  57. package/{ping-QYRIZONU.js → ping-VFB6SCMH.js} +10 -10
  58. package/{pkg-WQTNABKT.js → pkg-ZNK5SCF4.js} +13 -13
  59. package/{profile-PRI7WXK7.js → profile-TW32HLYA.js} +10 -10
  60. package/{publish-PSBYJQS7.js → publish-AHOITWZQ.js} +36 -21
  61. package/{query-UFYLQW4N.js → query-KKP5PNSQ.js} +20 -20
  62. package/{registry-YTJZ3AQD.js → registry-VHB65BWD.js} +5 -5
  63. package/registry-client-src-revalidate.js +5936 -5801
  64. package/{repo-4S6ETFXX.js → repo-BHTVK5KE.js} +19 -19
  65. package/{reporter-GLWYHI2Y.js → reporter-VQU7HYKM.js} +77 -77
  66. package/{run-OU7NUB7A.js → run-UD32OTUJ.js} +17 -17
  67. package/{run-exec-QPBY7ULE.js → run-exec-NOCIUNGL.js} +17 -17
  68. package/security-archive-src-update-expired.js +1 -1
  69. package/{setup-23QXG473.js → setup-PBCWOSTV.js} +18 -18
  70. package/{src-575IYJOL.js → src-LRKPUV4J.js} +16 -16
  71. package/src-T5FBZFMV.js +222 -0
  72. package/{src-3GN7TDNH.js → src-Z44JKVWS.js} +9 -7
  73. package/{token-FCIA3RGD.js → token-PCPB6NOL.js} +10 -10
  74. package/{uninstall-BQVZVKB5.js → uninstall-LOGSQXFS.js} +14 -14
  75. package/{unpublish-YGJ5HEYF.js → unpublish-O3UFCTEJ.js} +10 -10
  76. package/{update-WCGV66JK.js → update-WBCLWGLN.js} +17 -17
  77. package/{version-7EA3UQG7.js → version-S3LCB2TQ.js} +13 -13
  78. package/{view-5FWIENVE.js → view-LMPENVAJ.js} +12 -12
  79. package/vlr.js +1 -1
  80. package/vlrx.js +1 -1
  81. package/vlt.js +1 -1
  82. package/vlx.js +1 -1
  83. package/vlxl.js +1 -1
  84. package/{whoami-O4ZTBIC4.js → whoami-LYMG7R3P.js} +10 -10
  85. package/chunk-WD74RJXW.js +0 -75
@@ -20,6 +20,1776 @@ function create(cls, defaultFrom, message, cause, from = defaultFrom) {
20
20
  function error(message, cause, from) {
21
21
  return create(Error, error, message, cause, from);
22
22
  }
23
+ function typeError(message, cause, from) {
24
+ return create(TypeError, typeError, message, cause, from);
25
+ }
26
+ function syntaxError(message, cause, from) {
27
+ return create(
28
+ SyntaxError,
29
+ syntaxError,
30
+ message,
31
+ cause,
32
+ from
33
+ );
34
+ }
35
+
36
+ // ../../src/fast-split/src/index.ts
37
+ function fastSplit(str, delim, limit = -1, onPart) {
38
+ let i = 0;
39
+ let p = 0;
40
+ const l = delim.length;
41
+ const parts = [];
42
+ while (i !== -1) {
43
+ i = str.indexOf(delim, p);
44
+ const part = i === -1 || parts.length === limit - 1 ? str.substring(p) : str.substring(p, i);
45
+ parts.push(onPart?.(part, parts, i) ?? part);
46
+ if (parts.length === limit) {
47
+ return parts;
48
+ }
49
+ p = i + l;
50
+ }
51
+ return parts;
52
+ }
53
+
54
+ // ../../src/semver/src/version.ts
55
+ var maybeNumber = (s) => {
56
+ if (!/^[0-9]+$/.test(s)) return s;
57
+ const n7 = Number(s);
58
+ return n7 <= Number.MAX_SAFE_INTEGER ? n7 : s;
59
+ };
60
+ var safeNumber = (s, version, field) => {
61
+ const n7 = Number(s);
62
+ if (n7 > Number.MAX_SAFE_INTEGER) {
63
+ throw invalidVersion(
64
+ version,
65
+ `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`
66
+ );
67
+ }
68
+ return n7;
69
+ };
70
+ var re = {
71
+ prefix: /^[ v=]+/,
72
+ main: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/,
73
+ prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\+)/,
74
+ build: /\+([0-9a-zA-Z_.-]+)$/,
75
+ full: /^[ v=]*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\+([0-9a-zA-Z_.-]+))?$/
76
+ };
77
+ var invalidVersion = (version, message) => {
78
+ const er = syntaxError(
79
+ `invalid version: ${message}`,
80
+ { version },
81
+ Version
82
+ );
83
+ return er;
84
+ };
85
+ var Version = class _Version {
86
+ /** raw string provided to create this Version */
87
+ raw;
88
+ /** major version number */
89
+ major;
90
+ /** minor version number */
91
+ minor;
92
+ /** patch version number */
93
+ patch;
94
+ /**
95
+ * List of `'.'`-separated strings and numbers indicating that this
96
+ * version is a prerelease.
97
+ *
98
+ * This is undefined if the version does not have a prerelease section.
99
+ */
100
+ prerelease;
101
+ /**
102
+ * List of `'.'`-separated strings in the `build` section.
103
+ *
104
+ * This is undefined if the version does not have a build.
105
+ */
106
+ build;
107
+ /** Canonical strict form of this version */
108
+ toString() {
109
+ return `${this.major}.${this.minor}.${this.patch}${this.prerelease ? "-" + this.prerelease.join(".") : ""}${this.build ? "+" + this.build.join(".") : ""}`;
110
+ }
111
+ /** Generate a `Version` object from a SemVer string */
112
+ static parse(version) {
113
+ version = version.replace(re.prefix, "").trim();
114
+ if (version.length > 256) {
115
+ throw invalidVersion(
116
+ version,
117
+ "must be less than 256 characters"
118
+ );
119
+ }
120
+ const parsed = re.full.exec(version);
121
+ if (!parsed) {
122
+ const main2 = re.main.exec(version);
123
+ if (!main2) {
124
+ throw invalidVersion(
125
+ version,
126
+ "no Major.minor.patch tuple present"
127
+ );
128
+ } else {
129
+ throw invalidVersion(
130
+ version,
131
+ "invalid build or patch section"
132
+ );
133
+ }
134
+ }
135
+ const [_2, major_, minor_, patch_, prerelease, build] = parsed;
136
+ const major2 = safeNumber(major_, version, "major");
137
+ const minor2 = safeNumber(minor_, version, "minor");
138
+ const patch = safeNumber(patch_, version, "patch");
139
+ return new _Version(
140
+ version,
141
+ major2,
142
+ minor2,
143
+ patch,
144
+ prerelease,
145
+ build
146
+ );
147
+ }
148
+ constructor(version, major2, minor2, patch, prerelease, build) {
149
+ this.raw = version;
150
+ this.major = major2;
151
+ this.minor = minor2;
152
+ this.patch = patch;
153
+ if (prerelease) {
154
+ this.prerelease = fastSplit(prerelease, ".", -1, (c) => {
155
+ if (!c) {
156
+ throw invalidVersion(
157
+ version,
158
+ "invalid prerelease, empty identifiers not allowed"
159
+ );
160
+ }
161
+ return maybeNumber(c);
162
+ });
163
+ }
164
+ if (build) {
165
+ this.build = fastSplit(build, ".", -1, (c) => {
166
+ if (!c) {
167
+ throw invalidVersion(
168
+ version,
169
+ "invalid build metadata, empty identifiers not allowed"
170
+ );
171
+ }
172
+ });
173
+ }
174
+ }
175
+ /**
176
+ * Return 1 if this is > the provided version, -1 if we're less, or 0 if
177
+ * they are equal.
178
+ *
179
+ * No special handling for prerelease versions, this is just a precedence
180
+ * comparison.
181
+ *
182
+ * This can be used to sort a list of versions by precedence:
183
+ *
184
+ * ```ts
185
+ * const versions: Version[] = getVersionsSomehow()
186
+ * const sorted = versions.sort((a, b) => a.compare(b))
187
+ * ```
188
+ */
189
+ compare(v2) {
190
+ if (this.major > v2.major) return 1;
191
+ if (this.major < v2.major) return -1;
192
+ if (this.minor > v2.minor) return 1;
193
+ if (this.minor < v2.minor) return -1;
194
+ if (this.patch > v2.patch) return 1;
195
+ if (this.patch < v2.patch) return -1;
196
+ if (!v2.prerelease?.length)
197
+ return !this.prerelease?.length ? 0 : -1;
198
+ if (!this.prerelease?.length) return 1;
199
+ const len = Math.max(this.prerelease.length, v2.prerelease.length);
200
+ const me2 = this.prerelease;
201
+ const thee = v2.prerelease;
202
+ for (let i = 0; i < len; i++) {
203
+ const m = me2[i];
204
+ const t = thee[i];
205
+ if (m === t) continue;
206
+ if (t === void 0) return 1;
207
+ if (m === void 0) return -1;
208
+ if (typeof m !== typeof t) {
209
+ return typeof m === "string" ? 1 : -1;
210
+ }
211
+ return m > t ? 1 : -1;
212
+ }
213
+ return 0;
214
+ }
215
+ /**
216
+ * The inverse of compare, for sorting version lists in reverse order
217
+ */
218
+ rcompare(v2) {
219
+ return -1 * this.compare(v2);
220
+ }
221
+ /** true if this version is > the argument */
222
+ greaterThan(v2) {
223
+ return this.compare(v2) === 1;
224
+ }
225
+ /** true if this version is >= the argument */
226
+ greaterThanEqual(v2) {
227
+ return this.compare(v2) > -1;
228
+ }
229
+ /** true if this version is < the argument */
230
+ lessThan(v2) {
231
+ return this.compare(v2) === -1;
232
+ }
233
+ /** true if this version is &lt;= the argument */
234
+ lessThanEqual(v2) {
235
+ return this.compare(v2) < 1;
236
+ }
237
+ /** true if these two versions have equal SemVer precedence */
238
+ equals(v2) {
239
+ return this.compare(v2) === 0;
240
+ }
241
+ /** just compare the M.m.p parts of the version */
242
+ tupleEquals(v2) {
243
+ return this.major === v2.major && this.minor === v2.minor && this.patch === v2.patch;
244
+ }
245
+ /** true if this version satisfies the range */
246
+ satisfies(r) {
247
+ return r.test(this);
248
+ }
249
+ /**
250
+ * Increment the version in place, in the manner specified.
251
+ *
252
+ * Part behaviors:
253
+ *
254
+ * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
255
+ * simply drop the prerelease. Otherwise, set the minor and patch to 0, and
256
+ * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
257
+ * `2.0.0`
258
+ *
259
+ * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
260
+ * simply drop the prerelease. Otherwise, set the patch to 0, and increment the
261
+ * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
262
+ *
263
+ * - `'patch'` If the version has a prerelease, then simply drop the
264
+ * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
265
+ * `1.2.3` and `1.2.3` becomes `1.2.4`.
266
+ *
267
+ * - `'premajor'` Set the patch and minor versions to `0`, increment the major
268
+ * version, and add a prerelease, using the optional identifier.
269
+ *
270
+ * - `'preminor'` Set the patch version to `0`, increment the minor version,
271
+ * and add a prerelease, using the optional identifier.
272
+ *
273
+ * - `'prepatch'` If a prerelease is already present, increment the patch
274
+ * version, otherwise leave it untouched, and add a prerelease, using the
275
+ * optional identifier.
276
+ *
277
+ * - `'prerelease'` If a prerelease version is present, then behave the same as
278
+ * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
279
+ *
280
+ * - `'pre'` This is mostly for use by the other prerelease incrementers.
281
+ *
282
+ * - If a prerelease identifier is provided:
283
+ *
284
+ * Update that named portion of the prerelease. For example,
285
+ * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
286
+ *
287
+ * If there is no prerelease identifier by that name, then replace the
288
+ * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
289
+ * would result in `1.2.3-beta`.
290
+ *
291
+ * If the prerelease identifer is present, but has no numeric value
292
+ * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
293
+ * would result in `1.2.3-beta.0`.
294
+ *
295
+ * - If no prerelease identifier is provided:
296
+ *
297
+ * If there is no current prerelease, then set the prerelease to `0`. So,
298
+ * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
299
+ *
300
+ * If the last item in the prerelease is numeric, then increment it. So,
301
+ * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
302
+ */
303
+ inc(part, prereleaseIdentifier) {
304
+ switch (part) {
305
+ case "premajor":
306
+ this.prerelease = void 0;
307
+ this.patch = 0;
308
+ this.minor = 0;
309
+ this.major++;
310
+ this.inc("pre", prereleaseIdentifier);
311
+ break;
312
+ case "preminor":
313
+ this.prerelease = void 0;
314
+ this.patch = 0;
315
+ this.minor++;
316
+ this.inc("pre", prereleaseIdentifier);
317
+ break;
318
+ case "prepatch":
319
+ this.prerelease = void 0;
320
+ this.inc("patch");
321
+ this.inc("pre", prereleaseIdentifier);
322
+ break;
323
+ case "prerelease":
324
+ if (!this.prerelease?.length)
325
+ this.inc("patch", prereleaseIdentifier);
326
+ this.inc("pre", prereleaseIdentifier);
327
+ break;
328
+ case "pre": {
329
+ if (!prereleaseIdentifier) {
330
+ if (!this.prerelease?.length) {
331
+ this.prerelease = [0];
332
+ break;
333
+ }
334
+ const last = this.prerelease[this.prerelease.length - 1];
335
+ if (typeof last === "number") {
336
+ this.prerelease[this.prerelease.length - 1] = last + 1;
337
+ } else {
338
+ this.prerelease.push(0);
339
+ }
340
+ break;
341
+ }
342
+ if (!this.prerelease?.length) {
343
+ this.prerelease = [prereleaseIdentifier];
344
+ break;
345
+ }
346
+ const i = this.prerelease.indexOf(
347
+ maybeNumber(prereleaseIdentifier)
348
+ );
349
+ if (i === -1) {
350
+ this.prerelease = [prereleaseIdentifier];
351
+ break;
352
+ }
353
+ const baseValue = this.prerelease[i + 1];
354
+ if (typeof baseValue === "number") {
355
+ this.prerelease[i + 1] = baseValue + 1;
356
+ break;
357
+ }
358
+ if (i === this.prerelease.length - 1) {
359
+ this.prerelease.push(0);
360
+ break;
361
+ }
362
+ this.prerelease.splice(i + 1, 0, 0);
363
+ break;
364
+ }
365
+ case "major":
366
+ if (!this.prerelease?.length || this.minor || this.patch)
367
+ this.major++;
368
+ this.prerelease = void 0;
369
+ this.patch = 0;
370
+ this.minor = 0;
371
+ break;
372
+ case "minor":
373
+ if (!this.prerelease?.length || this.patch) this.minor++;
374
+ this.prerelease = void 0;
375
+ this.patch = 0;
376
+ break;
377
+ case "patch":
378
+ if (!this.prerelease?.length) this.patch++;
379
+ this.prerelease = void 0;
380
+ break;
381
+ default:
382
+ throw typeError(
383
+ "Invalid increment identifier",
384
+ {
385
+ version: this,
386
+ found: part,
387
+ validOptions: [
388
+ "major",
389
+ "minor",
390
+ "patch",
391
+ "premajor",
392
+ "preminor",
393
+ "prepatch",
394
+ "prerelease",
395
+ "pre"
396
+ ]
397
+ },
398
+ this.inc
399
+ );
400
+ }
401
+ this.raw = this.toString();
402
+ return this;
403
+ }
404
+ };
405
+
406
+ // ../../src/semver/src/comparator.ts
407
+ var isOperator = (o) => !!o && (o === ">" || o === "<" || o === ">=" || o === "<=" || o === "" || o === "~" || o === "^" || o === "~>");
408
+ var preJunk = new Set("=v ");
409
+ var invalidComp = (c, message) => syntaxError(
410
+ `invalid comparator: '${c}' ${message}`,
411
+ { found: c },
412
+ Comparator
413
+ );
414
+ var assertNumber = (value, c, field) => {
415
+ const n7 = Number(value);
416
+ if (n7 !== n7) {
417
+ throw invalidComp(
418
+ c,
419
+ `${field} must be numeric or 'x', got: '${value}'`
420
+ );
421
+ }
422
+ return n7;
423
+ };
424
+ var assertVersion = (v2, comp) => {
425
+ if (!v2) {
426
+ throw invalidComp(comp, "no value provided for operator");
427
+ }
428
+ };
429
+ var assertMissing = (value, c, field) => {
430
+ if (value && !isX(value)) {
431
+ throw invalidComp(
432
+ c,
433
+ `cannot omit '${field}' and include subsequent fields`
434
+ );
435
+ }
436
+ };
437
+ var MAJOR = 0;
438
+ var MINOR = 1;
439
+ var PATCH = 2;
440
+ var isX = (c) => !c || c === "X" || c === "x" || c === "*";
441
+ var isFullVersion = (parsed) => void 0 !== parsed[PATCH];
442
+ var isXPatch = (parsed) => void 0 !== parsed[MINOR] && void 0 === parsed[PATCH];
443
+ var isXMinor = (parsed) => void 0 !== parsed[MAJOR] && void 0 === parsed[MINOR];
444
+ var isXMajor = (parsed) => void 0 === parsed[MAJOR];
445
+ var Comparator = class {
446
+ /**
447
+ * does this range include prereleases, even when they do not
448
+ * match the tuple in the comparator?
449
+ */
450
+ includePrerelease;
451
+ /** raw string used to create this comparator */
452
+ raw;
453
+ /** tokens extracted from the raw string input */
454
+ tokens;
455
+ /**
456
+ * Either the `any` comparator, the `none` comparator, or an operator
457
+ * and a {@link ParsedXRange}
458
+ */
459
+ tuples = [];
460
+ /** true if this comparator can not match anything */
461
+ isNone = false;
462
+ /**
463
+ * true if this comparator is a `'*'` type of range.
464
+ *
465
+ * Note that it still will not match versions with a prerelease value,
466
+ * unless the tuple in the version matches the tuple provided to the
467
+ * comparator, and the comparator version also has a prerelease value,
468
+ * unless `includePrerelease` is set.
469
+ */
470
+ isAny = false;
471
+ /** the canonical strict simplified parsed form of this constructor */
472
+ toString() {
473
+ return this.isNone ? "<0.0.0-0" : this.isAny ? "*" : (
474
+ /* c8 ignore next */
475
+ this.tuples.map((c) => isAny(c) ? "*" : c.join("")).join(" ")
476
+ );
477
+ }
478
+ constructor(comp, includePrerelease = false) {
479
+ this.includePrerelease = includePrerelease;
480
+ comp = comp.trim();
481
+ this.raw = comp;
482
+ let hyphen = false;
483
+ const rawComps = fastSplit(comp, " ", -1, (part, parts, i) => {
484
+ if (part === "-") {
485
+ if (hyphen) {
486
+ throw invalidComp(
487
+ comp,
488
+ "multiple hyphen ranges not allowed"
489
+ );
490
+ }
491
+ if (parts.length !== 1 || i === -1) {
492
+ throw invalidComp(
493
+ comp,
494
+ "hyphen must be between two versions"
495
+ );
496
+ }
497
+ hyphen = true;
498
+ } else if (hyphen && parts.length !== 2) {
499
+ throw invalidComp(comp, "hyphen range must be alone");
500
+ }
501
+ });
502
+ const comps = [];
503
+ let followingOperator = false;
504
+ let l = 0;
505
+ for (const c of rawComps) {
506
+ if (c === "") continue;
507
+ if (!followingOperator) {
508
+ followingOperator = isOperator(c);
509
+ comps.push(c);
510
+ l++;
511
+ continue;
512
+ }
513
+ comps[l - 1] += c;
514
+ followingOperator = false;
515
+ }
516
+ if (hyphen) {
517
+ const [min, _2, max] = comps;
518
+ if (!min || !max) {
519
+ throw invalidComp(comp, "hyphen must be between two versions");
520
+ }
521
+ this.#parseHyphenRange(min, max);
522
+ } else if (!comps.length || comps.length === 1 && isX(comps[0])) {
523
+ this.tuples.push(this.#getComparatorAny());
524
+ } else {
525
+ for (const c of comps) {
526
+ this.#parse(c);
527
+ if (this.isNone) break;
528
+ }
529
+ }
530
+ this.tokens = comps;
531
+ this.isAny = true;
532
+ for (const c of this.tuples) {
533
+ if (Array.isArray(c) || !c.isAny) {
534
+ this.isAny = false;
535
+ break;
536
+ }
537
+ }
538
+ }
539
+ // inclusive min
540
+ #xInclusiveMin(raw) {
541
+ const z = this.includePrerelease ? "0" : void 0;
542
+ const [M3, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
543
+ return M3 === void 0 ? this.#getComparatorAny() : [">=", new Version(raw, M3, m, p, pr, build)];
544
+ }
545
+ // exclusive min
546
+ #xExclusiveMin(raw) {
547
+ const parsed = this.#parseX(raw);
548
+ if (isFullVersion(parsed)) {
549
+ return [">", new Version(raw, ...parsed)];
550
+ }
551
+ const z = this.includePrerelease ? "0" : void 0;
552
+ if (isXPatch(parsed)) {
553
+ return [
554
+ ">=",
555
+ new Version(
556
+ raw,
557
+ parsed[MAJOR],
558
+ parsed[MINOR] + 1,
559
+ 0,
560
+ z,
561
+ void 0
562
+ )
563
+ ];
564
+ }
565
+ if (isXMinor(parsed)) {
566
+ return [
567
+ ">=",
568
+ new Version(raw, parsed[MAJOR] + 1, 0, 0, z, void 0)
569
+ ];
570
+ }
571
+ this.isNone = true;
572
+ this.tuples.length = 0;
573
+ return comparatorNone;
574
+ }
575
+ #xInclusiveMax(raw) {
576
+ const parsed = this.#parseX(raw);
577
+ return isFullVersion(parsed) ? ["<=", new Version(raw, ...parsed)] : isXPatch(parsed) ? [
578
+ "<",
579
+ new Version(
580
+ raw,
581
+ parsed[MAJOR],
582
+ parsed[MINOR] + 1,
583
+ 0,
584
+ "0",
585
+ void 0
586
+ )
587
+ ] : isXMinor(parsed) ? [
588
+ "<",
589
+ new Version(raw, parsed[MAJOR] + 1, 0, 0, "0", void 0)
590
+ ] : this.#getComparatorAny();
591
+ }
592
+ #xExclusiveMax(raw) {
593
+ const z = this.includePrerelease ? "0" : void 0;
594
+ const [M3 = 0, m = 0, p = 0, pr = z, build] = this.#parseX(raw);
595
+ if (M3 === 0 && m === 0 && p === 0 && pr === "0") {
596
+ this.isNone = true;
597
+ this.tuples.length = 0;
598
+ return comparatorNone;
599
+ }
600
+ return ["<", new Version(raw, M3, m, p, pr, build)];
601
+ }
602
+ #validXM(raw, m, p) {
603
+ assertMissing(m, raw, "major");
604
+ assertMissing(p, raw, "major");
605
+ if (m === "" || p === "") {
606
+ throw invalidComp(raw, `(Did you mean '*'?)`);
607
+ }
608
+ return [];
609
+ }
610
+ #validXm(raw, M3, m, p) {
611
+ assertMissing(p, raw, "major");
612
+ if (m === "" || p === "") {
613
+ throw invalidComp(raw, `(Did you mean '${M3}'?)`);
614
+ }
615
+ return [assertNumber(M3, raw, "major")];
616
+ }
617
+ #validXp(raw, M3, m, p) {
618
+ if (p === "") {
619
+ throw invalidComp(raw, `(Did you mean '${M3}.${m}'?)`);
620
+ }
621
+ return [
622
+ assertNumber(M3, raw, "major"),
623
+ assertNumber(m, raw, "minor")
624
+ ];
625
+ }
626
+ #validTuple(raw, M3, m, p) {
627
+ return [
628
+ assertNumber(M3, raw, "major"),
629
+ assertNumber(m, raw, "minor"),
630
+ assertNumber(p, raw, "patch")
631
+ ];
632
+ }
633
+ #validXbuild(raw, M3, m, p, pl) {
634
+ const patch = p.substring(0, pl);
635
+ const build = p.substring(pl + 1);
636
+ if (!patch) {
637
+ throw invalidComp(raw, "cannot specify build without patch");
638
+ }
639
+ if (!build) {
640
+ throw invalidComp(raw, `encountered '+', but no build value`);
641
+ }
642
+ return [
643
+ assertNumber(M3, raw, "major"),
644
+ assertNumber(m, raw, "minor"),
645
+ assertNumber(patch, raw, "patch"),
646
+ void 0,
647
+ build
648
+ ];
649
+ }
650
+ #validXpr(raw, M3, m, p, hy) {
651
+ {
652
+ const patch = p.substring(0, hy);
653
+ const pr = p.substring(hy + 1);
654
+ if (!patch) {
655
+ throw invalidComp(
656
+ raw,
657
+ "cannot specify prerelease without patch"
658
+ );
659
+ }
660
+ if (!pr) {
661
+ throw invalidComp(
662
+ raw,
663
+ `encountered '-', but no prerelease value`
664
+ );
665
+ }
666
+ return [
667
+ assertNumber(M3, raw, "major"),
668
+ assertNumber(m, raw, "minor"),
669
+ assertNumber(patch, raw, "patch"),
670
+ pr,
671
+ void 0
672
+ ];
673
+ }
674
+ }
675
+ #validXprbuild(raw, M3, m, p, hy, pl) {
676
+ const patch = p.substring(0, hy);
677
+ const pr = p.substring(hy + 1, pl);
678
+ const build = p.substring(pl + 1);
679
+ if (!patch) {
680
+ throw invalidComp(
681
+ raw,
682
+ "cannot specify prerelease without patch"
683
+ );
684
+ }
685
+ if (!pr) {
686
+ throw invalidComp(
687
+ raw,
688
+ `encountered '-', but no prerelease value`
689
+ );
690
+ }
691
+ if (!build) {
692
+ throw invalidComp(raw, `encountered '+', but no build value`);
693
+ }
694
+ return [
695
+ assertNumber(M3, raw, "major"),
696
+ assertNumber(m, raw, "minor"),
697
+ assertNumber(patch, raw, "patch"),
698
+ pr,
699
+ build
700
+ ];
701
+ }
702
+ // pull the relevant values out of an X-range or version
703
+ // return the fields for creating a Version object.
704
+ // only call once operator is stripped off
705
+ #parseX(raw) {
706
+ let [M3, m, p] = fastSplit(raw, ".", 3);
707
+ let prune = 0;
708
+ while (M3 && preJunk.has(M3.charAt(prune))) prune++;
709
+ if (M3 !== void 0 && prune !== 0) M3 = M3.substring(prune);
710
+ if (!M3 || isX(M3)) return this.#validXM(raw, m, p);
711
+ if (!m || isX(m)) return this.#validXm(raw, M3, m, p);
712
+ if (!p || isX(p)) return this.#validXp(raw, M3, m, p);
713
+ const hy = p.indexOf("-");
714
+ const pl = p.indexOf("+");
715
+ if (pl === -1 && hy === -1) return this.#validTuple(raw, M3, m, p);
716
+ if (pl === -1) return this.#validXpr(raw, M3, m, p, hy);
717
+ if (hy === -1) return this.#validXbuild(raw, M3, m, p, pl);
718
+ return this.#validXprbuild(raw, M3, m, p, hy, pl);
719
+ }
720
+ #parseHyphenRange(min, max) {
721
+ const minv = this.#xInclusiveMin(min);
722
+ const maxv = this.#xInclusiveMax(max);
723
+ const minAny = isAny(minv);
724
+ const maxAny = isAny(maxv);
725
+ if (minAny && maxAny) this.tuples.push(this.#getComparatorAny());
726
+ else if (minAny) this.tuples.push(maxv);
727
+ else if (maxAny) this.tuples.push(minv);
728
+ else this.tuples.push(minv, maxv);
729
+ }
730
+ #parse(comp) {
731
+ const first = comp.charAt(0);
732
+ const first2 = comp.substring(0, 2);
733
+ const v1 = comp.substring(1);
734
+ const v2 = comp.substring(2);
735
+ switch (first2) {
736
+ case "~>":
737
+ assertVersion(v2, comp);
738
+ return this.#parseTilde(v2);
739
+ case ">=":
740
+ assertVersion(v2, comp);
741
+ return this.tuples.push(this.#xInclusiveMin(v2));
742
+ case "<=":
743
+ assertVersion(v2, comp);
744
+ return this.tuples.push(this.#xInclusiveMax(v2));
745
+ }
746
+ switch (first) {
747
+ case "~":
748
+ assertVersion(v1, comp);
749
+ return this.#parseTilde(v1);
750
+ case "^":
751
+ assertVersion(v1, comp);
752
+ return this.#parseCaret(v1);
753
+ case ">":
754
+ assertVersion(v1, comp);
755
+ return this.tuples.push(this.#xExclusiveMin(v1));
756
+ case "<":
757
+ assertVersion(v1, comp);
758
+ return this.tuples.push(this.#xExclusiveMax(v1));
759
+ }
760
+ return this.#parseEq(comp);
761
+ }
762
+ #parseTilde(comp) {
763
+ const parsed = this.#parseX(comp);
764
+ if (isXMajor(parsed)) {
765
+ this.tuples.push(this.#getComparatorAny());
766
+ return;
767
+ }
768
+ const z = this.includePrerelease ? "0" : void 0;
769
+ if (isXMinor(parsed)) {
770
+ const [M4] = parsed;
771
+ this.tuples.push(
772
+ [">=", new Version(comp, M4, 0, 0, z, void 0)],
773
+ ["<", new Version(comp, M4 + 1, 0, 0, "0", void 0)]
774
+ );
775
+ return;
776
+ }
777
+ if (isXPatch(parsed)) {
778
+ const [M4, m2] = parsed;
779
+ const z2 = this.includePrerelease ? "0" : void 0;
780
+ this.tuples.push(
781
+ [">=", new Version(comp, M4, m2, 0, z2, void 0)],
782
+ ["<", new Version(comp, M4, m2 + 1, 0, "0", void 0)]
783
+ );
784
+ return;
785
+ }
786
+ const [M3, m, p, pr = z, build] = parsed;
787
+ this.tuples.push(
788
+ [">=", new Version(comp, M3, m, p, pr, build)],
789
+ ["<", new Version(comp, M3, m + 1, 0, "0", build)]
790
+ );
791
+ }
792
+ #parseCaret(comp) {
793
+ const min = this.#xInclusiveMin(comp);
794
+ if (isAny(min)) {
795
+ this.tuples.push(min);
796
+ return;
797
+ }
798
+ const minv = min[1];
799
+ if (minv.major !== 0) {
800
+ this.tuples.push(min, [
801
+ "<",
802
+ new Version(comp, minv.major + 1, 0, 0, "0", void 0)
803
+ ]);
804
+ } else if (minv.minor !== 0) {
805
+ this.tuples.push(min, [
806
+ "<",
807
+ new Version(
808
+ comp,
809
+ minv.major,
810
+ minv.minor + 1,
811
+ 0,
812
+ "0",
813
+ void 0
814
+ )
815
+ ]);
816
+ } else if (!minv.prerelease?.length) {
817
+ this.tuples.push(["", minv]);
818
+ } else {
819
+ this.tuples.push(min, [
820
+ "<",
821
+ new Version(
822
+ comp,
823
+ minv.major,
824
+ minv.minor,
825
+ minv.patch + 1,
826
+ "0",
827
+ void 0
828
+ )
829
+ ]);
830
+ }
831
+ }
832
+ #parseEq(comp) {
833
+ const parsed = this.#parseX(comp);
834
+ const z = this.includePrerelease ? "0" : void 0;
835
+ if (isFullVersion(parsed)) {
836
+ this.tuples.push(["", new Version(comp, ...parsed)]);
837
+ } else if (isXMajor(parsed)) {
838
+ this.tuples.push(this.#getComparatorAny());
839
+ } else if (isXMinor(parsed)) {
840
+ this.tuples.push([
841
+ ">=",
842
+ new Version(comp, parsed[MAJOR], 0, 0, z, void 0)
843
+ ]);
844
+ this.tuples.push([
845
+ "<",
846
+ new Version(comp, parsed[MAJOR] + 1, 0, 0, "0", void 0)
847
+ ]);
848
+ } else if (isXPatch(parsed)) {
849
+ this.tuples.push(
850
+ [
851
+ ">=",
852
+ new Version(
853
+ comp,
854
+ parsed[MAJOR],
855
+ parsed[MINOR],
856
+ 0,
857
+ z,
858
+ void 0
859
+ )
860
+ ],
861
+ [
862
+ "<",
863
+ new Version(
864
+ comp,
865
+ parsed[MAJOR],
866
+ parsed[MINOR] + 1,
867
+ 0,
868
+ "0",
869
+ void 0
870
+ )
871
+ ]
872
+ );
873
+ }
874
+ }
875
+ /** return true if the version is a match for this comparator */
876
+ test(v2) {
877
+ if (this.isNone) return false;
878
+ const ip = this.includePrerelease;
879
+ const hasPR = !!v2.prerelease?.length;
880
+ let prOK = ip || !hasPR;
881
+ for (const c of this.tuples) {
882
+ if (isAny(c)) {
883
+ continue;
884
+ }
885
+ const [op, cv] = c;
886
+ prOK ||= !!cv.prerelease?.length && v2.tupleEquals(cv);
887
+ switch (op) {
888
+ case "":
889
+ if (!v2.equals(cv)) return false;
890
+ continue;
891
+ case ">":
892
+ if (!v2.greaterThan(cv)) return false;
893
+ continue;
894
+ case ">=":
895
+ if (!v2.greaterThanEqual(cv)) return false;
896
+ continue;
897
+ case "<":
898
+ if (!v2.lessThan(cv)) return false;
899
+ continue;
900
+ case "<=":
901
+ if (!v2.lessThanEqual(cv)) return false;
902
+ continue;
903
+ }
904
+ }
905
+ return prOK;
906
+ }
907
+ #getComparatorAny() {
908
+ return this.includePrerelease ? comparatorAnyPR : comparatorAny;
909
+ }
910
+ };
911
+ var isAny = (c) => c === comparatorAny || c === comparatorAnyPR;
912
+ var comparatorAny = {
913
+ isAny: true,
914
+ toString: () => "*",
915
+ includePrerelease: false,
916
+ test: (v2) => !v2.prerelease?.length
917
+ };
918
+ var comparatorAnyPR = {
919
+ isAny: true,
920
+ toString: () => "*",
921
+ includePrerelease: true,
922
+ test: (_2) => true
923
+ };
924
+ var comparatorNone = {
925
+ isNone: true,
926
+ toString: () => "<0.0.0-0",
927
+ includePrerelease: false,
928
+ test: (_2) => false
929
+ };
930
+
931
+ // ../../src/semver/src/range.ts
932
+ var Range = class {
933
+ /** raw string used to create this Range */
934
+ raw;
935
+ /** true if the range is `*` */
936
+ isAny;
937
+ /** true if the range is a single semver version */
938
+ isSingle;
939
+ /** true if the range cannot match anything */
940
+ /**
941
+ * set of {@link Comparator} objects representing the `||`-separated sections
942
+ * of the range. If at least one of these matches, then the version is a
943
+ * match.
944
+ */
945
+ set = [];
946
+ /** true if all prerelease versions should be included */
947
+ includePrerelease;
948
+ /** cached toString */
949
+ #toString;
950
+ constructor(range, includePrerelease = false) {
951
+ this.raw = range;
952
+ this.includePrerelease = includePrerelease;
953
+ this.isAny = false;
954
+ let isFirst = true;
955
+ this.isSingle = false;
956
+ const comparatorErrors = [];
957
+ fastSplit(range, "||", -1, (part) => {
958
+ if (this.isAny) return;
959
+ const cmp = this.#maybeComparator(part, this.includePrerelease);
960
+ if (cmp instanceof Error) {
961
+ comparatorErrors.push(cmp);
962
+ return;
963
+ }
964
+ if (cmp.isAny) {
965
+ this.set = [cmp];
966
+ this.isAny = true;
967
+ return;
968
+ }
969
+ this.set.push(cmp);
970
+ if (!isFirst) this.isSingle = false;
971
+ else if (Array.isArray(cmp.tuples) && cmp.tuples.length === 1 && Array.isArray(cmp.tuples[0]) && cmp.tuples[0][0] === "") {
972
+ this.isSingle = true;
973
+ }
974
+ isFirst = false;
975
+ });
976
+ if (!this.set.length && comparatorErrors.length) {
977
+ if (comparatorErrors.length === 1 && comparatorErrors[0]) {
978
+ throw comparatorErrors[0];
979
+ }
980
+ throw new AggregateError(comparatorErrors);
981
+ }
982
+ }
983
+ #maybeComparator(part, includePrerelease) {
984
+ try {
985
+ return new Comparator(part, includePrerelease);
986
+ } catch (er) {
987
+ return asError(er);
988
+ }
989
+ }
990
+ /**
991
+ * test a {@link Version} against the range
992
+ */
993
+ test(v2) {
994
+ return this.set.some((c) => c.test(v2));
995
+ }
996
+ /** return the simplified canonical form of this range */
997
+ toString() {
998
+ if (this.#toString) return this.#toString;
999
+ if (this.isSingle) {
1000
+ this.#toString = String(this.set[0]);
1001
+ return this.#toString;
1002
+ }
1003
+ this.#toString = this.set.map((c) => String(c)).join(" || ");
1004
+ return this.#toString;
1005
+ }
1006
+ };
1007
+
1008
+ // ../../src/semver/src/index.ts
1009
+ var rangeCache = /* @__PURE__ */ new Map();
1010
+ var MAX_RANGE_CACHE = 4096;
1011
+ var parseRange = (range, includePrerelease = false) => {
1012
+ if (typeof range === "object") {
1013
+ if (range.includePrerelease === includePrerelease) return range;
1014
+ range = range.raw;
1015
+ }
1016
+ const key = `${+includePrerelease}\0${range}`;
1017
+ const cached = rangeCache.get(key);
1018
+ if (cached !== void 0 || rangeCache.has(key)) return cached;
1019
+ let parsed;
1020
+ try {
1021
+ parsed = new Range(range, includePrerelease);
1022
+ } catch {
1023
+ parsed = void 0;
1024
+ }
1025
+ if (rangeCache.size >= MAX_RANGE_CACHE) rangeCache.clear();
1026
+ rangeCache.set(key, parsed);
1027
+ return parsed;
1028
+ };
1029
+
1030
+ // ../../src/spec/src/valid-name.ts
1031
+ var pathSafeName = /^(?!(?:node_modules|\.vlt)$)(?![A-Za-z]:)(?:@(?!\.\.?\/)[^/\\\x00-\x1f\x7f]+\/)?(?!\.\.?$)[^/\\\x00-\x1f\x7f]+$/i;
1032
+ var isPathSafeName = (name2) => typeof name2 === "string" && pathSafeName.test(name2);
1033
+ var assertPathSafeName = (name2, from) => {
1034
+ if (isPathSafeName(name2)) return;
1035
+ throw error(
1036
+ "Invalid package name: not usable as a path segment",
1037
+ {
1038
+ code: "EINVALIDNAME",
1039
+ found: name2,
1040
+ from,
1041
+ wanted: "a single path segment, or a well-formed @scope/name"
1042
+ },
1043
+ assertPathSafeName
1044
+ );
1045
+ };
1046
+
1047
+ // ../../src/spec/src/browser.ts
1048
+ var kCustomInspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
1049
+ var defaultRegistryName = "npm";
1050
+ var defaultRegistries = {
1051
+ gh: "https://npm.pkg.github.com/"
1052
+ };
1053
+ var defaultJsrRegistries = { jsr: "https://npm.jsr.io/" };
1054
+ var defaultGitHosts = {
1055
+ github: "git+ssh://git@github.com:$1/$2.git",
1056
+ bitbucket: "git+ssh://git@bitbucket.org:$1/$2.git",
1057
+ gitlab: "git+ssh://git@gitlab.com:$1/$2.git",
1058
+ gist: "git+ssh://git@gist.github.com/$1.git"
1059
+ };
1060
+ var defaultGitHostArchives = {
1061
+ github: "https://api.github.com/repos/$1/$2/tarball/$committish",
1062
+ bitbucket: "https://bitbucket.org/$1/$2/get/$committish.tar.gz",
1063
+ gist: "https://codeload.github.com/gist/$1/tar.gz/$committish",
1064
+ gitlab: "https://gitlab.com/$1/$2/repository/archive.tar.gz?ref=$committish"
1065
+ };
1066
+ var gitHostWebsites = {
1067
+ github: "https://github.com/",
1068
+ bitbucket: "https://bitbucket.org/",
1069
+ gist: "https://gist.github.com/",
1070
+ gitlab: "https://gitlab.com/"
1071
+ };
1072
+ var getOptions = (options) => ({
1073
+ catalog: {},
1074
+ catalogs: {},
1075
+ ...options,
1076
+ // built-in aliases are user/service-overridable: user config wins
1077
+ "jsr-registries": {
1078
+ ...defaultJsrRegistries,
1079
+ ...options?.["jsr-registries"] ?? {}
1080
+ },
1081
+ registry: options?.registry,
1082
+ "default-registry-alias": options?.["default-registry-alias"] ?? defaultRegistryName,
1083
+ "scoped-registries": options?.["scoped-registries"] ?? {},
1084
+ "git-hosts": options?.["git-hosts"] ? {
1085
+ ...defaultGitHosts,
1086
+ ...options["git-hosts"]
1087
+ } : defaultGitHosts,
1088
+ registries: {
1089
+ ...defaultRegistries,
1090
+ ...options?.registries ?? {}
1091
+ },
1092
+ "git-host-archives": options?.["git-host-archives"] ? {
1093
+ ...defaultGitHostArchives,
1094
+ ...options["git-host-archives"]
1095
+ } : defaultGitHostArchives
1096
+ });
1097
+ var protocolRE = /^([a-zA-Z][a-zA-Z0-9+-]+):/;
1098
+ var builtinProtocols = /* @__PURE__ */ new Set([
1099
+ "catalog",
1100
+ "workspace",
1101
+ "registry",
1102
+ "file",
1103
+ "http",
1104
+ "https",
1105
+ "git",
1106
+ "git+ssh",
1107
+ "git+http",
1108
+ "git+https",
1109
+ "git+file"
1110
+ ]);
1111
+ var unknownProtocol = (str, options) => {
1112
+ const p = protocolRE.exec(str)?.[1];
1113
+ return p === void 0 || builtinProtocols.has(p) || p === options["default-registry-alias"] || options.registries[p] !== void 0 || options["git-hosts"][p] !== void 0 || options["jsr-registries"][p] !== void 0 ? void 0 : p;
1114
+ };
1115
+ 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
1116
+ // custom registered registry protocol e.g: `github:`, `custom:`
1117
+ [
1118
+ ...Object.keys(options["git-hosts"]),
1119
+ ...Object.keys(options.registries),
1120
+ ...Object.keys(options["jsr-registries"])
1121
+ ].some((key) => spec.startsWith(`${key}:`)) || unknownProtocol(spec, options) !== void 0;
1122
+ var findFirstAt = (spec, hasScope) => spec.indexOf("@", hasScope ? 1 : 0);
1123
+ var findGitIdentifier = (spec) => spec.indexOf("#") > 2;
1124
+ var findFileIdentifier = (spec) => spec.includes("/");
1125
+ var Spec = class _Spec {
1126
+ static parse(spec, bareOrOptions, options) {
1127
+ return typeof spec === "object" ? spec : new this(spec, bareOrOptions, options);
1128
+ }
1129
+ static parseArgs(specOrBareSpec, opts) {
1130
+ const options = getOptions(opts ?? {});
1131
+ if (startsWithSpecIdentifier(specOrBareSpec, options)) {
1132
+ const parsed = this.parse("(unknown)", specOrBareSpec, options);
1133
+ if (parsed.subspec) {
1134
+ const { namedJsrRegistry: jsrHost } = parsed;
1135
+ if (!jsrHost) {
1136
+ parsed.name = parsed.subspec.name;
1137
+ }
1138
+ parsed.spec = `${parsed.name}@${parsed.bareSpec}`;
1139
+ assertPathSafeName(parsed.name, parsed.spec);
1140
+ }
1141
+ return parsed;
1142
+ } else {
1143
+ const hasScope = specOrBareSpec.startsWith("@");
1144
+ const at2 = findFirstAt(specOrBareSpec, hasScope);
1145
+ if (at2 > -1) {
1146
+ return this.parse(
1147
+ specOrBareSpec.substring(0, at2),
1148
+ specOrBareSpec.substring(at2 + 1),
1149
+ options
1150
+ );
1151
+ } else if (findGitIdentifier(specOrBareSpec) || !hasScope && findFileIdentifier(specOrBareSpec)) {
1152
+ return this.parse("(unknown)", specOrBareSpec, options);
1153
+ } else {
1154
+ return this.parse(`${specOrBareSpec}@`, options);
1155
+ }
1156
+ }
1157
+ }
1158
+ static nodejsDependencies;
1159
+ type;
1160
+ spec;
1161
+ options;
1162
+ name;
1163
+ scope;
1164
+ scopeRegistry;
1165
+ bareSpec;
1166
+ gitRemote;
1167
+ gitSelector;
1168
+ gitSelectorParsed;
1169
+ gitCommittish;
1170
+ namedGitHost;
1171
+ namedGitHostPath;
1172
+ workspaceSpec;
1173
+ workspace;
1174
+ namedRegistry;
1175
+ namedJsrRegistry;
1176
+ registry;
1177
+ registrySpec;
1178
+ conventionalRegistryTarball;
1179
+ semver;
1180
+ range;
1181
+ distTag;
1182
+ remoteURL;
1183
+ file;
1184
+ catalog;
1185
+ subspec;
1186
+ overridden = false;
1187
+ #final;
1188
+ #toString;
1189
+ /**
1190
+ * Return the final entry in the chain of subspecs
1191
+ * When deciding which thing to actually fetch, spec.final is the thing
1192
+ * to look at.
1193
+ */
1194
+ get final() {
1195
+ if (this.#final) return this.#final;
1196
+ const final = this.subspec ? this.subspec.final : this;
1197
+ if (final.type === "catalog") {
1198
+ throw error('invalid Spec.final value, type is "catalog"');
1199
+ }
1200
+ return this.#final = final;
1201
+ }
1202
+ /**
1203
+ * Normally, the string value of a Spec is just the string passed in to
1204
+ * be parsed. However, in the case of a chain of subspecs, like
1205
+ * `foo@npm:bar@npm:baz@npm:quux@latest`, this simplifies out the middle
1206
+ * parts of the chain, returning just `foo@npm:quux@latest`
1207
+ */
1208
+ toString() {
1209
+ if (this.#toString !== void 0) return this.#toString;
1210
+ let sub = this;
1211
+ while (sub.subspec?.subspec) sub = sub.subspec;
1212
+ if (sub.subspec && sub.subspec.type !== "registry")
1213
+ sub = sub.subspec;
1214
+ return this.#toString = this.name + "@" + sub.bareSpec;
1215
+ }
1216
+ constructor(spec, bareOrOptions, options = {}) {
1217
+ if (bareOrOptions && typeof bareOrOptions === "object") {
1218
+ options = bareOrOptions;
1219
+ bareOrOptions = void 0;
1220
+ }
1221
+ this.options = getOptions(options);
1222
+ if (typeof bareOrOptions === "string") {
1223
+ this.name = spec;
1224
+ this.#parseScope(spec);
1225
+ this.bareSpec = bareOrOptions;
1226
+ this.spec = `${this.name}@${bareOrOptions}`;
1227
+ assertPathSafeName(this.name, this.spec);
1228
+ } else {
1229
+ this.spec = spec;
1230
+ this.#assertKnownProtocol(spec);
1231
+ if (!spec.startsWith("git@") && startsWithSpecIdentifier(spec, this.options) && spec.includes(":") && [
1232
+ ...Object.keys(this.options.registries),
1233
+ ...Object.keys(defaultRegistries)
1234
+ ].some((key) => spec.startsWith(`${key}:`))) {
1235
+ this.name = spec;
1236
+ this.bareSpec = spec;
1237
+ } else {
1238
+ const hasScope = spec.startsWith("@");
1239
+ let at2 = findFirstAt(spec, hasScope);
1240
+ if (at2 === -1) {
1241
+ at2 = spec.length;
1242
+ spec += "@";
1243
+ }
1244
+ this.name = spec.substring(0, at2);
1245
+ assertPathSafeName(this.name, spec);
1246
+ if (hasScope) this.#parseScope(this.name);
1247
+ this.bareSpec = spec.substring(at2 + 1);
1248
+ }
1249
+ }
1250
+ if (this.bareSpec.startsWith("catalog:")) {
1251
+ this.catalog = this.bareSpec.substring("catalog:".length);
1252
+ const catalog = this.catalog ? this.options.catalogs?.[this.catalog] : this.options.catalog;
1253
+ if (!catalog) {
1254
+ throw this.#error("Named catalog not found", {
1255
+ name: this.catalog,
1256
+ validOptions: this.options.catalogs && Object.keys(this.options.catalogs)
1257
+ });
1258
+ }
1259
+ const sub = catalog[this.name];
1260
+ if (!sub) {
1261
+ throw this.#error("Name not found in catalog", {
1262
+ name: this.name,
1263
+ validOptions: Object.keys(catalog)
1264
+ });
1265
+ }
1266
+ this.subspec = _Spec.parse(this.name, sub, this.options);
1267
+ this.type = "catalog";
1268
+ this.registry = this.subspec.final.registry;
1269
+ return;
1270
+ }
1271
+ if (this.bareSpec.startsWith("https://")) {
1272
+ for (const [name2, origin] of Object.entries(gitHostWebsites)) {
1273
+ if (this.bareSpec.startsWith(origin)) {
1274
+ const parsed = new URL(this.bareSpec);
1275
+ const [user, project] = parsed.pathname.replace(/\.git$/, "").replace(/\/+/g, " ").trim().split(" ");
1276
+ if (user && project) {
1277
+ this.bareSpec = `${name2}:${user}/${project}${parsed.hash}`;
1278
+ this.spec = `${this.name}@${this.bareSpec}`;
1279
+ break;
1280
+ }
1281
+ }
1282
+ }
1283
+ }
1284
+ if (this.bareSpec.startsWith("workspace:")) {
1285
+ this.type = "workspace";
1286
+ const ws2 = this.bareSpec.substring("workspace:".length).trim();
1287
+ const w = ws2.lastIndexOf("@");
1288
+ if (w === -1) {
1289
+ this.workspace = this.name;
1290
+ } else {
1291
+ const wsName = ws2.substring(0, w);
1292
+ if (!wsName || wsName === "*" || wsName === "~" || wsName === "^" || (wsName.startsWith("@") ? wsName.split("/").length !== 2 || wsName.substring(1).includes("@") : wsName.includes("@"))) {
1293
+ throw this.#error(
1294
+ "workspace: name must be a path or valid package name",
1295
+ { found: wsName }
1296
+ );
1297
+ }
1298
+ this.workspace = wsName;
1299
+ }
1300
+ const wss = w === -1 ? ws2 : ws2.substring(w + 1) || "*";
1301
+ const range2 = wss === "*" ? void 0 : parseRange(wss);
1302
+ if (wss !== "*" && wss !== "~" && wss !== "^" && !range2) {
1303
+ throw this.#error(
1304
+ "workspace: spec must be one of *, ~, or ^, or a valid semver range",
1305
+ {
1306
+ found: wss,
1307
+ wanted: `'*'|'~'|'^'|SemverRange`
1308
+ }
1309
+ );
1310
+ }
1311
+ this.workspaceSpec = wss;
1312
+ if (range2) {
1313
+ this.semver = wss;
1314
+ this.range = range2;
1315
+ }
1316
+ return;
1317
+ }
1318
+ 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
1319
+ this.bareSpec.startsWith("git@github.com")) {
1320
+ if (this.bareSpec.startsWith("git@")) {
1321
+ this.bareSpec = `git+ssh://${this.bareSpec}`;
1322
+ this.spec = `${this.name}@${this.bareSpec}`;
1323
+ }
1324
+ this.type = "git";
1325
+ for (const [name2, host] of Object.entries(
1326
+ this.options["git-hosts"]
1327
+ )) {
1328
+ const s = host.indexOf("$");
1329
+ if (s > 0 && this.bareSpec.startsWith(host.substring(0, s))) {
1330
+ const p = this.bareSpec.substring(s).replace(/\.git(#.*)?$/, "$1");
1331
+ this.bareSpec = `${name2}:${p}`;
1332
+ this.spec = `${this.name}@${this.bareSpec}`;
1333
+ this.#parseHostedGit(name2, host);
1334
+ this.type = "git";
1335
+ return;
1336
+ }
1337
+ }
1338
+ this.#parseGitSelector(this.bareSpec);
1339
+ return;
1340
+ }
1341
+ const regs = Object.entries(this.options.registries);
1342
+ if (this.bareSpec.startsWith("registry:")) {
1343
+ const reg = this.bareSpec.substring("registry:".length);
1344
+ const h = reg.indexOf("#");
1345
+ if (h === -1) {
1346
+ throw this.#error("registry: must include name/version");
1347
+ }
1348
+ this.type = "registry";
1349
+ let url = reg.substring(0, h);
1350
+ if (!url.endsWith("/")) url += "/";
1351
+ const regSpec = reg.substring(h + 1);
1352
+ for (let [name2, u] of regs) {
1353
+ if (!u.endsWith("/")) {
1354
+ u += "/";
1355
+ this.options.registries[name2] = u;
1356
+ }
1357
+ if (u === url) this.namedRegistry = name2;
1358
+ }
1359
+ this.#parseRegistrySpec(regSpec, url);
1360
+ this.#guessRegistryTarball();
1361
+ return;
1362
+ }
1363
+ for (const [host, url] of regs) {
1364
+ const h = `${host}:`;
1365
+ if (this.bareSpec.startsWith(h)) {
1366
+ this.type = "registry";
1367
+ this.namedRegistry = host;
1368
+ this.#parseRegistrySpec(
1369
+ this.bareSpec.substring(h.length),
1370
+ url
1371
+ ).namedRegistry ??= host;
1372
+ if (this.subspec && this.name === this.bareSpec) {
1373
+ this.name = this.subspec.name;
1374
+ this.spec = `${this.name}@${this.bareSpec}`;
1375
+ assertPathSafeName(this.name, this.spec);
1376
+ }
1377
+ this.#guessRegistryTarball();
1378
+ return;
1379
+ }
1380
+ }
1381
+ const ghosts = Object.entries(this.options["git-hosts"]);
1382
+ for (const [name2, template] of ghosts) {
1383
+ if (this.#parseHostedGit(name2, template)) {
1384
+ this.type = "git";
1385
+ return;
1386
+ }
1387
+ }
1388
+ const jsrs = Object.entries(this.options["jsr-registries"]);
1389
+ for (const [host, url] of jsrs) {
1390
+ const h = `${host}:`;
1391
+ if (this.bareSpec.startsWith(h)) {
1392
+ this.type = "registry";
1393
+ this.namedJsrRegistry = host;
1394
+ this.#parseJsrRegistrySpec(
1395
+ this.bareSpec.substring(h.length),
1396
+ url
1397
+ ).namedJsrRegistry ??= host;
1398
+ return;
1399
+ }
1400
+ }
1401
+ if (this.bareSpec.startsWith("https://") || this.bareSpec.startsWith("http://")) {
1402
+ this.remoteURL = this.bareSpec;
1403
+ this.type = "remote";
1404
+ return;
1405
+ }
1406
+ if (this.bareSpec.startsWith("file:")) {
1407
+ this.type = "file";
1408
+ const [path, uri] = getNormalizeFile(
1409
+ this.constructor.nodejsDependencies
1410
+ )(this.bareSpec, this);
1411
+ this.file = path;
1412
+ this.bareSpec = uri.replace(/\/+$/, "");
1413
+ this.spec = `${this.name}@${this.bareSpec}`;
1414
+ return;
1415
+ }
1416
+ this.#assertKnownProtocol(this.bareSpec);
1417
+ if (!this.bareSpec.startsWith("./") && !this.bareSpec.startsWith("../") && this.options["git-hosts"].github) {
1418
+ const hash2 = this.bareSpec.indexOf("#");
1419
+ const up = hash2 === -1 ? this.bareSpec : this.bareSpec.substring(0, hash2);
1420
+ if (up.split("/").length === 2) {
1421
+ this.bareSpec = `github:${this.bareSpec}`;
1422
+ this.spec = `${this.name}@${this.bareSpec}`;
1423
+ this.#parseHostedGit(
1424
+ "github",
1425
+ this.options["git-hosts"].github
1426
+ );
1427
+ this.type = "git";
1428
+ return;
1429
+ }
1430
+ }
1431
+ if (this.bareSpec.includes("/") || this.bareSpec === "." || this.bareSpec === "..") {
1432
+ this.type = "file";
1433
+ const [file, uri] = getNormalizeFile(
1434
+ this.constructor.nodejsDependencies
1435
+ )(`file:${this.bareSpec}`, this);
1436
+ this.bareSpec = uri;
1437
+ this.spec = `${this.name}@${this.bareSpec}`;
1438
+ this.file = file;
1439
+ return;
1440
+ }
1441
+ this.type = "registry";
1442
+ const range = parseRange(this.bareSpec);
1443
+ if (range) {
1444
+ this.semver = this.bareSpec.trim();
1445
+ this.range = range;
1446
+ } else {
1447
+ this.distTag = this.bareSpec;
1448
+ }
1449
+ this.registrySpec = this.bareSpec;
1450
+ const {
1451
+ "scoped-registries": scopeRegs,
1452
+ registry,
1453
+ registries,
1454
+ "default-registry-alias": defaultAlias
1455
+ } = this.options;
1456
+ const scopeReg = this.scope && scopeRegs[this.scope];
1457
+ this.registry = scopeReg ?? registry ?? registries[defaultAlias];
1458
+ for (const r of Object.values(this.options["jsr-registries"])) {
1459
+ if (this.registry === r) return;
1460
+ }
1461
+ this.#guessRegistryTarball();
1462
+ }
1463
+ #parseScope(name2) {
1464
+ if (!name2.startsWith("@")) return;
1465
+ const s = name2.indexOf("/");
1466
+ if (s > 1 && s < name2.length - 1) {
1467
+ const scope = name2.substring(0, s);
1468
+ this.registry = this.scopeRegistry = this.options["scoped-registries"][scope];
1469
+ this.scope = scope;
1470
+ }
1471
+ }
1472
+ #parseHostedGit(name2, template) {
1473
+ if (this.bareSpec.startsWith(`${name2}:`)) {
1474
+ const h = this.bareSpec.indexOf("#");
1475
+ const bare = h === -1 ? this.bareSpec : this.bareSpec.substring(0, h);
1476
+ const hash2 = h === -1 ? "" : this.bareSpec.substring(h);
1477
+ const hostPath = bare.substring(name2.length + 1);
1478
+ if (!hostPath) {
1479
+ throw this.#error("invalid named git host specifier");
1480
+ }
1481
+ const split = hostPath.split("/");
1482
+ let t = template;
1483
+ for (let i = 0; i < split.length; i++) {
1484
+ t = t.split(`$${i + 1}`).join(split[i]);
1485
+ }
1486
+ t += hash2;
1487
+ this.namedGitHost = name2;
1488
+ this.namedGitHostPath = hostPath;
1489
+ this.#parseGitSelector(t);
1490
+ if (this.gitCommittish && !this.gitSelectorParsed?.path) {
1491
+ const archiveHost = this.options["git-host-archives"][name2];
1492
+ if (name2 === "github" && this.gitCommittish.startsWith("pull/") && this.gitCommittish.match(/\//g)?.length === 1) {
1493
+ this.gitCommittish += "/head";
1494
+ }
1495
+ if (archiveHost) {
1496
+ this.type = "remote";
1497
+ let t2 = archiveHost;
1498
+ t2 = t2.split("$committish").join(this.gitCommittish);
1499
+ for (let i = 0; i < split.length; i++) {
1500
+ t2 = t2.split(`$${i + 1}`).join(split[i]);
1501
+ }
1502
+ this.remoteURL = t2;
1503
+ }
1504
+ }
1505
+ return true;
1506
+ }
1507
+ return false;
1508
+ }
1509
+ /* c8 ignore start */
1510
+ [kCustomInspect]() {
1511
+ return `@vltpkg/spec.Spec ${String(this)}`;
1512
+ }
1513
+ /* c8 ignore stop */
1514
+ #guessRegistryTarball() {
1515
+ const { name: name2, registry, range } = this.final;
1516
+ if (!registry || !range?.isSingle) return;
1517
+ const stripScope = /^@[^/]+\//;
1518
+ const base = registry.endsWith("/") ? registry : registry + "/";
1519
+ this.conventionalRegistryTarball = String(
1520
+ new URL(
1521
+ `${name2}/-/${name2.replace(stripScope, "")}-${range}.tgz`,
1522
+ base
1523
+ )
1524
+ );
1525
+ }
1526
+ #parseRegistrySpec(s, url) {
1527
+ this.registry = url;
1528
+ this.subspec = this.constructor.parse(s, {
1529
+ ...this.options,
1530
+ registry: url
1531
+ });
1532
+ return this.subspec;
1533
+ }
1534
+ #parseJsrRegistrySpec(s, url) {
1535
+ this.registry = url;
1536
+ if (!s.startsWith("@")) s = `${this.name}@${s}`;
1537
+ const name2 = s.startsWith("@jsr/") ? s : `@jsr/${s.replace(/^@/, "").replace(/\//, "__")}`;
1538
+ this.subspec = this.constructor.parse(name2, {
1539
+ ...this.options,
1540
+ "scoped-registries": {
1541
+ ...this.options["scoped-registries"],
1542
+ "@jsr": url
1543
+ }
1544
+ });
1545
+ if (this.name === "(unknown)") {
1546
+ const nextAt = s.indexOf("@", 1);
1547
+ if (nextAt === -1) {
1548
+ this.name = s;
1549
+ } else {
1550
+ this.name = s.substring(0, s.indexOf("@", 1));
1551
+ }
1552
+ assertPathSafeName(this.name, s);
1553
+ }
1554
+ const reg = `${this.namedJsrRegistry}:`;
1555
+ const n7 = `${reg}${this.name}`;
1556
+ if (this.bareSpec.startsWith(n7 + "@")) {
1557
+ this.bareSpec = reg + this.bareSpec.substring(n7.length + 1);
1558
+ } else if (this.bareSpec === n7) {
1559
+ this.bareSpec = reg;
1560
+ }
1561
+ this.spec = this.name + "@" + this.bareSpec;
1562
+ return this.subspec;
1563
+ }
1564
+ #assertKnownProtocol(str) {
1565
+ const proto = unknownProtocol(str, this.options);
1566
+ if (proto === void 0) return;
1567
+ throw this.#error(`Protocol ${proto}: is not defined`, {
1568
+ found: `${proto}:`,
1569
+ validOptions: [
1570
+ .../* @__PURE__ */ new Set([
1571
+ ...builtinProtocols,
1572
+ this.options["default-registry-alias"],
1573
+ ...Object.keys(this.options.registries),
1574
+ ...Object.keys(this.options["git-hosts"]),
1575
+ ...Object.keys(this.options["jsr-registries"])
1576
+ ])
1577
+ ].map((p) => `${p}:`)
1578
+ });
1579
+ }
1580
+ #error(message, extra = {}) {
1581
+ return error(message, { spec: this.spec, ...extra }, this.#error);
1582
+ }
1583
+ #parseGitSelector(s) {
1584
+ const h = s.indexOf("#");
1585
+ if (h === -1) {
1586
+ this.gitRemote = s;
1587
+ return;
1588
+ }
1589
+ this.gitRemote = s.substring(0, h);
1590
+ this.gitSelector = s.substring(h + 1);
1591
+ const [selectorParsed, committish, range] = this.constructor.parseGitSelector(this.gitSelector, this);
1592
+ this.range = range;
1593
+ this.gitCommittish = committish;
1594
+ this.gitSelectorParsed = selectorParsed;
1595
+ }
1596
+ /**
1597
+ * Should only ever be called with the bit that comes AFTER the #
1598
+ * in the git remote url.
1599
+ */
1600
+ static parseGitSelector(selector, spec) {
1601
+ if (!selector) return [{}];
1602
+ const split = selector.split("::");
1603
+ const first = split[0];
1604
+ let committish = void 0;
1605
+ let range = void 0;
1606
+ const parsed = {};
1607
+ if (typeof first !== "string") {
1608
+ throw typeError("impossible", {
1609
+ found: first,
1610
+ wanted: String
1611
+ });
1612
+ }
1613
+ if (!first.includes(":")) {
1614
+ committish = first;
1615
+ split.shift();
1616
+ }
1617
+ for (const kv of split) {
1618
+ const c = kv.indexOf(":");
1619
+ if (c === -1) continue;
1620
+ const k3 = kv.substring(0, c);
1621
+ const v2 = kv.substring(c + 1);
1622
+ if (k3 === "semver") {
1623
+ if (committish) {
1624
+ throw error(
1625
+ "Cannot specify a semver range and committish value",
1626
+ { spec }
1627
+ );
1628
+ }
1629
+ range = parseRange(v2);
1630
+ if (!range) {
1631
+ throw error(`Invalid git tag semver range: ${v2}`, { spec });
1632
+ }
1633
+ }
1634
+ if (k3 === "semver" || k3 === "path") {
1635
+ if (k3 === "path") {
1636
+ if (
1637
+ /* c8 ignore next */
1638
+ this.nodejsDependencies?.isAbsolute(
1639
+ v2
1640
+ ) || /(^|\/|\\)\.\.($|\\|\/)/.test(v2)
1641
+ ) {
1642
+ throw error("Invalid path in git selector", { spec });
1643
+ }
1644
+ parsed.path = (this.nodejsDependencies ? this.nodejsDependencies.join("/", v2).substring(1) : v2).replace(/\\/g, "/");
1645
+ } else {
1646
+ parsed[k3] = v2;
1647
+ }
1648
+ }
1649
+ }
1650
+ return [parsed, committish, range];
1651
+ }
1652
+ };
1653
+ var getNormalizeFile = (opts) => (bareSpec, spec) => {
1654
+ const slashes = bareSpec.substring(
1655
+ "file:".length,
1656
+ "file://".length
1657
+ );
1658
+ const pref = `file:${slashes === "//" ? slashes : ""}`;
1659
+ const rest = bareSpec.substring(pref.length);
1660
+ const [a = "", b = "/", c = "/", d3 = "/"] = rest.split("", 4);
1661
+ if (!a) {
1662
+ return [".", "file:."];
1663
+ }
1664
+ if (a === "/" && b === "~" && c !== "/" || a === "~" && b !== "/") {
1665
+ throw error(
1666
+ `invalid file: specifier. '~username' not supported`,
1667
+ { spec }
1668
+ );
1669
+ }
1670
+ if (a === "~") {
1671
+ return (
1672
+ /* c8 ignore start */
1673
+ opts ? [
1674
+ opts.resolve(opts.homedir(), rest.substring(2)),
1675
+ `file:${rest}`
1676
+ ] : [rest, `file:${rest}`]
1677
+ );
1678
+ }
1679
+ if (a === "/" && b === "~") {
1680
+ return opts ? [
1681
+ opts.resolve(opts.homedir(), rest.substring(3)),
1682
+ `file:${rest.substring(1)}`
1683
+ ] : (
1684
+ /* c8 ignore stop */
1685
+ [rest.substring(1), `file:${rest.substring(1)}`]
1686
+ );
1687
+ }
1688
+ if (a === "/" && b === "." && (c === "/" || c === "." && d3 === "/")) {
1689
+ return [rest.substring(1), `file:${rest.substring(1)}`];
1690
+ }
1691
+ if (a === "." && (b === "/" || b === "." && c === "/")) {
1692
+ return [rest, `file:${rest}`];
1693
+ }
1694
+ if (slashes === "//") {
1695
+ try {
1696
+ const parsed = new URL(bareSpec);
1697
+ if (parsed.host) {
1698
+ if (parsed.host !== "localhost") {
1699
+ throw error(
1700
+ `invalid file:// specifier. host must be empty or 'localhost'`,
1701
+ {
1702
+ spec,
1703
+ found: parsed.host,
1704
+ validOptions: ["", "localhost"]
1705
+ }
1706
+ );
1707
+ }
1708
+ }
1709
+ return [
1710
+ parsed.pathname.replace(/^\/([a-zA-Z]:\/)/, "$1"),
1711
+ `file://${parsed.pathname}`
1712
+ ];
1713
+ } catch (er) {
1714
+ throw error("invalid file:// specifier", {
1715
+ spec,
1716
+ cause: er
1717
+ });
1718
+ }
1719
+ }
1720
+ if (opts?.winPath.isAbsolute(rest)) {
1721
+ return [rest, `file://${rest}`];
1722
+ }
1723
+ return [`./${rest}`, `file:./${rest}`];
1724
+ };
1725
+
1726
+ // ../../src/types/src/index.ts
1727
+ import { posix } from "node:path";
1728
+ import { debuglog } from "node:util";
1729
+ var debug = debuglog("vlt");
1730
+ var unixify = (ref) => ref.replace(/[\\:]/g, "/");
1731
+ var secure = (ref) => {
1732
+ const s = unixify(posix.join(".", posix.join("/", unixify(ref))));
1733
+ return s === "./" ? "" : s;
1734
+ };
1735
+ var secureBinPaths = (bin) => {
1736
+ const res = {};
1737
+ for (const [key, val] of Object.entries(bin)) {
1738
+ const v2 = typeof val === "string" ? secure(val) : "";
1739
+ const k3 = posix.basename(secure(key));
1740
+ if (!k3 || !v2) {
1741
+ debug("dropped unusable bin entry", key, val);
1742
+ continue;
1743
+ }
1744
+ if (k3 !== key || v2 !== val) {
1745
+ debug("rewrote unsafe bin entry", key, val, "->", k3, v2);
1746
+ }
1747
+ res[k3] = v2;
1748
+ }
1749
+ return res;
1750
+ };
1751
+ var normalizeBinPaths = (manifest) => {
1752
+ const { name: name2, bin } = manifest;
1753
+ if (bin) {
1754
+ if (name2 && typeof bin === "string") {
1755
+ const [_scope, pkg] = parseScope(name2);
1756
+ return secureBinPaths({ [pkg]: bin });
1757
+ } else if (typeof bin === "object") {
1758
+ return secureBinPaths(bin);
1759
+ }
1760
+ }
1761
+ };
1762
+ var integrityRE = /^sha512-[a-zA-Z0-9/+]{86}==$/;
1763
+ var isIntegrity = (i) => typeof i === "string" && integrityRE.test(i);
1764
+ var integrityHex = (i) => isIntegrity(i) ? Buffer.from(i.slice(7), "base64").toString("hex") : void 0;
1765
+ var BROTLI_TARBALL_EXT = ".tar.br";
1766
+ var tarballFormat = (url) => {
1767
+ const end = /[?#]/.exec(url)?.index ?? url.length;
1768
+ return url.endsWith(BROTLI_TARBALL_EXT, end) ? "brotli" : void 0;
1769
+ };
1770
+ var asError = (er, fallbackMessage = "Unknown error") => er instanceof Error ? er : new Error(String(er) || fallbackMessage);
1771
+ var isObject = (v2) => !!v2 && typeof v2 === "object" && (v2.constructor === Object || v2.constructor === void 0);
1772
+ var maybeRecordStringString = (o) => o === void 0 || isRecordStringString(o);
1773
+ var isRecordStringString = (o) => isRecordStringT(o, (s) => typeof s === "string");
1774
+ var isRecordStringT = (o, check) => isObject(o) && Object.entries(o).every(
1775
+ ([k3, v2]) => typeof k3 === "string" && check(v2)
1776
+ );
1777
+ var maybePeerDependenciesMetaSet = (o) => o === void 0 || isRecordStringT(
1778
+ o,
1779
+ (v2) => isPeerDependenciesMetaValue(v2)
1780
+ );
1781
+ var maybeBoolean = (o) => o === void 0 || typeof o === "boolean";
1782
+ var isPeerDependenciesMetaValue = (o) => isObject(o) && maybeBoolean(o.optional);
1783
+ var maybeString = (a) => a === void 0 || typeof a === "string";
1784
+ var maybeDist = (a) => a === void 0 || isObject(a) && maybeString(a.tarball);
1785
+ var isManifest = (m) => isObject(m) && !Array.isArray(m) && maybeString(m.name) && maybeString(m.version) && maybeRecordStringString(m.dependencies) && maybeRecordStringString(m.devDependencies) && maybeRecordStringString(m.optionalDependencies) && maybeRecordStringString(m.peerDependencies) && maybeRecordStringString(m.acceptDependencies) && maybePeerDependenciesMetaSet(m.peerDependenciesMeta) && maybeDist(m.dist);
1786
+ var parseScope = (scoped) => {
1787
+ if (scoped.startsWith("@")) {
1788
+ const [scope, name2, ...rest] = scoped.split("/");
1789
+ if (scope && name2 && rest.length === 0) return [scope, name2];
1790
+ }
1791
+ return [void 0, scoped];
1792
+ };
23
1793
 
24
1794
  // ../../src/cache/src/index.ts
25
1795
  import { createHash, randomBytes } from "node:crypto";
@@ -624,7 +2394,7 @@ import { resolve as resolve6, dirname } from "node:path";
624
2394
 
625
2395
  // ../../node_modules/.vlt/~npm~glob@13.0.6/node_modules/glob/dist/esm/index.min.js
626
2396
  import { fileURLToPath as Wi } from "node:url";
627
- import { posix as mi, win32 as re } from "node:path";
2397
+ import { posix as mi, win32 as re2 } from "node:path";
628
2398
  import { fileURLToPath as gi } from "node:url";
629
2399
  import { lstatSync as wi, readdir as yi, readdirSync as bi, readlinkSync as Si, realpathSync as Ei } from "node:fs";
630
2400
  import * as xi from "node:fs";
@@ -2748,7 +4518,7 @@ var Pt = class n2 extends R2 {
2748
4518
  return new n2(t, e, this.root, this.roots, this.nocase, this.childrenCache(), s);
2749
4519
  }
2750
4520
  getRootString(t) {
2751
- return re.parse(t).root;
4521
+ return re2.parse(t).root;
2752
4522
  }
2753
4523
  getRoot(t) {
2754
4524
  if (t = Ri(t.toUpperCase()), t === this.root.name) return this.root;
@@ -3020,11 +4790,11 @@ var it = class extends It {
3020
4790
  sep = "\\";
3021
4791
  constructor(t = process.cwd(), e = {}) {
3022
4792
  let { nocase: s = true } = e;
3023
- super(t, re, "\\", { ...e, nocase: s }), this.nocase = s;
4793
+ super(t, re2, "\\", { ...e, nocase: s }), this.nocase = s;
3024
4794
  for (let i = this.cwd; i; i = i.parent) i.nocase = this.nocase;
3025
4795
  }
3026
4796
  parseRootPath(t) {
3027
- return re.parse(t).root.toUpperCase();
4797
+ return re2.parse(t).root.toUpperCase();
3028
4798
  }
3029
4799
  newRoot(t) {
3030
4800
  return new Pt(this.rootPath, U2, void 0, this.roots, this.nocase, this.childrenCache(), { fs: t });
@@ -3916,10 +5686,10 @@ var isDirSync = (path) => {
3916
5686
  var isDir = (path) => stat(path).then((st2) => st2.isDirectory(), () => false);
3917
5687
  var win32DefaultTmp = async (path) => {
3918
5688
  const { root } = parse3(path);
3919
- const tmp = tmpdir();
3920
- const { root: tmpRoot } = parse3(tmp);
5689
+ const tmp2 = tmpdir();
5690
+ const { root: tmpRoot } = parse3(tmp2);
3921
5691
  if (root.toLowerCase() === tmpRoot.toLowerCase()) {
3922
- return tmp;
5692
+ return tmp2;
3923
5693
  }
3924
5694
  const driveTmp = resolve3(root, "/temp");
3925
5695
  if (await isDir(driveTmp)) {
@@ -3929,10 +5699,10 @@ var win32DefaultTmp = async (path) => {
3929
5699
  };
3930
5700
  var win32DefaultTmpSync = (path) => {
3931
5701
  const { root } = parse3(path);
3932
- const tmp = tmpdir();
3933
- const { root: tmpRoot } = parse3(tmp);
5702
+ const tmp2 = tmpdir();
5703
+ const { root: tmpRoot } = parse3(tmp2);
3934
5704
  if (root.toLowerCase() === tmpRoot.toLowerCase()) {
3935
- return tmp;
5705
+ return tmp2;
3936
5706
  }
3937
5707
  const driveTmp = resolve3(root, "/temp");
3938
5708
  if (isDirSync(driveTmp)) {
@@ -3991,10 +5761,10 @@ var rimrafMoveRemoveDir = async (path, opt, ent) => {
3991
5761
  await ignoreENOENT(tmpUnlink(path, opt.tmp, rmdir2));
3992
5762
  return true;
3993
5763
  };
3994
- var tmpUnlink = async (path, tmp, rm2) => {
3995
- const tmpFile = resolve4(tmp, uniqueFilename(path));
5764
+ var tmpUnlink = async (path, tmp2, rm3) => {
5765
+ const tmpFile = resolve4(tmp2, uniqueFilename(path));
3996
5766
  await rename(path, tmpFile);
3997
- return await rm2(tmpFile);
5767
+ return await rm3(tmpFile);
3998
5768
  };
3999
5769
  var rimrafMoveRemoveSync = (path, opt) => {
4000
5770
  opt?.signal?.throwIfAborted();
@@ -4005,7 +5775,7 @@ var rimrafMoveRemoveDirSync = (path, opt, ent) => {
4005
5775
  if (!opt.tmp) {
4006
5776
  return rimrafMoveRemoveDirSync(path, { ...opt, tmp: defaultTmpSync(path) }, ent);
4007
5777
  }
4008
- const tmp = opt.tmp;
5778
+ const tmp2 = opt.tmp;
4009
5779
  if (path === opt.tmp && parse4(path).root !== path) {
4010
5780
  throw new Error("cannot delete temp directory used for deletion");
4011
5781
  }
@@ -4022,7 +5792,7 @@ var rimrafMoveRemoveDirSync = (path, opt, ent) => {
4022
5792
  if (opt.filter && !opt.filter(path, ent)) {
4023
5793
  return false;
4024
5794
  }
4025
- ignoreENOENTSync(() => tmpUnlinkSync(path, tmp, unlinkFixEPERMSync));
5795
+ ignoreENOENTSync(() => tmpUnlinkSync(path, tmp2, unlinkFixEPERMSync));
4026
5796
  return true;
4027
5797
  }
4028
5798
  let removedAll = true;
@@ -4039,13 +5809,13 @@ var rimrafMoveRemoveDirSync = (path, opt, ent) => {
4039
5809
  if (opt.filter && !opt.filter(path, ent)) {
4040
5810
  return false;
4041
5811
  }
4042
- ignoreENOENTSync(() => tmpUnlinkSync(path, tmp, rmdirSync));
5812
+ ignoreENOENTSync(() => tmpUnlinkSync(path, tmp2, rmdirSync));
4043
5813
  return true;
4044
5814
  };
4045
- var tmpUnlinkSync = (path, tmp, rmSync2) => {
4046
- const tmpFile = resolve4(tmp, uniqueFilename(path));
5815
+ var tmpUnlinkSync = (path, tmp2, rmSync3) => {
5816
+ const tmpFile = resolve4(tmp2, uniqueFilename(path));
4047
5817
  renameSync(path, tmpFile);
4048
- return rmSync2(tmpFile);
5818
+ return rmSync3(tmpFile);
4049
5819
  };
4050
5820
 
4051
5821
  // ../../node_modules/.vlt/~npm~rimraf@6.1.3/node_modules/rimraf/dist/esm/rimraf-windows.js
@@ -4230,7 +6000,7 @@ var windows = Object.assign(wrap(rimrafWindows), {
4230
6000
  sync: windowsSync
4231
6001
  });
4232
6002
  var posixSync = wrapSync(rimrafPosixSync);
4233
- var posix = Object.assign(wrap(rimrafPosix), { sync: posixSync });
6003
+ var posix2 = Object.assign(wrap(rimrafPosix), { sync: posixSync });
4234
6004
  var moveRemoveSync = wrapSync(rimrafMoveRemoveSync);
4235
6005
  var moveRemove = Object.assign(wrap(rimrafMoveRemove), {
4236
6006
  sync: moveRemoveSync
@@ -4245,7 +6015,7 @@ var rimraf = Object.assign(rimraf_, {
4245
6015
  manualSync,
4246
6016
  native,
4247
6017
  nativeSync,
4248
- posix,
6018
+ posix: posix2,
4249
6019
  posixSync,
4250
6020
  windows,
4251
6021
  windowsSync,
@@ -4269,6 +6039,7 @@ var Cache = class _Cache extends I {
4269
6039
  #pending = /* @__PURE__ */ new Set();
4270
6040
  onDiskWrite;
4271
6041
  onDiskDelete;
6042
+ store;
4272
6043
  /**
4273
6044
  * A list of the actions currently happening in the background
4274
6045
  */
@@ -4287,6 +6058,7 @@ var Cache = class _Cache extends I {
4287
6058
  onDiskWrite,
4288
6059
  onDiskDelete,
4289
6060
  path,
6061
+ store,
4290
6062
  fetchMethod: _2,
4291
6063
  sizeCalculation = options.maxSize || options.maxEntrySize ? (v2, k3) => v2.length + k3.length : void 0,
4292
6064
  ...lruOpts
@@ -4310,6 +6082,7 @@ var Cache = class _Cache extends I {
4310
6082
  });
4311
6083
  this.onDiskWrite = onDiskWrite;
4312
6084
  this.onDiskDelete = onDiskDelete;
6085
+ this.store = store;
4313
6086
  this.#path = path;
4314
6087
  }
4315
6088
  /**
@@ -4435,16 +6208,14 @@ var Cache = class _Cache extends I {
4435
6208
  */
4436
6209
  integrityPath(integrity) {
4437
6210
  if (!integrity) return void 0;
4438
- const m = /^sha512-([a-zA-Z0-9/+]{86}==)$/.exec(integrity);
4439
- const hash2 = m?.[1];
4440
- if (!hash2) {
6211
+ const hex = integrityHex(integrity);
6212
+ if (!hex) {
4441
6213
  throw error("invalid integrity value", {
4442
6214
  found: integrity,
4443
- wanted: /^sha512-([a-zA-Z0-9/+]{86}==)$/
6215
+ wanted: integrityRE
4444
6216
  });
4445
6217
  }
4446
- const base = Buffer.from(hash2, "base64").toString("hex");
4447
- return resolve6(this.#path, base);
6218
+ return resolve6(this.#path, hex);
4448
6219
  }
4449
6220
  /**
4450
6221
  * Read synchronously from the fs cache storage if not already
@@ -4471,13 +6242,20 @@ var Cache = class _Cache extends I {
4471
6242
  }
4472
6243
  /* c8 ignore stop */
4473
6244
  /**
4474
- * Delete path and path + '.key'
6245
+ * Delete path and path + '.key', and with an integrity, its
6246
+ * integrity link and global store entry
4475
6247
  */
4476
6248
  async #diskDelete(path, integrity) {
4477
- const intPath = this.#maybeIntegrityPath(integrity);
4478
6249
  const paths = [path, path + ".key"];
4479
- if (intPath) paths.push(intPath);
4480
- return await rimraf(paths);
6250
+ const hex = integrityHex(integrity);
6251
+ if (hex) paths.push(resolve6(this.#path, hex));
6252
+ const deleted = await rimraf(paths);
6253
+ if (hex && this.store) {
6254
+ const entry = resolve6(this.store, hex);
6255
+ await rimraf(entry);
6256
+ await rimraf([entry + ".json", entry + ".copied"]);
6257
+ }
6258
+ return deleted;
4481
6259
  }
4482
6260
  #maybeIntegrityPath(i) {
4483
6261
  try {
@@ -4486,14 +6264,14 @@ var Cache = class _Cache extends I {
4486
6264
  }
4487
6265
  }
4488
6266
  async #writeFileAtomic(file, data) {
4489
- const tmp = `${file}.${this.#random}.${this.#i++}`;
4490
- await writeFile(tmp, data);
4491
- await rename2(tmp, file);
6267
+ const tmp2 = `${file}.${this.#random}.${this.#i++}`;
6268
+ await writeFile(tmp2, data);
6269
+ await rename2(tmp2, file);
4492
6270
  }
4493
6271
  async #linkAtomic(src, dest) {
4494
- const tmp = `${dest}.${this.#random}.${this.#i++}`;
4495
- await link(src, tmp);
4496
- await rename2(tmp, dest);
6272
+ const tmp2 = `${dest}.${this.#random}.${this.#i++}`;
6273
+ await link(src, tmp2);
6274
+ await rename2(tmp2, dest);
4497
6275
  }
4498
6276
  async #diskWrite(valFile, key, val, integrity) {
4499
6277
  const dir = dirname(valFile);
@@ -4543,9 +6321,600 @@ var Cache = class _Cache extends I {
4543
6321
  };
4544
6322
 
4545
6323
  // ../../src/cache-unzip/src/unzip.ts
6324
+ import { setPriority } from "node:os";
4546
6325
  import { pathToFileURL } from "node:url";
6326
+ import { debuglog as debuglog4 } from "node:util";
4547
6327
  import { gunzipSync } from "node:zlib";
4548
- var __CODE_SPLIT_SCRIPT_NAME = import.meta.filename;
6328
+
6329
+ // ../../src/tar/src/store-index.ts
6330
+ import { readFileSync as readFileSync2 } from "node:fs";
6331
+ import { debuglog as debuglog2 } from "node:util";
6332
+ var debug2 = debuglog2("vlt");
6333
+ var storeIndexPath = (storeEntry) => storeEntry + ".json";
6334
+ var isRecord2 = (x3) => !!x3 && typeof x3 === "object" && !Array.isArray(x3);
6335
+ var isOptString = (x3) => x3 === void 0 || typeof x3 === "string";
6336
+ var unsafePath = /(?:^|\/)\.{0,2}(?:\/|$)|\\/;
6337
+ var isRelPath = (p) => typeof p === "string" && !unsafePath.test(p);
6338
+ var isIndexFile = (f) => Array.isArray(f) && f.length === 3 && isRelPath(f[0]) && typeof f[1] === "number" && (f[2] === 0 || f[2] === 1);
6339
+ var isStoreIndex = (x3) => isRecord2(x3) && x3.v === 1 && typeof x3.scripts === "boolean" && isOptString(x3.name) && isOptString(x3.version) && (x3.bins === void 0 || isRecord2(x3.bins) && Object.values(x3.bins).every((b) => typeof b === "string")) && Array.isArray(x3.dirs) && x3.dirs.every(isRelPath) && Array.isArray(x3.files) && x3.files.every(isIndexFile) && isOptString(x3.manifest);
6340
+ var readStoreIndex = (storeEntry) => {
6341
+ let index;
6342
+ try {
6343
+ index = JSON.parse(
6344
+ readFileSync2(storeIndexPath(storeEntry), "utf8")
6345
+ );
6346
+ } catch (er) {
6347
+ if (er.code !== "ENOENT") {
6348
+ debug2("global store: invalid index", storeEntry);
6349
+ }
6350
+ return void 0;
6351
+ }
6352
+ if (isStoreIndex(index)) return index;
6353
+ debug2("global store: invalid index", storeEntry);
6354
+ return void 0;
6355
+ };
6356
+ var storeIndexManifest = (packageJson, bindingGyp) => {
6357
+ let pkg;
6358
+ try {
6359
+ pkg = JSON.parse(
6360
+ packageJson.toString("utf8").replace(/^\uFEFF/, "")
6361
+ );
6362
+ } catch (cause) {
6363
+ throw error("invalid package.json in tarball", { cause });
6364
+ }
6365
+ if (!isRecord2(pkg)) {
6366
+ throw error("invalid package.json in tarball", { found: pkg });
6367
+ }
6368
+ const { name: name2, version, scripts, bin } = pkg;
6369
+ const s = isRecord2(scripts) ? scripts : {};
6370
+ const result = {
6371
+ scripts: !!(s.install || s.preinstall || s.postinstall) || bindingGyp
6372
+ };
6373
+ const bins = normalizeBinPaths({
6374
+ name: typeof name2 === "string" ? name2 : void 0,
6375
+ bin
6376
+ });
6377
+ if (bins && Object.keys(bins).length) result.bins = bins;
6378
+ if (typeof name2 === "string") result.name = name2;
6379
+ if (typeof version === "string") result.version = version;
6380
+ if (isManifest(pkg)) result.manifest = JSON.stringify(pkg);
6381
+ return result;
6382
+ };
6383
+
6384
+ // ../../src/tar/src/unpack.ts
6385
+ import { randomBytes as randomBytes2 } from "node:crypto";
6386
+ import {
6387
+ chmodSync as chmodSync2,
6388
+ lstatSync as lstatSync2,
6389
+ mkdirSync as mkdirSync2,
6390
+ readFileSync as readFileSync3,
6391
+ renameSync as renameSync2,
6392
+ statSync as statSync2,
6393
+ writeFileSync
6394
+ } from "node:fs";
6395
+ import {
6396
+ basename as basename3,
6397
+ dirname as dirname2,
6398
+ isAbsolute,
6399
+ join,
6400
+ relative,
6401
+ resolve as resolve7,
6402
+ sep
6403
+ } from "node:path";
6404
+
6405
+ // ../../node_modules/.vlt/~npm~tar@7.5.22/node_modules/tar/dist/esm/header.js
6406
+ import { posix as pathModule } from "node:path";
6407
+
6408
+ // ../../node_modules/.vlt/~npm~tar@7.5.22/node_modules/tar/dist/esm/large-numbers.js
6409
+ var encode = (num, buf) => {
6410
+ if (!Number.isSafeInteger(num)) {
6411
+ throw Error("cannot encode number outside of javascript safe integer range");
6412
+ } else if (num < 0) {
6413
+ encodeNegative(num, buf);
6414
+ } else {
6415
+ encodePositive(num, buf);
6416
+ }
6417
+ return buf;
6418
+ };
6419
+ var encodePositive = (num, buf) => {
6420
+ buf[0] = 128;
6421
+ for (var i = buf.length; i > 1; i--) {
6422
+ buf[i - 1] = num & 255;
6423
+ num = Math.floor(num / 256);
6424
+ }
6425
+ };
6426
+ var encodeNegative = (num, buf) => {
6427
+ buf[0] = 255;
6428
+ var flipped = false;
6429
+ num = num * -1;
6430
+ for (var i = buf.length; i > 1; i--) {
6431
+ var byte = num & 255;
6432
+ num = Math.floor(num / 256);
6433
+ if (flipped) {
6434
+ buf[i - 1] = onesComp(byte);
6435
+ } else if (byte === 0) {
6436
+ buf[i - 1] = 0;
6437
+ } else {
6438
+ flipped = true;
6439
+ buf[i - 1] = twosComp(byte);
6440
+ }
6441
+ }
6442
+ };
6443
+ var parse6 = (buf) => {
6444
+ const pre = buf[0];
6445
+ const value = pre === 128 ? pos(buf.subarray(1, buf.length)) : pre === 255 ? twos(buf) : null;
6446
+ if (value === null) {
6447
+ throw Error("invalid base256 encoding");
6448
+ }
6449
+ if (!Number.isSafeInteger(value)) {
6450
+ throw Error("parsed number outside of javascript safe integer range");
6451
+ }
6452
+ return value;
6453
+ };
6454
+ var twos = (buf) => {
6455
+ var len = buf.length;
6456
+ var sum = 0;
6457
+ var flipped = false;
6458
+ for (var i = len - 1; i > -1; i--) {
6459
+ var byte = Number(buf[i]);
6460
+ var f;
6461
+ if (flipped) {
6462
+ f = onesComp(byte);
6463
+ } else if (byte === 0) {
6464
+ f = byte;
6465
+ } else {
6466
+ flipped = true;
6467
+ f = twosComp(byte);
6468
+ }
6469
+ if (f !== 0) {
6470
+ sum -= f * Math.pow(256, len - i - 1);
6471
+ }
6472
+ }
6473
+ return sum;
6474
+ };
6475
+ var pos = (buf) => {
6476
+ var len = buf.length;
6477
+ var sum = 0;
6478
+ for (var i = len - 1; i > -1; i--) {
6479
+ var byte = Number(buf[i]);
6480
+ if (byte !== 0) {
6481
+ sum += byte * Math.pow(256, len - i - 1);
6482
+ }
6483
+ }
6484
+ return sum;
6485
+ };
6486
+ var onesComp = (byte) => (255 ^ byte) & 255;
6487
+ var twosComp = (byte) => (255 ^ byte) + 1 & 255;
6488
+
6489
+ // ../../node_modules/.vlt/~npm~tar@7.5.22/node_modules/tar/dist/esm/types.js
6490
+ var isCode = (c) => name.has(c);
6491
+ var normalFsTypes = /* @__PURE__ */ new Set([
6492
+ "0",
6493
+ "",
6494
+ "1",
6495
+ "2",
6496
+ "3",
6497
+ "4",
6498
+ "5",
6499
+ "6",
6500
+ "7",
6501
+ "D"
6502
+ ]);
6503
+ var name = /* @__PURE__ */ new Map([
6504
+ ["0", "File"],
6505
+ // same as File
6506
+ ["", "OldFile"],
6507
+ ["1", "Link"],
6508
+ ["2", "SymbolicLink"],
6509
+ // Devices and FIFOs aren't fully supported
6510
+ // they are parsed, but skipped when unpacking
6511
+ ["3", "CharacterDevice"],
6512
+ ["4", "BlockDevice"],
6513
+ ["5", "Directory"],
6514
+ ["6", "FIFO"],
6515
+ // same as File
6516
+ ["7", "ContiguousFile"],
6517
+ // pax headers
6518
+ ["g", "GlobalExtendedHeader"],
6519
+ ["x", "ExtendedHeader"],
6520
+ // vendor-specific stuff
6521
+ // skip
6522
+ ["A", "SolarisACL"],
6523
+ // like 5, but with data, which should be skipped
6524
+ ["D", "GNUDumpDir"],
6525
+ // metadata only, skip
6526
+ ["I", "Inode"],
6527
+ // data = link path of next file
6528
+ ["K", "NextFileHasLongLinkpath"],
6529
+ // data = path of next file
6530
+ ["L", "NextFileHasLongPath"],
6531
+ // skip
6532
+ ["M", "ContinuationFile"],
6533
+ // like L
6534
+ ["N", "OldGnuLongPath"],
6535
+ // skip
6536
+ ["S", "SparseFile"],
6537
+ // skip
6538
+ ["V", "TapeVolumeHeader"],
6539
+ // like x
6540
+ ["X", "OldExtendedHeader"]
6541
+ ]);
6542
+ var code = new Map(Array.from(name).map((kv) => [kv[1], kv[0]]));
6543
+
6544
+ // ../../node_modules/.vlt/~npm~tar@7.5.22/node_modules/tar/dist/esm/header.js
6545
+ var notNegative = (n7) => n7 === void 0 || n7 < 0 ? void 0 : n7;
6546
+ var Header = class {
6547
+ cksumValid = false;
6548
+ needPax = false;
6549
+ nullBlock = false;
6550
+ block;
6551
+ path;
6552
+ mode;
6553
+ uid;
6554
+ gid;
6555
+ size;
6556
+ cksum;
6557
+ #type = "Unsupported";
6558
+ linkpath;
6559
+ uname;
6560
+ gname;
6561
+ devmaj = 0;
6562
+ devmin = 0;
6563
+ atime;
6564
+ ctime;
6565
+ mtime;
6566
+ charset;
6567
+ comment;
6568
+ constructor(data, off = 0, ex, gex) {
6569
+ if (Buffer.isBuffer(data)) {
6570
+ this.decode(data, off || 0, ex, gex);
6571
+ } else if (data) {
6572
+ this.#slurp(data);
6573
+ }
6574
+ }
6575
+ decode(buf, off, ex, gex) {
6576
+ if (!off) {
6577
+ off = 0;
6578
+ }
6579
+ if (!buf || !(buf.length >= off + 512)) {
6580
+ throw new Error("need 512 bytes for header");
6581
+ }
6582
+ const t = decString(buf, off + 156, 1);
6583
+ const isNormalFS = normalFsTypes.has(t);
6584
+ const exForFields = isNormalFS ? ex : void 0;
6585
+ const gexForFields = isNormalFS ? gex : void 0;
6586
+ this.path = exForFields?.path ?? decString(buf, off, 100);
6587
+ this.mode = exForFields?.mode ?? gexForFields?.mode ?? decNumber(buf, off + 100, 8);
6588
+ this.uid = exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
6589
+ this.gid = exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
6590
+ this.size = notNegative(exForFields?.size ?? gexForFields?.size ?? decNumber(buf, off + 124, 12));
6591
+ this.mtime = exForFields?.mtime ?? gexForFields?.mtime ?? decDate(buf, off + 136, 12);
6592
+ this.cksum = decNumber(buf, off + 148, 12);
6593
+ if (gexForFields)
6594
+ this.#slurp(gexForFields, true);
6595
+ if (exForFields)
6596
+ this.#slurp(exForFields);
6597
+ if (isCode(t)) {
6598
+ this.#type = t || "0";
6599
+ }
6600
+ if (this.#type === "0" && this.path.slice(-1) === "/") {
6601
+ this.#type = "5";
6602
+ }
6603
+ if (this.#type === "5") {
6604
+ this.size = 0;
6605
+ }
6606
+ this.linkpath = decString(buf, off + 157, 100);
6607
+ if (buf.subarray(off + 257, off + 265).toString() === "ustar\x0000") {
6608
+ this.uname = exForFields?.uname ?? gexForFields?.uname ?? decString(buf, off + 265, 32);
6609
+ this.gname = exForFields?.gname ?? gexForFields?.gname ?? decString(buf, off + 297, 32);
6610
+ this.devmaj = exForFields?.devmaj ?? gexForFields?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0;
6611
+ this.devmin = exForFields?.devmin ?? gexForFields?.devmin ?? decNumber(buf, off + 337, 8) ?? 0;
6612
+ if (buf[off + 475] !== 0) {
6613
+ const prefix = decString(buf, off + 345, 155);
6614
+ this.path = prefix + "/" + this.path;
6615
+ } else {
6616
+ const prefix = decString(buf, off + 345, 130);
6617
+ if (prefix) {
6618
+ this.path = prefix + "/" + this.path;
6619
+ }
6620
+ this.atime = ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
6621
+ this.ctime = ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
6622
+ }
6623
+ }
6624
+ let sum = 8 * 32;
6625
+ for (let i = off; i < off + 148; i++) {
6626
+ sum += buf[i];
6627
+ }
6628
+ for (let i = off + 156; i < off + 512; i++) {
6629
+ sum += buf[i];
6630
+ }
6631
+ this.cksumValid = sum === this.cksum;
6632
+ if (this.cksum === void 0 && sum === 8 * 32) {
6633
+ this.nullBlock = true;
6634
+ }
6635
+ }
6636
+ #slurp(ex, gex = false) {
6637
+ Object.assign(this, Object.fromEntries(Object.entries(ex).filter(([k3, v2]) => {
6638
+ return !(v2 === null || v2 === void 0 || k3 === "size" && Number(v2) < 0 || k3 === "path" && gex || k3 === "linkpath" && gex || k3 === "global");
6639
+ })));
6640
+ }
6641
+ encode(buf, off = 0) {
6642
+ if (!buf) {
6643
+ buf = this.block = Buffer.alloc(512);
6644
+ }
6645
+ if (this.#type === "Unsupported") {
6646
+ this.#type = "0";
6647
+ }
6648
+ if (!(buf.length >= off + 512)) {
6649
+ throw new Error("need 512 bytes for header");
6650
+ }
6651
+ const prefixSize = this.ctime || this.atime ? 130 : 155;
6652
+ const split = splitPrefix(this.path || "", prefixSize);
6653
+ const path = split[0];
6654
+ const prefix = split[1];
6655
+ this.needPax = !!split[2];
6656
+ this.needPax = encString(buf, off, 100, path) || this.needPax;
6657
+ this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax;
6658
+ this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax;
6659
+ this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax;
6660
+ this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax;
6661
+ this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax;
6662
+ buf[off + 156] = Number(this.#type.codePointAt(0));
6663
+ this.needPax = encString(buf, off + 157, 100, this.linkpath) || this.needPax;
6664
+ buf.write("ustar\x0000", off + 257, 8);
6665
+ this.needPax = encString(buf, off + 265, 32, this.uname) || this.needPax;
6666
+ this.needPax = encString(buf, off + 297, 32, this.gname) || this.needPax;
6667
+ this.needPax = encNumber(buf, off + 329, 8, this.devmaj) || this.needPax;
6668
+ this.needPax = encNumber(buf, off + 337, 8, this.devmin) || this.needPax;
6669
+ this.needPax = encString(buf, off + 345, prefixSize, prefix) || this.needPax;
6670
+ if (buf[off + 475] !== 0) {
6671
+ this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax;
6672
+ } else {
6673
+ this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax;
6674
+ this.needPax = encDate(buf, off + 476, 12, this.atime) || this.needPax;
6675
+ this.needPax = encDate(buf, off + 488, 12, this.ctime) || this.needPax;
6676
+ }
6677
+ let sum = 8 * 32;
6678
+ for (let i = off; i < off + 148; i++) {
6679
+ sum += buf[i];
6680
+ }
6681
+ for (let i = off + 156; i < off + 512; i++) {
6682
+ sum += buf[i];
6683
+ }
6684
+ this.cksum = sum;
6685
+ encNumber(buf, off + 148, 8, this.cksum);
6686
+ this.cksumValid = true;
6687
+ return this.needPax;
6688
+ }
6689
+ get type() {
6690
+ return this.#type === "Unsupported" ? this.#type : name.get(this.#type);
6691
+ }
6692
+ get typeKey() {
6693
+ return this.#type;
6694
+ }
6695
+ set type(type) {
6696
+ const c = String(code.get(type));
6697
+ if (isCode(c) || c === "Unsupported") {
6698
+ this.#type = c;
6699
+ } else if (isCode(type)) {
6700
+ this.#type = type;
6701
+ } else {
6702
+ throw new TypeError("invalid entry type: " + type);
6703
+ }
6704
+ }
6705
+ };
6706
+ var splitPrefix = (p, prefixSize) => {
6707
+ const pathSize = 100;
6708
+ let pp = p;
6709
+ let prefix = "";
6710
+ let ret = void 0;
6711
+ const root = pathModule.parse(p).root || ".";
6712
+ if (Buffer.byteLength(pp) < pathSize) {
6713
+ ret = [pp, prefix, false];
6714
+ } else {
6715
+ prefix = pathModule.dirname(pp);
6716
+ pp = pathModule.basename(pp);
6717
+ do {
6718
+ if (Buffer.byteLength(pp) <= pathSize && Buffer.byteLength(prefix) <= prefixSize) {
6719
+ ret = [pp, prefix, false];
6720
+ } else if (Buffer.byteLength(pp) > pathSize && Buffer.byteLength(prefix) <= prefixSize) {
6721
+ ret = [pp.slice(0, pathSize - 1), prefix, true];
6722
+ } else {
6723
+ pp = pathModule.join(pathModule.basename(prefix), pp);
6724
+ prefix = pathModule.dirname(prefix);
6725
+ }
6726
+ } while (prefix !== root && ret === void 0);
6727
+ if (!ret) {
6728
+ ret = [p.slice(0, pathSize - 1), "", true];
6729
+ }
6730
+ }
6731
+ return ret;
6732
+ };
6733
+ var decString = (buf, off, size) => buf.subarray(off, off + size).toString("utf8").replace(/\0.*/, "");
6734
+ var decDate = (buf, off, size) => numToDate(decNumber(buf, off, size));
6735
+ var numToDate = (num) => num === void 0 ? void 0 : new Date(num * 1e3);
6736
+ var decNumber = (buf, off, size) => Number(buf[off]) & 128 ? parse6(buf.subarray(off, off + size)) : decSmallNumber(buf, off, size);
6737
+ var nanUndef = (value) => isNaN(value) ? void 0 : value;
6738
+ var decSmallNumber = (buf, off, size) => nanUndef(parseInt(buf.subarray(off, off + size).toString("utf8").replace(/\0.*$/, "").trim(), 8));
6739
+ var MAXNUM = {
6740
+ 12: 8589934591,
6741
+ 8: 2097151
6742
+ };
6743
+ var encNumber = (buf, off, size, num) => num === void 0 ? false : num > MAXNUM[size] || num < 0 ? (encode(num, buf.subarray(off, off + size)), true) : (encSmallNumber(buf, off, size, num), false);
6744
+ var encSmallNumber = (buf, off, size, num) => buf.write(octalString(num, size), off, size, "ascii");
6745
+ var octalString = (num, size) => padOctal(Math.floor(num).toString(8), size);
6746
+ var padOctal = (str, size) => (str.length === size - 1 ? str : new Array(size - str.length - 1).join("0") + str + " ") + "\0";
6747
+ var encDate = (buf, off, size, date) => date === void 0 ? false : encNumber(buf, off, size, date.getTime() / 1e3);
6748
+ var NULLS = new Array(156).join("\0");
6749
+ var encString = (buf, off, size, str) => str === void 0 ? false : (buf.write(str + NULLS, off, size, "utf8"), str.length !== Buffer.byteLength(str) || str.length > size);
6750
+
6751
+ // ../../node_modules/.vlt/~npm~tar@7.5.22/node_modules/tar/dist/esm/pax.js
6752
+ import { basename as basename2 } from "node:path";
6753
+ var Pax = class _Pax {
6754
+ atime;
6755
+ mtime;
6756
+ ctime;
6757
+ charset;
6758
+ comment;
6759
+ gid;
6760
+ uid;
6761
+ gname;
6762
+ uname;
6763
+ linkpath;
6764
+ dev;
6765
+ ino;
6766
+ nlink;
6767
+ path;
6768
+ size;
6769
+ mode;
6770
+ global;
6771
+ constructor(obj, global = false) {
6772
+ this.atime = obj.atime;
6773
+ this.charset = obj.charset;
6774
+ this.comment = obj.comment;
6775
+ this.ctime = obj.ctime;
6776
+ this.dev = obj.dev;
6777
+ this.gid = obj.gid;
6778
+ this.global = global;
6779
+ this.gname = obj.gname;
6780
+ this.ino = obj.ino;
6781
+ this.linkpath = obj.linkpath;
6782
+ this.mtime = obj.mtime;
6783
+ this.nlink = obj.nlink;
6784
+ this.path = obj.path;
6785
+ this.size = obj.size;
6786
+ this.uid = obj.uid;
6787
+ this.uname = obj.uname;
6788
+ }
6789
+ encode() {
6790
+ const body = this.encodeBody();
6791
+ if (body === "") {
6792
+ return Buffer.allocUnsafe(0);
6793
+ }
6794
+ const bodyLen = Buffer.byteLength(body);
6795
+ const bufLen = 512 * Math.ceil(1 + bodyLen / 512);
6796
+ const buf = Buffer.allocUnsafe(bufLen);
6797
+ for (let i = 0; i < 512; i++) {
6798
+ buf[i] = 0;
6799
+ }
6800
+ new Header({
6801
+ // XXX split the path
6802
+ // then the path should be PaxHeader + basename, but less than 99,
6803
+ // prepend with the dirname
6804
+ /* c8 ignore start */
6805
+ path: ("PaxHeader/" + basename2(this.path ?? "")).slice(0, 99),
6806
+ /* c8 ignore stop */
6807
+ mode: this.mode || 420,
6808
+ uid: this.uid,
6809
+ gid: this.gid,
6810
+ size: bodyLen,
6811
+ mtime: this.mtime,
6812
+ type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader",
6813
+ linkpath: "",
6814
+ uname: this.uname || "",
6815
+ gname: this.gname || "",
6816
+ devmaj: 0,
6817
+ devmin: 0,
6818
+ atime: this.atime,
6819
+ ctime: this.ctime
6820
+ }).encode(buf);
6821
+ buf.write(body, 512, bodyLen, "utf8");
6822
+ for (let i = bodyLen + 512; i < buf.length; i++) {
6823
+ buf[i] = 0;
6824
+ }
6825
+ return buf;
6826
+ }
6827
+ encodeBody() {
6828
+ return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname");
6829
+ }
6830
+ encodeField(field) {
6831
+ if (this[field] === void 0) {
6832
+ return "";
6833
+ }
6834
+ const r = this[field];
6835
+ const v2 = r instanceof Date ? r.getTime() / 1e3 : r;
6836
+ const s = " " + (field === "dev" || field === "ino" || field === "nlink" ? "SCHILY." : "") + field + "=" + v2 + "\n";
6837
+ const byteLen = Buffer.byteLength(s);
6838
+ let digits = Math.floor(Math.log(byteLen) / Math.log(10)) + 1;
6839
+ if (byteLen + digits >= Math.pow(10, digits)) {
6840
+ digits += 1;
6841
+ }
6842
+ const len = digits + byteLen;
6843
+ return len + s;
6844
+ }
6845
+ static parse(str, ex, g = false) {
6846
+ return new _Pax(merge(parseKV(str), ex), g);
6847
+ }
6848
+ };
6849
+ var merge = (a, b) => b ? Object.assign({}, b, a) : a;
6850
+ var parseKV = (str) => str.replace(/\n$/, "").split("\n").reduce(parseKVLine, /* @__PURE__ */ Object.create(null));
6851
+ var parseKVLine = (set, line) => {
6852
+ const n7 = parseInt(line, 10);
6853
+ if (n7 !== Buffer.byteLength(line) + 1) {
6854
+ return set;
6855
+ }
6856
+ line = line.slice((n7 + " ").length);
6857
+ const kv = line.split("=");
6858
+ const r = kv.shift();
6859
+ if (!r) {
6860
+ return set;
6861
+ }
6862
+ const k3 = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1");
6863
+ const v2 = kv.join("=").replace(/\0.*/, "");
6864
+ switch (k3) {
6865
+ case "path":
6866
+ case "linkpath":
6867
+ case "type":
6868
+ case "charset":
6869
+ case "comment":
6870
+ case "gname":
6871
+ case "uname":
6872
+ set[k3] = v2;
6873
+ break;
6874
+ case "ctime":
6875
+ case "atime":
6876
+ case "mtime":
6877
+ set[k3] = new Date(Number(v2) * 1e3);
6878
+ break;
6879
+ case "size":
6880
+ const s = +v2;
6881
+ if (s >= 0)
6882
+ set[k3] = s;
6883
+ break;
6884
+ case "gid":
6885
+ case "uid":
6886
+ case "dev":
6887
+ case "ino":
6888
+ case "nlink":
6889
+ case "mode":
6890
+ set[k3] = +v2;
6891
+ break;
6892
+ }
6893
+ return set;
6894
+ };
6895
+
6896
+ // ../../src/tar/src/unpack.ts
6897
+ import {
6898
+ brotliDecompress as brotliCB,
6899
+ brotliDecompressSync as brotliSyncCB,
6900
+ unzip as unzipCB,
6901
+ unzipSync as unzipSyncCB
6902
+ } from "node:zlib";
6903
+
6904
+ // ../../src/tar/src/find-tar-dir.ts
6905
+ var findTarDir = (path, tarDir) => {
6906
+ if (tarDir !== void 0) return tarDir;
6907
+ if (!path) return void 0;
6908
+ const i = path.indexOf("/", path.startsWith("./") ? 2 : 0);
6909
+ if (i === -1) return void 0;
6910
+ const chomp = path.substring(0, i);
6911
+ if (chomp === "." || chomp === ".." || chomp === "" || chomp === "./." || chomp === "./.." || chomp === "./") {
6912
+ return void 0;
6913
+ }
6914
+ return chomp + "/";
6915
+ };
6916
+
6917
+ // ../../src/tar/src/unpack.ts
4549
6918
  var MAX_DECOMPRESSION_RATIO = 1e3;
4550
6919
  var defaultMaxUnpackedBytes = 2 * 1024 * 1024 * 1024;
4551
6920
  var parseMaxUnpackedBytes = (raw) => {
@@ -4555,12 +6924,405 @@ var parseMaxUnpackedBytes = (raw) => {
4555
6924
  var maxUnpackedBytes = parseMaxUnpackedBytes(
4556
6925
  process.env.VLT_TAR_MAX_UNPACKED_BYTES
4557
6926
  );
6927
+ var unzipMax = (len) => Math.min(maxUnpackedBytes, len * MAX_DECOMPRESSION_RATIO);
6928
+ var unzipError = (er, found, max) => er.code === "ERR_BUFFER_TOO_LARGE" ? error("tarball exceeds maximum unpacked size", {
6929
+ found,
6930
+ max,
6931
+ cause: er
6932
+ }) : er;
6933
+ var unzipSync = (input) => {
6934
+ const max = unzipMax(input.length);
6935
+ try {
6936
+ return unzipSyncCB(input, { maxOutputLength: max });
6937
+ } catch (er) {
6938
+ throw unzipError(er, input.length, max);
6939
+ }
6940
+ };
6941
+ var isGzip = (b) => b[0] === 31 && b[1] === 139;
6942
+ var brotliSync = (input) => {
6943
+ const max = unzipMax(input.length);
6944
+ try {
6945
+ return brotliSyncCB(input, { maxOutputLength: max });
6946
+ } catch (er) {
6947
+ throw unzipError(er, input.length, max);
6948
+ }
6949
+ };
6950
+ var decompressSync = (input, format) => format === "brotli" ? brotliSync(input) : isGzip(input) ? unzipSync(input) : input;
6951
+ var tmp = randomBytes2(6).toString("hex") + ".";
6952
+ var foldKeys = process.platform === "darwin" || process.platform === "win32";
6953
+ var entryKey = (p) => foldKeys ? p.toLowerCase() : p;
6954
+ var parseWriteLanes = (raw) => {
6955
+ const n7 = Number(raw);
6956
+ return Number.isFinite(n7) && n7 >= 1 ? Math.floor(n7) : 64;
6957
+ };
6958
+ var writeLaneLimit = parseWriteLanes(
6959
+ process.env.VLT_TAR_WRITE_LANES
6960
+ );
6961
+ var isClearlySafeRelPath = (sub) => {
6962
+ const len = sub.length;
6963
+ if (len === 0) return true;
6964
+ if (sub.charCodeAt(0) === 47) return false;
6965
+ if (len >= 2 && sub.charCodeAt(1) === 58) {
6966
+ const c = sub.charCodeAt(0);
6967
+ if (c >= 65 && c <= 90 || c >= 97 && c <= 122) {
6968
+ return false;
6969
+ }
6970
+ }
6971
+ let i = 0;
6972
+ while (i < len) {
6973
+ let j3 = i;
6974
+ while (j3 < len && sub.charCodeAt(j3) !== 47) j3++;
6975
+ const slen = j3 - i;
6976
+ if (slen === 1 && sub.charCodeAt(i) === 46) return false;
6977
+ if (slen === 2 && sub.charCodeAt(i) === 46 && sub.charCodeAt(i + 1) === 46) {
6978
+ return false;
6979
+ }
6980
+ i = j3 + 1;
6981
+ }
6982
+ return true;
6983
+ };
6984
+ var checkFs = (h, tarDir, target) => {
6985
+ if (!h.path) return false;
6986
+ if (!tarDir) return false;
6987
+ h.path = h.path.replace(/[\\/]+/g, "/");
6988
+ if (!h.path.startsWith(tarDir)) return false;
6989
+ const sub = h.path.slice(tarDir.length);
6990
+ if (isClearlySafeRelPath(sub)) return true;
6991
+ const rel = relative(target, resolve7(target, sub));
6992
+ if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
6993
+ return false;
6994
+ }
6995
+ return true;
6996
+ };
6997
+ var parseTarball = (buffer, tmp2) => {
6998
+ if (isGzip(buffer)) {
6999
+ throw error("still gzipped after unzipping", {
7000
+ found: true,
7001
+ wanted: false
7002
+ });
7003
+ }
7004
+ if (buffer.length % 512 !== 0) {
7005
+ throw error("Invalid tarball: length not divisible by 512", {
7006
+ found: buffer.length
7007
+ });
7008
+ }
7009
+ if (buffer.length < 1024) {
7010
+ throw error(
7011
+ "Invalid tarball: not terminated by 1024 null bytes",
7012
+ {
7013
+ found: buffer.length
7014
+ }
7015
+ );
7016
+ }
7017
+ for (let i = buffer.length - 1024; i < buffer.length; i++) {
7018
+ if (buffer[i] !== 0) {
7019
+ throw error(
7020
+ "Invalid tarball: not terminated by 1024 null bytes",
7021
+ { found: buffer.subarray(i, i + 10) }
7022
+ );
7023
+ }
7024
+ }
7025
+ const entries = /* @__PURE__ */ new Map();
7026
+ let tarDir = void 0;
7027
+ let offset = 0;
7028
+ let h;
7029
+ let ex = void 0;
7030
+ let gex = void 0;
7031
+ while (offset < buffer.length && !(h = new Header(buffer, offset, ex, gex)).nullBlock) {
7032
+ offset += 512;
7033
+ ex = void 0;
7034
+ gex = void 0;
7035
+ const size = h.size ?? 0;
7036
+ const body = buffer.subarray(offset, offset + size);
7037
+ if (!h.cksumValid) continue;
7038
+ offset += 512 * Math.ceil(size / 512);
7039
+ switch (h.type) {
7040
+ case "File":
7041
+ if (!tarDir) tarDir = findTarDir(h.path, tarDir);
7042
+ if (!tarDir) continue;
7043
+ if (!checkFs(h, tarDir, tmp2)) continue;
7044
+ {
7045
+ const dest = resolve7(tmp2, h.path.substring(tarDir.length));
7046
+ const key = entryKey(dest);
7047
+ if (entries.get(key)?.dir === true) {
7048
+ throw error("file/directory collision in tarball", {
7049
+ path: dest
7050
+ });
7051
+ }
7052
+ entries.set(key, {
7053
+ path: dest,
7054
+ body,
7055
+ executable: 1 === ((h.mode ?? 1638) & 1),
7056
+ dir: false
7057
+ });
7058
+ }
7059
+ break;
7060
+ case "Directory":
7061
+ if (!tarDir) tarDir = findTarDir(h.path, tarDir);
7062
+ if (!tarDir) continue;
7063
+ if (!checkFs(h, tarDir, tmp2)) continue;
7064
+ {
7065
+ const dest = resolve7(tmp2, h.path.substring(tarDir.length));
7066
+ const key = entryKey(dest);
7067
+ if (entries.get(key)?.dir === false) {
7068
+ throw error("file/directory collision in tarball", {
7069
+ path: dest
7070
+ });
7071
+ }
7072
+ entries.set(key, {
7073
+ path: dest,
7074
+ dir: true
7075
+ });
7076
+ }
7077
+ break;
7078
+ case "GlobalExtendedHeader":
7079
+ gex = Pax.parse(body.toString(), gex, true);
7080
+ break;
7081
+ case "ExtendedHeader":
7082
+ case "OldExtendedHeader":
7083
+ ex = Pax.parse(body.toString(), ex, false);
7084
+ break;
7085
+ case "NextFileHasLongPath":
7086
+ case "OldGnuLongPath":
7087
+ ex ??= /* @__PURE__ */ Object.create(null);
7088
+ ex.path = body.toString().replace(/\0.*/, "");
7089
+ break;
7090
+ }
7091
+ }
7092
+ const dirs = /* @__PURE__ */ new Set();
7093
+ const files = [];
7094
+ for (const e of entries.values()) {
7095
+ if (e.dir) dirs.add(e.path);
7096
+ else {
7097
+ dirs.add(dirname2(e.path));
7098
+ files.push(e);
7099
+ }
7100
+ }
7101
+ return { dirs, files };
7102
+ };
7103
+ var storeLayout = (tarData, dir, format) => {
7104
+ const { dirs, files } = parseTarball(
7105
+ decompressSync(tarData, format),
7106
+ dir
7107
+ );
7108
+ const rel = (p) => relative(dir, p).replace(/\\/g, "/");
7109
+ const list = files.map((f) => [rel(f.path), f]);
7110
+ const pj = list.find(([p]) => p === "package.json")?.[1];
7111
+ if (!pj) throw error("no package.json in tarball", { path: dir });
7112
+ const manifest = storeIndexManifest(
7113
+ pj.body,
7114
+ list.some(([p]) => p === "binding.gyp")
7115
+ );
7116
+ const bins = new Set(
7117
+ Object.values(manifest.bins ?? {}).map(entryKey)
7118
+ );
7119
+ const indexFiles = [];
7120
+ const binFiles = [];
7121
+ for (const [p, f] of list) {
7122
+ if (bins.has(entryKey(p))) {
7123
+ f.executable = true;
7124
+ binFiles.push(f.path);
7125
+ }
7126
+ indexFiles.push([p, f.body.length, f.executable ? 1 : 0]);
7127
+ }
7128
+ const allDirs = /* @__PURE__ */ new Set();
7129
+ for (const d3 of dirs) {
7130
+ for (let p = rel(d3); p && !allDirs.has(p); ) {
7131
+ allDirs.add(p);
7132
+ p = p.slice(0, Math.max(0, p.lastIndexOf("/")));
7133
+ }
7134
+ }
7135
+ const indexDirs = [...allDirs].sort().sort((a, b) => a.length - b.length);
7136
+ return {
7137
+ index: {
7138
+ v: 1,
7139
+ files: indexFiles.sort((a, b) => a[0] < b[0] ? -1 : 1),
7140
+ dirs: indexDirs,
7141
+ ...manifest
7142
+ },
7143
+ files,
7144
+ binFiles
7145
+ };
7146
+ };
7147
+ var unpackToStoreSync = (tarData, dir, format) => {
7148
+ const { index, files, binFiles } = storeLayout(tarData, dir, format);
7149
+ mkdirSync2(dirname2(dir), { recursive: true });
7150
+ mkdirSync2(dir, { mode: 511 });
7151
+ let succeeded = false;
7152
+ try {
7153
+ for (const d3 of index.dirs) {
7154
+ mkdirSync2(join(dir, d3), { recursive: true, mode: 511 });
7155
+ }
7156
+ for (const f of files) {
7157
+ writeFileSync(f.path, f.body, {
7158
+ mode: f.executable ? 511 : 438
7159
+ });
7160
+ }
7161
+ let binMode = 0;
7162
+ for (const p of binFiles) {
7163
+ binMode ||= statSync2(p).mode & 511 | 73;
7164
+ chmodSync2(p, binMode);
7165
+ }
7166
+ succeeded = true;
7167
+ } finally {
7168
+ if (!succeeded) rimrafSync(dir);
7169
+ }
7170
+ return { index };
7171
+ };
7172
+
7173
+ // ../../src/cache-unzip/src/explode.ts
7174
+ import {
7175
+ lstatSync as lstatSync3,
7176
+ readdirSync as readdirSync2,
7177
+ renameSync as renameSync3,
7178
+ rmSync as rmSync2,
7179
+ writeFileSync as writeFileSync2
7180
+ } from "node:fs";
7181
+ import { join as join2 } from "node:path";
7182
+ import { performance as performance2 } from "node:perf_hooks";
7183
+ import { debuglog as debuglog3 } from "node:util";
7184
+ var debug3 = debuglog3("vlt");
7185
+ var linkers = /* @__PURE__ */ new Set(["auto", "hardlink", "copy"]);
7186
+ var storeEnabled = () => linkers.has(process.env.VLT_STORE_LINKER ?? "");
7187
+ var STALE_MS = 60 * 60 * 1e3;
7188
+ var parseConcurrency = (raw) => {
7189
+ const n7 = Number(raw);
7190
+ return Number.isFinite(n7) && n7 >= 1 ? Math.floor(n7) : 1;
7191
+ };
7192
+ var rm2 = (path) => rmSync2(path, { recursive: true, force: true });
7193
+ var entryIntegrity = (buf) => {
7194
+ const headSize = buf.readUInt32BE(0);
7195
+ let key;
7196
+ for (let i = 7, size = 4; i + 4 <= headSize; i += size) {
7197
+ size = Math.max(4, buf.readUInt32BE(i));
7198
+ const h = buf.toString("utf8", i + 4, i + size);
7199
+ if (key === void 0) key = h.toLowerCase();
7200
+ else if (key === "integrity") return h;
7201
+ else key = void 0;
7202
+ }
7203
+ };
7204
+ var sweep = (tmp2) => {
7205
+ let names;
7206
+ try {
7207
+ names = readdirSync2(tmp2);
7208
+ } catch {
7209
+ return;
7210
+ }
7211
+ const now = Date.now();
7212
+ for (const name2 of names) {
7213
+ const p = join2(tmp2, name2);
7214
+ try {
7215
+ if (now - lstatSync3(p).mtimeMs > STALE_MS) rm2(p);
7216
+ } catch {
7217
+ }
7218
+ }
7219
+ };
7220
+ var seq = 0;
7221
+ var explodeEntry = (store, buf, format) => {
7222
+ const hex = integrityHex(entryIntegrity(buf));
7223
+ if (!hex) return "ignored";
7224
+ const entry = join2(store, hex);
7225
+ if (lstatSync3(entry, { throwIfNoEntry: false })) {
7226
+ if (readStoreIndex(entry)) return "skipped";
7227
+ rm2(entry);
7228
+ }
7229
+ const n7 = `${process.pid}.${seq++}`;
7230
+ const tmp2 = join2(store, ".tmp", `${hex}.${n7}`);
7231
+ const sideTmp = join2(store, ".tmp", `${hex}.json.${n7}`);
7232
+ const { index } = unpackToStoreSync(
7233
+ buf.subarray(buf.readUInt32BE(0)),
7234
+ tmp2,
7235
+ format
7236
+ );
7237
+ try {
7238
+ writeFileSync2(sideTmp, JSON.stringify(index));
7239
+ renameSync3(sideTmp, storeIndexPath(entry));
7240
+ renameSync3(tmp2, entry);
7241
+ } catch (er) {
7242
+ rm2(tmp2);
7243
+ rm2(sideTmp);
7244
+ if (lstatSync3(entry, { throwIfNoEntry: false })) return "skipped";
7245
+ throw er;
7246
+ }
7247
+ let bytes = 0;
7248
+ for (const [, size] of index.files) bytes += size;
7249
+ return bytes;
7250
+ };
7251
+ var explode = async (cache, store, keys, integrities) => {
7252
+ if (!storeEnabled()) return;
7253
+ const start = performance2.now();
7254
+ const s = {
7255
+ exploded: /* @__PURE__ */ new Set(),
7256
+ written: 0,
7257
+ skipped: 0,
7258
+ ignored: 0,
7259
+ failed: 0,
7260
+ bytes: 0,
7261
+ ms: 0
7262
+ };
7263
+ sweep(join2(store, ".tmp"));
7264
+ let next = 0;
7265
+ const lane = async () => {
7266
+ for (; ; ) {
7267
+ const key = keys[next++];
7268
+ if (key === void 0) return;
7269
+ const buf = await cache.fetch(key, {
7270
+ context: { integrity: integrities?.get(key) }
7271
+ });
7272
+ cache.delete(key);
7273
+ if (!buf) {
7274
+ s.ignored++;
7275
+ continue;
7276
+ }
7277
+ try {
7278
+ const res = explodeEntry(store, buf, tarballFormat(key));
7279
+ if (typeof res === "number") {
7280
+ s.exploded.add(key);
7281
+ s.written++;
7282
+ s.bytes += res;
7283
+ } else s[res]++;
7284
+ } catch (er) {
7285
+ s.failed++;
7286
+ debug3("global store: explode failed", key, er);
7287
+ }
7288
+ }
7289
+ };
7290
+ const lanes = Math.min(
7291
+ parseConcurrency(process.env.VLT_CACHE_EXPLODE_CONCURRENCY),
7292
+ keys.length
7293
+ );
7294
+ await Promise.all(Array.from({ length: lanes }, lane));
7295
+ s.ms = Math.round(performance2.now() - start);
7296
+ debug3(
7297
+ "global store: explode written=%d skipped=%d ignored=%d failed=%d bytes=%d ms=%d",
7298
+ s.written,
7299
+ s.skipped,
7300
+ s.ignored,
7301
+ s.failed,
7302
+ s.bytes,
7303
+ s.ms
7304
+ );
7305
+ return s;
7306
+ };
7307
+
7308
+ // ../../src/cache-unzip/src/unzip.ts
7309
+ var __CODE_SPLIT_SCRIPT_NAME = import.meta.filename;
7310
+ var debug4 = debuglog4("vlt");
7311
+ var MAX_DECOMPRESSION_RATIO2 = 1e3;
7312
+ var defaultMaxUnpackedBytes2 = 2 * 1024 * 1024 * 1024;
7313
+ var parseMaxUnpackedBytes2 = (raw) => {
7314
+ const n7 = Number(raw);
7315
+ return Number.isFinite(n7) && n7 >= 1 ? Math.floor(n7) : defaultMaxUnpackedBytes2;
7316
+ };
7317
+ var maxUnpackedBytes2 = parseMaxUnpackedBytes2(
7318
+ process.env.VLT_TAR_MAX_UNPACKED_BYTES
7319
+ );
4558
7320
  var isMain = (path) => path === __CODE_SPLIT_SCRIPT_NAME || path === pathToFileURL(__CODE_SPLIT_SCRIPT_NAME).toString();
4559
- var main = async (path, input = process.stdin) => {
7321
+ var main = async (path, input = process.stdin, store) => {
4560
7322
  if (!path) {
4561
7323
  return false;
4562
7324
  }
4563
- const keys = await new Promise((res) => {
7325
+ const items = await new Promise((res) => {
4564
7326
  const chunks = [];
4565
7327
  let chunkLen = 0;
4566
7328
  input.on("data", (chunk) => {
@@ -4573,142 +7335,169 @@ var main = async (path, input = process.stdin) => {
4573
7335
  );
4574
7336
  });
4575
7337
  });
7338
+ const integrities = /* @__PURE__ */ new Map();
7339
+ const keys = items.map((item) => {
7340
+ const [key, integrity] = item.split(" ");
7341
+ if (integrity) integrities.set(key, integrity);
7342
+ return key;
7343
+ });
4576
7344
  if (!keys.length) {
4577
- return false;
7345
+ return true;
4578
7346
  }
4579
7347
  const cache = new Cache({ path });
4580
- const readSize = (buf, offset) => {
4581
- const a = buf[offset];
4582
- const b = buf[offset + 1];
4583
- const c = buf[offset + 2];
4584
- const d3 = buf[offset + 3];
4585
- if (a === void 0 || b === void 0 || c === void 0 || d3 === void 0) {
4586
- throw error("Invalid buffer, not long enough to readSize", {
4587
- found: buf,
4588
- offset
4589
- });
7348
+ const mode = process.env.VLT_CACHE_UNZIP;
7349
+ const unzip = async (ks2) => mode === "0" ? [] : Promise.allSettled(
7350
+ ks2.map((k3) => unzipEntry(cache, k3, integrities.get(k3)))
7351
+ );
7352
+ const all = mode === "1" ? await unzip(keys) : void 0;
7353
+ const s = store ? await explode(cache, store, keys, integrities) : void 0;
7354
+ const results = all ?? await unzip(keys.filter((k3) => !s?.exploded.has(k3)));
7355
+ await cache.promise();
7356
+ let unzipped = 0;
7357
+ let rejected;
7358
+ for (const r of results) {
7359
+ if (r.status === "rejected") rejected ??= r;
7360
+ else if (r.value) unzipped++;
7361
+ }
7362
+ debug4(
7363
+ "cache-unzip: keys=%d exploded=%d unzipped=%d",
7364
+ keys.length,
7365
+ s?.written ?? 0,
7366
+ unzipped
7367
+ );
7368
+ if (rejected) throw rejected.reason;
7369
+ return !s?.failed;
7370
+ };
7371
+ var readSize = (buf, offset) => {
7372
+ const a = buf[offset];
7373
+ const b = buf[offset + 1];
7374
+ const c = buf[offset + 2];
7375
+ const d3 = buf[offset + 3];
7376
+ if (a === void 0 || b === void 0 || c === void 0 || d3 === void 0) {
7377
+ throw error("Invalid buffer, not long enough to readSize", {
7378
+ found: buf,
7379
+ offset
7380
+ });
7381
+ }
7382
+ return a << 24 | b << 16 | c << 8 | d3;
7383
+ };
7384
+ var unzipEntry = async (cache, key, under) => {
7385
+ const buffer = await cache.fetch(key, {
7386
+ context: { integrity: under }
7387
+ });
7388
+ if (!buffer || buffer.length < 4) return false;
7389
+ const headSizeOriginal = readSize(buffer, 0);
7390
+ const body = buffer.subarray(headSizeOriginal);
7391
+ if (body[0] !== 31 || body[1] !== 139) return false;
7392
+ let unz;
7393
+ try {
7394
+ unz = gunzipSync(body, {
7395
+ maxOutputLength: Math.min(
7396
+ maxUnpackedBytes2,
7397
+ body.length * MAX_DECOMPRESSION_RATIO2
7398
+ )
7399
+ });
7400
+ } catch (er) {
7401
+ if (er.code !== "ERR_BUFFER_TOO_LARGE") {
7402
+ throw er;
4590
7403
  }
4591
- return a << 24 | b << 16 | c << 8 | d3;
4592
- };
4593
- const results = await Promise.all(
4594
- keys.map(async (key) => {
4595
- const buffer = await cache.fetch(key);
4596
- if (!buffer || buffer.length < 4) return null;
4597
- const headSizeOriginal = readSize(buffer, 0);
4598
- const body = buffer.subarray(headSizeOriginal);
4599
- if (body[0] === 31 && body[1] === 139) {
4600
- let unz;
4601
- try {
4602
- unz = gunzipSync(body, {
4603
- maxOutputLength: Math.min(
4604
- maxUnpackedBytes,
4605
- body.length * MAX_DECOMPRESSION_RATIO
4606
- )
4607
- });
4608
- } catch (er) {
4609
- if (er.code !== "ERR_BUFFER_TOO_LARGE") {
4610
- throw er;
4611
- }
4612
- return null;
4613
- }
4614
- const headersBuffer = buffer.subarray(7, headSizeOriginal);
4615
- const headers = [];
4616
- let i = 0;
4617
- let sawEncoding = false;
4618
- let isEncoding = false;
4619
- let isContentLength = false;
4620
- let isIntegrity = false;
4621
- let integrity = void 0;
4622
- while (i < headersBuffer.length - 4) {
4623
- const size = readSize(headersBuffer, i);
4624
- const h = headersBuffer.subarray(i + 4, i + size);
4625
- if (isEncoding) {
4626
- isEncoding = false;
4627
- headers.push(Buffer.from("identity"));
4628
- } else if (isContentLength) {
4629
- isContentLength = false;
4630
- i += size;
4631
- continue;
4632
- } else if (isIntegrity) {
4633
- isIntegrity = false;
4634
- integrity = h.toString();
4635
- headers.push(h);
4636
- } else {
4637
- if (headers.length % 2 === 0) {
4638
- if (h.toString().toLowerCase() === "content-length") {
4639
- isContentLength = true;
4640
- i += size;
4641
- continue;
4642
- }
4643
- if (!sawEncoding && h.toString().toLowerCase() === "content-encoding") {
4644
- sawEncoding = true;
4645
- isEncoding = true;
4646
- } else if (!integrity && h.toString().toLowerCase() === "integrity") {
4647
- isIntegrity = true;
4648
- }
4649
- }
4650
- headers.push(h);
4651
- }
7404
+ return false;
7405
+ }
7406
+ const headersBuffer = buffer.subarray(7, headSizeOriginal);
7407
+ const headers = [];
7408
+ let i = 0;
7409
+ let sawEncoding = false;
7410
+ let isEncoding = false;
7411
+ let isContentLength = false;
7412
+ let isIntegrity2 = false;
7413
+ let integrity = void 0;
7414
+ while (i < headersBuffer.length - 4) {
7415
+ const size = readSize(headersBuffer, i);
7416
+ const h = headersBuffer.subarray(i + 4, i + size);
7417
+ if (isEncoding) {
7418
+ isEncoding = false;
7419
+ headers.push(Buffer.from("identity"));
7420
+ } else if (isContentLength) {
7421
+ isContentLength = false;
7422
+ i += size;
7423
+ continue;
7424
+ } else if (isIntegrity2) {
7425
+ isIntegrity2 = false;
7426
+ integrity = h.toString();
7427
+ headers.push(h);
7428
+ } else {
7429
+ if (headers.length % 2 === 0) {
7430
+ if (h.toString().toLowerCase() === "content-length") {
7431
+ isContentLength = true;
4652
7432
  i += size;
7433
+ continue;
4653
7434
  }
4654
- if (!sawEncoding) {
4655
- headers.push(
4656
- Buffer.from("content-encoding"),
4657
- Buffer.from("identity")
4658
- );
4659
- }
4660
- headers.push(
4661
- Buffer.from("content-length"),
4662
- Buffer.from(String(unz.byteLength))
4663
- );
4664
- const sb = buffer.subarray(4, 7);
4665
- const chunks = [sb];
4666
- let headLength = sb.byteLength + 4;
4667
- for (const h of headers) {
4668
- const hlBuf2 = Buffer.allocUnsafe(4);
4669
- const hl = h.byteLength + 4;
4670
- headLength += hl;
4671
- hlBuf2.set(
4672
- [
4673
- hl >> 24 & 255,
4674
- hl >> 16 & 255,
4675
- hl >> 8 & 255,
4676
- hl & 255
4677
- ],
4678
- 0
4679
- );
4680
- chunks.push(hlBuf2, h);
7435
+ if (!sawEncoding && h.toString().toLowerCase() === "content-encoding") {
7436
+ sawEncoding = true;
7437
+ isEncoding = true;
7438
+ } else if (!integrity && h.toString().toLowerCase() === "integrity") {
7439
+ isIntegrity2 = true;
4681
7440
  }
4682
- const hlBuf = Buffer.allocUnsafe(4);
4683
- hlBuf.set(
4684
- [
4685
- headLength >> 24 & 255,
4686
- headLength >> 16 & 255,
4687
- headLength >> 8 & 255,
4688
- headLength & 255
4689
- ],
4690
- 0
4691
- );
4692
- chunks.unshift(hlBuf);
4693
- chunks.push(unz);
4694
- cache.set(
4695
- key,
4696
- Buffer.concat(chunks, headLength + unz.length),
4697
- {
4698
- integrity
4699
- }
4700
- );
4701
7441
  }
4702
- return true;
4703
- })
7442
+ headers.push(h);
7443
+ }
7444
+ i += size;
7445
+ }
7446
+ if (!sawEncoding) {
7447
+ headers.push(
7448
+ Buffer.from("content-encoding"),
7449
+ Buffer.from("identity")
7450
+ );
7451
+ }
7452
+ headers.push(
7453
+ Buffer.from("content-length"),
7454
+ Buffer.from(String(unz.byteLength))
4704
7455
  );
4705
- await cache.promise();
4706
- return results.some(Boolean);
7456
+ const sb = buffer.subarray(4, 7);
7457
+ const chunks = [sb];
7458
+ let headLength = sb.byteLength + 4;
7459
+ for (const h of headers) {
7460
+ const hlBuf2 = Buffer.allocUnsafe(4);
7461
+ const hl = h.byteLength + 4;
7462
+ headLength += hl;
7463
+ hlBuf2.set(
7464
+ [
7465
+ hl >> 24 & 255,
7466
+ hl >> 16 & 255,
7467
+ hl >> 8 & 255,
7468
+ hl & 255
7469
+ ],
7470
+ 0
7471
+ );
7472
+ chunks.push(hlBuf2, h);
7473
+ }
7474
+ const hlBuf = Buffer.allocUnsafe(4);
7475
+ hlBuf.set(
7476
+ [
7477
+ headLength >> 24 & 255,
7478
+ headLength >> 16 & 255,
7479
+ headLength >> 8 & 255,
7480
+ headLength & 255
7481
+ ],
7482
+ 0
7483
+ );
7484
+ chunks.unshift(hlBuf);
7485
+ chunks.push(unz);
7486
+ cache.set(key, Buffer.concat(chunks, headLength + unz.length), {
7487
+ integrity
7488
+ });
7489
+ return true;
4707
7490
  };
4708
7491
  if (isMain(process.argv[1])) {
4709
7492
  process.title = "vlt-cache-unzip";
4710
- const path = process.argv.length === 2 ? void 0 : process.argv.at(-1);
4711
- const res = await main(path, process.stdin);
7493
+ const [, , path, store] = process.argv;
7494
+ if (store && storeEnabled()) {
7495
+ try {
7496
+ setPriority(19);
7497
+ } catch {
7498
+ }
7499
+ }
7500
+ const res = await main(path, process.stdin, store);
4712
7501
  if (!res) {
4713
7502
  process.exit(1);
4714
7503
  }