@vltpkg/cli-js 1.0.1 → 1.0.3

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 (83) hide show
  1. package/{access-SXQICNAN.js → access-5WETTBDZ.js} +9 -7
  2. package/{bugs-OOPMFRCI.js → bugs-KONFLIQQ.js} +19 -18
  3. package/{build-HDXI5OA7.js → build-S7G2DU7I.js} +12 -10
  4. package/{cache-RW4Y4XNQ.js → cache-Z4OIMLXQ.js} +23 -21
  5. package/{chunk-RXNA2XCX.js → chunk-4KCU2KZL.js} +8 -1
  6. package/{chunk-F2FKLPZD.js → chunk-5B23EKN4.js} +4 -4
  7. package/{chunk-4ZXA6RLP.js → chunk-5QJEOGEM.js} +3 -1
  8. package/{chunk-CCQYIYTA.js → chunk-5UPPEUG2.js} +11 -11
  9. package/chunk-BJBFEQRR.js +667 -0
  10. package/{chunk-MU7Y4R5E.js → chunk-DYCF76WI.js} +4 -4
  11. package/{chunk-EHEVBLDB.js → chunk-E737X73P.js} +38 -24
  12. package/{chunk-ICJRCXSG.js → chunk-FFOXTPQA.js} +12 -9
  13. package/chunk-G7UPIJAP.js +903 -0
  14. package/{chunk-CNSTFT7U.js → chunk-HAYXR3MW.js} +1 -1
  15. package/{chunk-U6DM3ROE.js → chunk-HNCE3YE5.js} +1649 -1569
  16. package/{chunk-2PLIV3N3.js → chunk-IITIX4ID.js} +740 -6
  17. package/chunk-LPIBYUMT.js +854 -0
  18. package/{chunk-E5YE7UTZ.js → chunk-LZGKX7JI.js} +114 -50
  19. package/{chunk-3SQ5Y324.js → chunk-NXEH3NQZ.js} +11 -13
  20. package/{chunk-MT76WHSM.js → chunk-OCJDISSI.js} +12 -6
  21. package/chunk-RNJSI3NZ.js +75 -0
  22. package/{chunk-FAG776ZD.js → chunk-T4GYDWUJ.js} +1 -1
  23. package/{chunk-VM2RMMY4.js → chunk-TMBNGWXK.js} +3 -3
  24. package/{chunk-EQ633HIM.js → chunk-UAAZW4N6.js} +4 -4
  25. package/{chunk-D5CP6O6G.js → chunk-UXIRAU5T.js} +4 -4
  26. package/{chunk-EFWPI6IY.js → chunk-VB3IWNHX.js} +1 -1
  27. package/chunk-VE6CCH33.js +3000 -0
  28. package/{chunk-UCD3RJYG.js → chunk-W2Q5EIMH.js} +8 -8
  29. package/{chunk-VZ7UNZHR.js → chunk-XQSBCMSC.js} +5 -5
  30. package/{reporter-2XBYWAVU.js → chunk-XU5SMHXP.js} +35 -10
  31. package/{ci-MTYU2K2A.js → ci-RZZE375O.js} +17 -16
  32. package/cli-package.json +1 -1
  33. package/{config-TVAXCTQO.js → config-LL3RLMZG.js} +9 -12
  34. package/{config-6NXV2BXW.js → config-MDFY3ORD.js} +15 -18
  35. package/{create-LXI5DCDW.js → create-GVSDTOGQ.js} +23 -23
  36. package/{deprecate-2AQBL5XT.js → deprecate-T4TQLGXQ.js} +16 -14
  37. package/{dist-tag-BFSYLRIH.js → dist-tag-GO46UQUN.js} +11 -9
  38. package/{docs-ADPJ4B4C.js → docs-FJME563T.js} +19 -18
  39. package/{exec-GMS54RAC.js → exec-M22KBPCK.js} +23 -23
  40. package/{exec-cache-R5LVZL5Z.js → exec-cache-3UNLDUAP.js} +22 -22
  41. package/{exec-local-TVCLZGIM.js → exec-local-YHVO5RLU.js} +20 -18
  42. package/{help-6CECUD6C.js → help-ZEWMLOJX.js} +3 -3
  43. package/{init-XXFLGYVP.js → init-4HPZY2KN.js} +12 -10
  44. package/{install-6KMXYSF5.js → install-2TZIP4PJ.js} +18 -17
  45. package/{list-RUO3SUKY.js → list-NFFXER43.js} +20 -18
  46. package/{login-6I2CGO7I.js → login-KV5YC5Z2.js} +9 -7
  47. package/{logout-JTU4BJKH.js → logout-I2VT3NAR.js} +9 -7
  48. package/{pack-NCWH2TUA.js → pack-47ZKFSHI.js} +16 -14
  49. package/package.json +6 -6
  50. package/{ping-4MEAC2WD.js → ping-Q7Y7QV63.js} +9 -7
  51. package/{pkg-ENSKG6G7.js → pkg-VTJS2ISJ.js} +13 -11
  52. package/{profile-62YHNFSO.js → profile-YXZYVEUX.js} +9 -7
  53. package/{publish-PPY724N2.js → publish-CBN67KN2.js} +21 -19
  54. package/{query-NLWXKOOT.js → query-U3QHF3ZE.js} +20 -18
  55. package/{registry-QGI44LG4.js → registry-CZPFR3OF.js} +3 -3
  56. package/registry-client-package.json +1 -1
  57. package/registry-client-src-revalidate.js +2080 -349
  58. package/{repo-BFRAXIVU.js → repo-4UIQRBI7.js} +19 -18
  59. package/{chunk-4RZDJQ5U.js → reporter-DKZTTACW.js} +5 -5
  60. package/{run-7O65747G.js → run-5DUYI6GL.js} +20 -18
  61. package/{run-exec-2OYWHL6K.js → run-exec-HPNBVAXH.js} +20 -18
  62. package/security-archive-src-update-expired.js +39 -4
  63. package/{setup-MMIDAIJI.js → setup-23W5FQVW.js} +24 -15
  64. package/{src-OK3KHDYR.js → src-2NB67FPG.js} +22 -23
  65. package/src-6OKPBJJT.js +59 -0
  66. package/src-M5RRGKUM.js +913 -0
  67. package/{token-VLVXUW54.js → token-SRCS5CRU.js} +9 -7
  68. package/{uninstall-TAG6QIAG.js → uninstall-JXHAFXZ2.js} +18 -17
  69. package/{unpublish-Y4L5J2IA.js → unpublish-GRYB5KQH.js} +12 -10
  70. package/{update-RYH4RKBS.js → update-GDLL4ER6.js} +17 -16
  71. package/{version-COHB32ON.js → version-JVG4CI4L.js} +13 -11
  72. package/{view-P7U4MF43.js → view-ABQLVL4L.js} +13 -15
  73. package/vlr.js +1 -1
  74. package/vlrx.js +1 -1
  75. package/vlt.js +1 -1
  76. package/vlx.js +1 -1
  77. package/vlxl.js +1 -1
  78. package/{whoami-47MVFMZC.js → whoami-RCCZ7BXI.js} +9 -7
  79. package/chunk-7NHXV6AH.js +0 -4488
  80. package/chunk-HB7CKTYO.js +0 -75
  81. package/chunk-PW6S6AIO.js +0 -716
  82. package/chunk-WXMYKCQW.js +0 -1640
  83. package/{chunk-Y7CQIZ7Y.js → chunk-FEIPJIEN.js} +3 -3
package/chunk-WXMYKCQW.js DELETED
@@ -1,1640 +0,0 @@
1
- var global = globalThis;
2
- import {Buffer} from "node:buffer";
3
- import {setTimeout as _vlt_setTimeout,clearTimeout as _vlt_clearTimeout,setImmediate as _vlt_setImmediate,clearImmediate as _vlt_clearImmediate,setInterval as _vlt_setInterval,clearInterval as _vlt_clearInterval} from "node:timers";
4
- globalThis.setTimeout = _vlt_setTimeout;
5
- globalThis.clearTimeout = _vlt_clearTimeout;
6
- globalThis.setImmediate = _vlt_setImmediate;
7
- globalThis.clearImmediate = _vlt_clearImmediate;
8
- globalThis.setInterval = _vlt_setInterval;
9
- globalThis.clearInterval = _vlt_clearInterval;
10
- import {createRequire as _vlt_createRequire} from "node:module";
11
- var require = _vlt_createRequire(import.meta.filename);
12
- import {
13
- Qn,
14
- require_lib
15
- } from "./chunk-FWKQ7YDF.js";
16
- import {
17
- Monorepo,
18
- PackageJson,
19
- clone,
20
- pickManifest,
21
- resolve,
22
- revs
23
- } from "./chunk-ICJRCXSG.js";
24
- import {
25
- RegistryClient
26
- } from "./chunk-U6DM3ROE.js";
27
- import {
28
- rimraf
29
- } from "./chunk-7NHXV6AH.js";
30
- import {
31
- Spec2 as Spec
32
- } from "./chunk-PW6S6AIO.js";
33
- import {
34
- asError,
35
- asPackument
36
- } from "./chunk-2PLIV3N3.js";
37
- import {
38
- XDG
39
- } from "./chunk-XNLSTHDK.js";
40
- import {
41
- error
42
- } from "./chunk-WZWDS3W4.js";
43
- import {
44
- __toESM
45
- } from "./chunk-PZLD7RTK.js";
46
-
47
- // ../../src/tar/src/unpack.ts
48
- import { randomBytes } from "node:crypto";
49
- import { lstat, mkdir, rename, writeFile } from "node:fs/promises";
50
- import { basename as basename2, dirname, resolve as resolve2, sep } from "node:path";
51
-
52
- // ../../node_modules/.vlt/~npm~tar@7.5.20/node_modules/tar/dist/esm/header.js
53
- import { posix as pathModule } from "node:path";
54
-
55
- // ../../node_modules/.vlt/~npm~tar@7.5.20/node_modules/tar/dist/esm/large-numbers.js
56
- var encode = (num, buf) => {
57
- if (!Number.isSafeInteger(num)) {
58
- throw Error("cannot encode number outside of javascript safe integer range");
59
- } else if (num < 0) {
60
- encodeNegative(num, buf);
61
- } else {
62
- encodePositive(num, buf);
63
- }
64
- return buf;
65
- };
66
- var encodePositive = (num, buf) => {
67
- buf[0] = 128;
68
- for (var i = buf.length; i > 1; i--) {
69
- buf[i - 1] = num & 255;
70
- num = Math.floor(num / 256);
71
- }
72
- };
73
- var encodeNegative = (num, buf) => {
74
- buf[0] = 255;
75
- var flipped = false;
76
- num = num * -1;
77
- for (var i = buf.length; i > 1; i--) {
78
- var byte = num & 255;
79
- num = Math.floor(num / 256);
80
- if (flipped) {
81
- buf[i - 1] = onesComp(byte);
82
- } else if (byte === 0) {
83
- buf[i - 1] = 0;
84
- } else {
85
- flipped = true;
86
- buf[i - 1] = twosComp(byte);
87
- }
88
- }
89
- };
90
- var parse = (buf) => {
91
- const pre = buf[0];
92
- const value = pre === 128 ? pos(buf.subarray(1, buf.length)) : pre === 255 ? twos(buf) : null;
93
- if (value === null) {
94
- throw Error("invalid base256 encoding");
95
- }
96
- if (!Number.isSafeInteger(value)) {
97
- throw Error("parsed number outside of javascript safe integer range");
98
- }
99
- return value;
100
- };
101
- var twos = (buf) => {
102
- var len = buf.length;
103
- var sum = 0;
104
- var flipped = false;
105
- for (var i = len - 1; i > -1; i--) {
106
- var byte = Number(buf[i]);
107
- var f;
108
- if (flipped) {
109
- f = onesComp(byte);
110
- } else if (byte === 0) {
111
- f = byte;
112
- } else {
113
- flipped = true;
114
- f = twosComp(byte);
115
- }
116
- if (f !== 0) {
117
- sum -= f * Math.pow(256, len - i - 1);
118
- }
119
- }
120
- return sum;
121
- };
122
- var pos = (buf) => {
123
- var len = buf.length;
124
- var sum = 0;
125
- for (var i = len - 1; i > -1; i--) {
126
- var byte = Number(buf[i]);
127
- if (byte !== 0) {
128
- sum += byte * Math.pow(256, len - i - 1);
129
- }
130
- }
131
- return sum;
132
- };
133
- var onesComp = (byte) => (255 ^ byte) & 255;
134
- var twosComp = (byte) => (255 ^ byte) + 1 & 255;
135
-
136
- // ../../node_modules/.vlt/~npm~tar@7.5.20/node_modules/tar/dist/esm/types.js
137
- var isCode = (c) => name.has(c);
138
- var normalFsTypes = /* @__PURE__ */ new Set([
139
- "0",
140
- "",
141
- "1",
142
- "2",
143
- "3",
144
- "4",
145
- "5",
146
- "6",
147
- "7",
148
- "D"
149
- ]);
150
- var name = /* @__PURE__ */ new Map([
151
- ["0", "File"],
152
- // same as File
153
- ["", "OldFile"],
154
- ["1", "Link"],
155
- ["2", "SymbolicLink"],
156
- // Devices and FIFOs aren't fully supported
157
- // they are parsed, but skipped when unpacking
158
- ["3", "CharacterDevice"],
159
- ["4", "BlockDevice"],
160
- ["5", "Directory"],
161
- ["6", "FIFO"],
162
- // same as File
163
- ["7", "ContiguousFile"],
164
- // pax headers
165
- ["g", "GlobalExtendedHeader"],
166
- ["x", "ExtendedHeader"],
167
- // vendor-specific stuff
168
- // skip
169
- ["A", "SolarisACL"],
170
- // like 5, but with data, which should be skipped
171
- ["D", "GNUDumpDir"],
172
- // metadata only, skip
173
- ["I", "Inode"],
174
- // data = link path of next file
175
- ["K", "NextFileHasLongLinkpath"],
176
- // data = path of next file
177
- ["L", "NextFileHasLongPath"],
178
- // skip
179
- ["M", "ContinuationFile"],
180
- // like L
181
- ["N", "OldGnuLongPath"],
182
- // skip
183
- ["S", "SparseFile"],
184
- // skip
185
- ["V", "TapeVolumeHeader"],
186
- // like x
187
- ["X", "OldExtendedHeader"]
188
- ]);
189
- var code = new Map(Array.from(name).map((kv) => [kv[1], kv[0]]));
190
-
191
- // ../../node_modules/.vlt/~npm~tar@7.5.20/node_modules/tar/dist/esm/header.js
192
- var notNegative = (n) => n === void 0 || n < 0 ? void 0 : n;
193
- var Header = class {
194
- cksumValid = false;
195
- needPax = false;
196
- nullBlock = false;
197
- block;
198
- path;
199
- mode;
200
- uid;
201
- gid;
202
- size;
203
- cksum;
204
- #type = "Unsupported";
205
- linkpath;
206
- uname;
207
- gname;
208
- devmaj = 0;
209
- devmin = 0;
210
- atime;
211
- ctime;
212
- mtime;
213
- charset;
214
- comment;
215
- constructor(data, off = 0, ex, gex) {
216
- if (Buffer.isBuffer(data)) {
217
- this.decode(data, off || 0, ex, gex);
218
- } else if (data) {
219
- this.#slurp(data);
220
- }
221
- }
222
- decode(buf, off, ex, gex) {
223
- if (!off) {
224
- off = 0;
225
- }
226
- if (!buf || !(buf.length >= off + 512)) {
227
- throw new Error("need 512 bytes for header");
228
- }
229
- const t = decString(buf, off + 156, 1);
230
- const isNormalFS = normalFsTypes.has(t);
231
- const exForFields = isNormalFS ? ex : void 0;
232
- const gexForFields = isNormalFS ? gex : void 0;
233
- this.path = exForFields?.path ?? decString(buf, off, 100);
234
- this.mode = exForFields?.mode ?? gexForFields?.mode ?? decNumber(buf, off + 100, 8);
235
- this.uid = exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
236
- this.gid = exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
237
- this.size = notNegative(exForFields?.size ?? gexForFields?.size ?? decNumber(buf, off + 124, 12));
238
- this.mtime = exForFields?.mtime ?? gexForFields?.mtime ?? decDate(buf, off + 136, 12);
239
- this.cksum = decNumber(buf, off + 148, 12);
240
- if (gexForFields)
241
- this.#slurp(gexForFields, true);
242
- if (exForFields)
243
- this.#slurp(exForFields);
244
- if (isCode(t)) {
245
- this.#type = t || "0";
246
- }
247
- if (this.#type === "0" && this.path.slice(-1) === "/") {
248
- this.#type = "5";
249
- }
250
- if (this.#type === "5") {
251
- this.size = 0;
252
- }
253
- this.linkpath = decString(buf, off + 157, 100);
254
- if (buf.subarray(off + 257, off + 265).toString() === "ustar\x0000") {
255
- this.uname = exForFields?.uname ?? gexForFields?.uname ?? decString(buf, off + 265, 32);
256
- this.gname = exForFields?.gname ?? gexForFields?.gname ?? decString(buf, off + 297, 32);
257
- this.devmaj = exForFields?.devmaj ?? gexForFields?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0;
258
- this.devmin = exForFields?.devmin ?? gexForFields?.devmin ?? decNumber(buf, off + 337, 8) ?? 0;
259
- if (buf[off + 475] !== 0) {
260
- const prefix = decString(buf, off + 345, 155);
261
- this.path = prefix + "/" + this.path;
262
- } else {
263
- const prefix = decString(buf, off + 345, 130);
264
- if (prefix) {
265
- this.path = prefix + "/" + this.path;
266
- }
267
- this.atime = ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
268
- this.ctime = ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
269
- }
270
- }
271
- let sum = 8 * 32;
272
- for (let i = off; i < off + 148; i++) {
273
- sum += buf[i];
274
- }
275
- for (let i = off + 156; i < off + 512; i++) {
276
- sum += buf[i];
277
- }
278
- this.cksumValid = sum === this.cksum;
279
- if (this.cksum === void 0 && sum === 8 * 32) {
280
- this.nullBlock = true;
281
- }
282
- }
283
- #slurp(ex, gex = false) {
284
- Object.assign(this, Object.fromEntries(Object.entries(ex).filter(([k, v]) => {
285
- return !(v === null || v === void 0 || k === "size" && Number(v) < 0 || k === "path" && gex || k === "linkpath" && gex || k === "global");
286
- })));
287
- }
288
- encode(buf, off = 0) {
289
- if (!buf) {
290
- buf = this.block = Buffer.alloc(512);
291
- }
292
- if (this.#type === "Unsupported") {
293
- this.#type = "0";
294
- }
295
- if (!(buf.length >= off + 512)) {
296
- throw new Error("need 512 bytes for header");
297
- }
298
- const prefixSize = this.ctime || this.atime ? 130 : 155;
299
- const split = splitPrefix(this.path || "", prefixSize);
300
- const path = split[0];
301
- const prefix = split[1];
302
- this.needPax = !!split[2];
303
- this.needPax = encString(buf, off, 100, path) || this.needPax;
304
- this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax;
305
- this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax;
306
- this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax;
307
- this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax;
308
- this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax;
309
- buf[off + 156] = Number(this.#type.codePointAt(0));
310
- this.needPax = encString(buf, off + 157, 100, this.linkpath) || this.needPax;
311
- buf.write("ustar\x0000", off + 257, 8);
312
- this.needPax = encString(buf, off + 265, 32, this.uname) || this.needPax;
313
- this.needPax = encString(buf, off + 297, 32, this.gname) || this.needPax;
314
- this.needPax = encNumber(buf, off + 329, 8, this.devmaj) || this.needPax;
315
- this.needPax = encNumber(buf, off + 337, 8, this.devmin) || this.needPax;
316
- this.needPax = encString(buf, off + 345, prefixSize, prefix) || this.needPax;
317
- if (buf[off + 475] !== 0) {
318
- this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax;
319
- } else {
320
- this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax;
321
- this.needPax = encDate(buf, off + 476, 12, this.atime) || this.needPax;
322
- this.needPax = encDate(buf, off + 488, 12, this.ctime) || this.needPax;
323
- }
324
- let sum = 8 * 32;
325
- for (let i = off; i < off + 148; i++) {
326
- sum += buf[i];
327
- }
328
- for (let i = off + 156; i < off + 512; i++) {
329
- sum += buf[i];
330
- }
331
- this.cksum = sum;
332
- encNumber(buf, off + 148, 8, this.cksum);
333
- this.cksumValid = true;
334
- return this.needPax;
335
- }
336
- get type() {
337
- return this.#type === "Unsupported" ? this.#type : name.get(this.#type);
338
- }
339
- get typeKey() {
340
- return this.#type;
341
- }
342
- set type(type) {
343
- const c = String(code.get(type));
344
- if (isCode(c) || c === "Unsupported") {
345
- this.#type = c;
346
- } else if (isCode(type)) {
347
- this.#type = type;
348
- } else {
349
- throw new TypeError("invalid entry type: " + type);
350
- }
351
- }
352
- };
353
- var splitPrefix = (p, prefixSize) => {
354
- const pathSize = 100;
355
- let pp = p;
356
- let prefix = "";
357
- let ret = void 0;
358
- const root = pathModule.parse(p).root || ".";
359
- if (Buffer.byteLength(pp) < pathSize) {
360
- ret = [pp, prefix, false];
361
- } else {
362
- prefix = pathModule.dirname(pp);
363
- pp = pathModule.basename(pp);
364
- do {
365
- if (Buffer.byteLength(pp) <= pathSize && Buffer.byteLength(prefix) <= prefixSize) {
366
- ret = [pp, prefix, false];
367
- } else if (Buffer.byteLength(pp) > pathSize && Buffer.byteLength(prefix) <= prefixSize) {
368
- ret = [pp.slice(0, pathSize - 1), prefix, true];
369
- } else {
370
- pp = pathModule.join(pathModule.basename(prefix), pp);
371
- prefix = pathModule.dirname(prefix);
372
- }
373
- } while (prefix !== root && ret === void 0);
374
- if (!ret) {
375
- ret = [p.slice(0, pathSize - 1), "", true];
376
- }
377
- }
378
- return ret;
379
- };
380
- var decString = (buf, off, size) => buf.subarray(off, off + size).toString("utf8").replace(/\0.*/, "");
381
- var decDate = (buf, off, size) => numToDate(decNumber(buf, off, size));
382
- var numToDate = (num) => num === void 0 ? void 0 : new Date(num * 1e3);
383
- var decNumber = (buf, off, size) => Number(buf[off]) & 128 ? parse(buf.subarray(off, off + size)) : decSmallNumber(buf, off, size);
384
- var nanUndef = (value) => isNaN(value) ? void 0 : value;
385
- var decSmallNumber = (buf, off, size) => nanUndef(parseInt(buf.subarray(off, off + size).toString("utf8").replace(/\0.*$/, "").trim(), 8));
386
- var MAXNUM = {
387
- 12: 8589934591,
388
- 8: 2097151
389
- };
390
- 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);
391
- var encSmallNumber = (buf, off, size, num) => buf.write(octalString(num, size), off, size, "ascii");
392
- var octalString = (num, size) => padOctal(Math.floor(num).toString(8), size);
393
- var padOctal = (str, size) => (str.length === size - 1 ? str : new Array(size - str.length - 1).join("0") + str + " ") + "\0";
394
- var encDate = (buf, off, size, date) => date === void 0 ? false : encNumber(buf, off, size, date.getTime() / 1e3);
395
- var NULLS = new Array(156).join("\0");
396
- 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);
397
-
398
- // ../../node_modules/.vlt/~npm~tar@7.5.20/node_modules/tar/dist/esm/pax.js
399
- import { basename } from "node:path";
400
- var Pax = class _Pax {
401
- atime;
402
- mtime;
403
- ctime;
404
- charset;
405
- comment;
406
- gid;
407
- uid;
408
- gname;
409
- uname;
410
- linkpath;
411
- dev;
412
- ino;
413
- nlink;
414
- path;
415
- size;
416
- mode;
417
- global;
418
- constructor(obj, global = false) {
419
- this.atime = obj.atime;
420
- this.charset = obj.charset;
421
- this.comment = obj.comment;
422
- this.ctime = obj.ctime;
423
- this.dev = obj.dev;
424
- this.gid = obj.gid;
425
- this.global = global;
426
- this.gname = obj.gname;
427
- this.ino = obj.ino;
428
- this.linkpath = obj.linkpath;
429
- this.mtime = obj.mtime;
430
- this.nlink = obj.nlink;
431
- this.path = obj.path;
432
- this.size = obj.size;
433
- this.uid = obj.uid;
434
- this.uname = obj.uname;
435
- }
436
- encode() {
437
- const body = this.encodeBody();
438
- if (body === "") {
439
- return Buffer.allocUnsafe(0);
440
- }
441
- const bodyLen = Buffer.byteLength(body);
442
- const bufLen = 512 * Math.ceil(1 + bodyLen / 512);
443
- const buf = Buffer.allocUnsafe(bufLen);
444
- for (let i = 0; i < 512; i++) {
445
- buf[i] = 0;
446
- }
447
- new Header({
448
- // XXX split the path
449
- // then the path should be PaxHeader + basename, but less than 99,
450
- // prepend with the dirname
451
- /* c8 ignore start */
452
- path: ("PaxHeader/" + basename(this.path ?? "")).slice(0, 99),
453
- /* c8 ignore stop */
454
- mode: this.mode || 420,
455
- uid: this.uid,
456
- gid: this.gid,
457
- size: bodyLen,
458
- mtime: this.mtime,
459
- type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader",
460
- linkpath: "",
461
- uname: this.uname || "",
462
- gname: this.gname || "",
463
- devmaj: 0,
464
- devmin: 0,
465
- atime: this.atime,
466
- ctime: this.ctime
467
- }).encode(buf);
468
- buf.write(body, 512, bodyLen, "utf8");
469
- for (let i = bodyLen + 512; i < buf.length; i++) {
470
- buf[i] = 0;
471
- }
472
- return buf;
473
- }
474
- encodeBody() {
475
- 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");
476
- }
477
- encodeField(field) {
478
- if (this[field] === void 0) {
479
- return "";
480
- }
481
- const r = this[field];
482
- const v = r instanceof Date ? r.getTime() / 1e3 : r;
483
- const s = " " + (field === "dev" || field === "ino" || field === "nlink" ? "SCHILY." : "") + field + "=" + v + "\n";
484
- const byteLen = Buffer.byteLength(s);
485
- let digits = Math.floor(Math.log(byteLen) / Math.log(10)) + 1;
486
- if (byteLen + digits >= Math.pow(10, digits)) {
487
- digits += 1;
488
- }
489
- const len = digits + byteLen;
490
- return len + s;
491
- }
492
- static parse(str, ex, g = false) {
493
- return new _Pax(merge(parseKV(str), ex), g);
494
- }
495
- };
496
- var merge = (a, b) => b ? Object.assign({}, b, a) : a;
497
- var parseKV = (str) => str.replace(/\n$/, "").split("\n").reduce(parseKVLine, /* @__PURE__ */ Object.create(null));
498
- var parseKVLine = (set, line) => {
499
- const n = parseInt(line, 10);
500
- if (n !== Buffer.byteLength(line) + 1) {
501
- return set;
502
- }
503
- line = line.slice((n + " ").length);
504
- const kv = line.split("=");
505
- const r = kv.shift();
506
- if (!r) {
507
- return set;
508
- }
509
- const k = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1");
510
- const v = kv.join("=").replace(/\0.*/, "");
511
- switch (k) {
512
- case "path":
513
- case "linkpath":
514
- case "type":
515
- case "charset":
516
- case "comment":
517
- case "gname":
518
- case "uname":
519
- set[k] = v;
520
- break;
521
- case "ctime":
522
- case "atime":
523
- case "mtime":
524
- set[k] = new Date(Number(v) * 1e3);
525
- break;
526
- case "size":
527
- const s = +v;
528
- if (s >= 0)
529
- set[k] = s;
530
- break;
531
- case "gid":
532
- case "uid":
533
- case "dev":
534
- case "ino":
535
- case "nlink":
536
- case "mode":
537
- set[k] = +v;
538
- break;
539
- }
540
- return set;
541
- };
542
-
543
- // ../../src/tar/src/unpack.ts
544
- import { unzip as unzipCB } from "node:zlib";
545
-
546
- // ../../src/tar/src/find-tar-dir.ts
547
- var findTarDir = (path, tarDir) => {
548
- if (tarDir !== void 0) return tarDir;
549
- if (!path) return void 0;
550
- const i = path.indexOf("/", path.startsWith("./") ? 2 : 0);
551
- if (i === -1) return void 0;
552
- const chomp = path.substring(0, i);
553
- if (chomp === "." || chomp === ".." || chomp === "" || chomp === "./." || chomp === "./.." || chomp === "./") {
554
- return void 0;
555
- }
556
- return chomp + "/";
557
- };
558
-
559
- // ../../src/tar/src/unpack.ts
560
- var unzip = async (input) => new Promise(
561
- (res, rej) => (
562
- /* c8 ignore start */
563
- unzipCB(input, (er, result) => er ? rej(er) : res(result))
564
- )
565
- /* c8 ignore stop */
566
- );
567
- var exists = async (path) => {
568
- try {
569
- await lstat(path);
570
- return true;
571
- } catch {
572
- return false;
573
- }
574
- };
575
- var id = 1;
576
- var tmp = randomBytes(6).toString("hex") + ".";
577
- var tmpSuffix = () => tmp + String(id++);
578
- var checkFs = (h, tarDir, target) => {
579
- if (!h.path) return false;
580
- if (!tarDir) return false;
581
- h.path = h.path.replace(/[\\/]+/g, "/");
582
- if (!h.path.startsWith(tarDir)) return false;
583
- const absoluteBasePath = target;
584
- const itemAbsolutePath = resolve2(
585
- target,
586
- h.path.slice(tarDir.length)
587
- );
588
- if (!itemAbsolutePath.startsWith(absoluteBasePath)) {
589
- return false;
590
- }
591
- return true;
592
- };
593
- var write = async (path, body, executable = false) => {
594
- await mkdirp(dirname(path));
595
- await writeFile(path, body, {
596
- mode: executable ? 511 : 438
597
- });
598
- };
599
- var made = /* @__PURE__ */ new Set();
600
- var making = /* @__PURE__ */ new Map();
601
- var mkdirp = async (d) => {
602
- if (!made.has(d)) {
603
- const m = making.get(d) ?? mkdir(d, { recursive: true, mode: 511 }).then(
604
- () => making.delete(d)
605
- );
606
- making.set(d, m);
607
- await m;
608
- made.add(d);
609
- }
610
- };
611
- var unpack = async (tarData, target) => {
612
- const isGzip = tarData[0] === 31 && tarData[1] === 139;
613
- await unpackUnzipped(
614
- isGzip ? await unzip(tarData) : tarData,
615
- target
616
- );
617
- };
618
- var unpackUnzipped = async (buffer, target) => {
619
- const isGzip = buffer[0] === 31 && buffer[1] === 139;
620
- if (isGzip) {
621
- throw error("still gzipped after unzipping", {
622
- found: isGzip,
623
- wanted: false
624
- });
625
- }
626
- if (buffer.length % 512 !== 0) {
627
- throw error("Invalid tarball: length not divisible by 512", {
628
- found: buffer.length
629
- });
630
- }
631
- if (buffer.length < 1024) {
632
- throw error(
633
- "Invalid tarball: not terminated by 1024 null bytes",
634
- { found: buffer.length }
635
- );
636
- }
637
- for (let i = buffer.length - 1024; i < buffer.length; i++) {
638
- if (buffer[i] !== 0) {
639
- throw error(
640
- "Invalid tarball: not terminated by 1024 null bytes",
641
- { found: buffer.subarray(i, i + 10) }
642
- );
643
- }
644
- }
645
- const tmp2 = dirname(target) + sep + "." + basename2(target) + "." + tmpSuffix();
646
- const og = tmp2 + ".ORIGINAL";
647
- await Promise.all([rimraf(tmp2), rimraf(og)]);
648
- let succeeded = false;
649
- try {
650
- let tarDir = void 0;
651
- let offset = 0;
652
- let h;
653
- let ex = void 0;
654
- let gex = void 0;
655
- while (offset < buffer.length && !(h = new Header(buffer, offset, ex, gex)).nullBlock) {
656
- offset += 512;
657
- ex = void 0;
658
- gex = void 0;
659
- const size = h.size ?? 0;
660
- const body = buffer.subarray(offset, offset + size);
661
- if (!h.cksumValid) continue;
662
- offset += 512 * Math.ceil(size / 512);
663
- switch (h.type) {
664
- case "File":
665
- if (!tarDir) tarDir = findTarDir(h.path, tarDir);
666
- if (!tarDir) continue;
667
- if (!checkFs(h, tarDir, tmp2)) continue;
668
- await write(
669
- resolve2(tmp2, h.path.substring(tarDir.length)),
670
- body,
671
- // if it's world-executable, it's an executable
672
- // otherwise, make it read-only.
673
- 1 === ((h.mode ?? 1638) & 1)
674
- );
675
- break;
676
- case "Directory":
677
- if (!tarDir) tarDir = findTarDir(h.path, tarDir);
678
- if (!tarDir) continue;
679
- if (!checkFs(h, tarDir, tmp2)) continue;
680
- await mkdirp(resolve2(tmp2, h.path.substring(tarDir.length)));
681
- break;
682
- case "GlobalExtendedHeader":
683
- gex = Pax.parse(body.toString(), gex, true);
684
- break;
685
- case "ExtendedHeader":
686
- case "OldExtendedHeader":
687
- ex = Pax.parse(body.toString(), ex, false);
688
- break;
689
- case "NextFileHasLongPath":
690
- case "OldGnuLongPath":
691
- ex ??= /* @__PURE__ */ Object.create(null);
692
- ex.path = body.toString().replace(/\0.*/, "");
693
- break;
694
- }
695
- }
696
- const targetExists = await exists(target);
697
- if (targetExists) await rename(target, og);
698
- await rename(tmp2, target);
699
- if (targetExists) await rimraf(og);
700
- succeeded = true;
701
- } finally {
702
- if (!succeeded) {
703
- if (await exists(og)) {
704
- await rimraf(target);
705
- await rename(og, target);
706
- }
707
- await rimraf(tmp2);
708
- }
709
- }
710
- };
711
-
712
- // ../../src/tar/src/pool.ts
713
- import os from "node:os";
714
-
715
- // ../../src/tar/src/unpack-request.ts
716
- var ID = 1;
717
- var UnpackRequest = class {
718
- id = ID++;
719
- tarData;
720
- target;
721
- resolve;
722
- reject;
723
- promise = new Promise((res, rej) => {
724
- this.resolve = res;
725
- this.reject = rej;
726
- });
727
- constructor(tarData, target) {
728
- this.tarData = tarData;
729
- this.target = target;
730
- }
731
- };
732
-
733
- // ../../src/tar/src/worker.ts
734
- var isObj = (o) => !!o && typeof o === "object";
735
- var isResponseOK = (o) => isObj(o) && typeof o.id === "number" && o.ok === true;
736
- var Worker = class {
737
- onMessage;
738
- constructor(onMessage) {
739
- this.onMessage = onMessage;
740
- }
741
- async process(req) {
742
- const { target, tarData, id: id2 } = req;
743
- try {
744
- await unpack(tarData, target);
745
- const m = { id: id2, ok: true };
746
- this.onMessage(m);
747
- } catch (error2) {
748
- const m = { id: id2, error: error2 };
749
- this.onMessage(m);
750
- }
751
- }
752
- };
753
-
754
- // ../../src/tar/src/pool.ts
755
- var Pool = class {
756
- /**
757
- * Number of workers to emplly. Defaults to 1 less than the number of
758
- * CPUs, or 1.
759
- */
760
- /* c8 ignore next */
761
- jobs = 8 * (Math.max(os.availableParallelism(), 2) - 1);
762
- /**
763
- * Set of currently active worker threads
764
- */
765
- workers = /* @__PURE__ */ new Set();
766
- /**
767
- * Queue of requests awaiting an available worker
768
- */
769
- queue = [];
770
- /**
771
- * Requests that have been assigned to a worker, but have not yet
772
- * been confirmed completed.
773
- */
774
- pending = /* @__PURE__ */ new Map();
775
- // handle a message from the worker
776
- #onMessage(w, m) {
777
- const { id: id2 } = m;
778
- const ur = this.pending.get(id2);
779
- if (!ur) return;
780
- if (isResponseOK(m)) {
781
- ur.resolve();
782
- } else {
783
- ur.reject(
784
- error(
785
- asError(m.error, "failed without error message").message,
786
- {
787
- found: m,
788
- cause: m.error
789
- }
790
- )
791
- );
792
- }
793
- const next = this.queue.shift();
794
- if (!next) {
795
- this.workers.delete(w);
796
- } else {
797
- void w.process(next);
798
- }
799
- }
800
- // create a new worker
801
- #createWorker(req) {
802
- const w = new Worker(
803
- (m) => this.#onMessage(w, m)
804
- );
805
- this.workers.add(w);
806
- void w.process(req);
807
- }
808
- /**
809
- * Provide the tardata to be unpacked, and the location where it's to be
810
- * placed. Will create a new worker up to the `jobs` value, and then start
811
- * pushing in the queue for workers to pick up as they become available.
812
- *
813
- * Returned promise resolves when the provided tarball has been extracted.
814
- */
815
- async unpack(tarData, target) {
816
- const ur = new UnpackRequest(tarData, target);
817
- this.pending.set(ur.id, ur);
818
- if (this.workers.size < this.jobs) {
819
- this.#createWorker(ur);
820
- } else {
821
- this.queue.push(ur);
822
- }
823
- return ur.promise;
824
- }
825
- };
826
-
827
- // ../../src/package-info/src/index.ts
828
- var import_ssri = __toESM(require_lib(), 1);
829
- import { createHash, randomBytes as randomBytes2 } from "node:crypto";
830
- import {
831
- mkdir as mkdir2,
832
- readFile,
833
- rm as rm2,
834
- stat,
835
- symlink,
836
- unlink,
837
- writeFile as writeFile2
838
- } from "node:fs/promises";
839
- import {
840
- basename as basename3,
841
- dirname as dirname2,
842
- resolve as pathResolve,
843
- relative
844
- } from "node:path";
845
-
846
- // ../../src/package-info/src/rename.ts
847
- import { rename as fsRename, rm } from "node:fs/promises";
848
- var { platform } = process;
849
- var rename2 = platform !== "win32" ? fsRename : (async function(oldPath, newPath) {
850
- let retries = 3;
851
- const retry = async (er) => {
852
- if (retries > 0 && er.code === "EPERM") {
853
- retries--;
854
- await rm(newPath, { recursive: true, force: true });
855
- return fsRename(oldPath, newPath).then(() => {
856
- }, retry);
857
- } else {
858
- throw er;
859
- }
860
- };
861
- return fsRename(oldPath, newPath).then(() => {
862
- }, retry);
863
- });
864
-
865
- // ../../src/package-info/src/index.ts
866
- var xdg = new XDG("vlt");
867
- var delimiter = "~";
868
- var manifestCacheMaxAge = 5 * 60 * 1e3;
869
- var noRegistryError = (spec) => error(
870
- 'No registry configured to resolve this spec. Set "registry" in vlt.json, pass --registry, or run `vlt login --registry=<url>`. See https://docs.vlt.sh/cli',
871
- { code: "ECONFIG", spec }
872
- );
873
- var PackageInfoClient = class {
874
- #registryClient;
875
- #projectRoot;
876
- #tarPool;
877
- options;
878
- #resolutions = /* @__PURE__ */ new Map();
879
- packageJson;
880
- monorepo;
881
- #trustedIntegrities = /* @__PURE__ */ new Map();
882
- #manifestCacheMinAge = Date.now() - manifestCacheMaxAge;
883
- #cachePath;
884
- #packumentPromises = /* @__PURE__ */ new Map();
885
- get registryClient() {
886
- if (!this.#registryClient) {
887
- this.#registryClient = new RegistryClient(this.options);
888
- }
889
- return this.#registryClient;
890
- }
891
- get tarPool() {
892
- if (!this.#tarPool) this.#tarPool = new Pool();
893
- return this.#tarPool;
894
- }
895
- constructor(options = {}) {
896
- this.options = options;
897
- this.#projectRoot = options.projectRoot || process.cwd();
898
- this.packageJson = options.packageJson ?? new PackageJson();
899
- const wsLoad = {
900
- ...options.workspace?.length && { paths: options.workspace },
901
- ...options["workspace-group"]?.length && {
902
- groups: options["workspace-group"]
903
- }
904
- };
905
- this.monorepo = options.monorepo ?? Monorepo.maybeLoad(this.#projectRoot, {
906
- load: wsLoad,
907
- packageJson: this.packageJson
908
- });
909
- this.#cachePath = options.cache ?? xdg.cache();
910
- void mkdir2(pathResolve(this.#cachePath, "package-info"), {
911
- recursive: true
912
- }).catch(() => {
913
- });
914
- }
915
- async extract(spec, target, options = {}) {
916
- if (typeof spec === "string")
917
- spec = Spec.parse(spec, this.options);
918
- const {
919
- from = this.#projectRoot,
920
- integrity,
921
- resolved,
922
- fromLockfile = false
923
- } = options;
924
- const f = spec.final;
925
- const alreadyResolved = !!(integrity && resolved);
926
- const r = alreadyResolved ? { resolved, integrity, spec } : await this.resolve(spec, options);
927
- switch (f.type) {
928
- case "git": {
929
- const {
930
- gitRemote,
931
- gitCommittish,
932
- remoteURL,
933
- gitSelectorParsed
934
- } = f;
935
- if (!remoteURL) {
936
- if (!gitRemote)
937
- throw this.#resolveError(
938
- spec,
939
- options,
940
- "no remote on git: specifier"
941
- );
942
- const { path } = gitSelectorParsed ?? {};
943
- if (path !== void 0) {
944
- const tmp2 = pathResolve(
945
- dirname2(target),
946
- `.TEMP.${basename3(target)}-${randomBytes2(6).toString("hex")}`
947
- );
948
- await clone(gitRemote, gitCommittish, tmp2, { spec });
949
- const src = pathResolve(tmp2, path);
950
- await rename2(src, target);
951
- void rm2(tmp2, { recursive: true, force: true });
952
- } else {
953
- await clone(gitRemote, gitCommittish, target, { spec });
954
- void rm2(target + "/.git", { recursive: true });
955
- }
956
- return r;
957
- }
958
- }
959
- case "registry": {
960
- const fetchTarball = async (useCache) => {
961
- const trustIntegrity = this.#trustedIntegrities.get(r.resolved) === r.integrity;
962
- const response = await this.registryClient.request(
963
- r.resolved,
964
- {
965
- integrity: r.integrity,
966
- trustIntegrity,
967
- ...useCache === false ? { useCache } : {}
968
- }
969
- );
970
- if (response.statusCode !== 200) {
971
- throw this.#resolveError(
972
- spec,
973
- options,
974
- `Registry returned HTTP ${response.statusCode} when fetching the tarball for ${spec}. The resolved version may have been unpublished, or the registry may be misconfigured or unreachable.`,
975
- {
976
- url: r.resolved,
977
- response
978
- }
979
- );
980
- }
981
- if (!trustIntegrity && response.checkIntegrity({ spec, url: resolved })) {
982
- this.#trustedIntegrities.set(
983
- r.resolved,
984
- response.integrity
985
- );
986
- }
987
- const buf2 = response.buffer();
988
- if (r.integrity && !fromLockfile) {
989
- const hash = createHash("sha512");
990
- hash.update(buf2);
991
- const computed = `sha512-${hash.digest("base64")}`;
992
- if (computed !== r.integrity) {
993
- throw error("Tarball integrity check failed", {
994
- code: "EINTEGRITY",
995
- spec,
996
- url: r.resolved,
997
- wanted: r.integrity,
998
- found: computed
999
- });
1000
- }
1001
- }
1002
- return buf2;
1003
- };
1004
- let buf;
1005
- try {
1006
- buf = await fetchTarball();
1007
- } catch (er) {
1008
- if (er instanceof Error && "cause" in er && er.cause?.code === "EINTEGRITY") {
1009
- buf = await fetchTarball(false);
1010
- } else {
1011
- throw er;
1012
- }
1013
- }
1014
- try {
1015
- await this.tarPool.unpack(buf, target);
1016
- } catch (er) {
1017
- throw this.#resolveError(
1018
- spec,
1019
- options,
1020
- "tar unpack failed",
1021
- { cause: er }
1022
- );
1023
- }
1024
- return r;
1025
- }
1026
- case "remote": {
1027
- const response = await this.registryClient.request(r.resolved);
1028
- if (response.statusCode !== 200) {
1029
- throw this.#resolveError(
1030
- spec,
1031
- options,
1032
- "failed to fetch remote tarball",
1033
- {
1034
- url: r.resolved,
1035
- response
1036
- }
1037
- );
1038
- }
1039
- const buf = response.buffer();
1040
- const computed = import_ssri.default.fromData(buf, { algorithms: ["sha512"] }).toString();
1041
- if (r.integrity && r.integrity !== computed) {
1042
- throw error("Integrity check failure", {
1043
- code: "EINTEGRITY",
1044
- spec,
1045
- url: r.resolved,
1046
- wanted: r.integrity,
1047
- found: computed
1048
- });
1049
- }
1050
- r.integrity = computed;
1051
- try {
1052
- await this.tarPool.unpack(buf, target);
1053
- } catch (er) {
1054
- throw this.#resolveError(
1055
- spec,
1056
- options,
1057
- "remote tar unpack failed",
1058
- { cause: er }
1059
- );
1060
- }
1061
- return r;
1062
- }
1063
- case "file": {
1064
- const { file } = f;
1065
- if (file === void 0)
1066
- throw this.#resolveError(spec, options, "no file path");
1067
- const path = pathResolve(from, file);
1068
- const st = await stat(path);
1069
- if (st.isFile()) {
1070
- try {
1071
- await this.tarPool.unpack(
1072
- await this.tarball(spec, options),
1073
- target
1074
- );
1075
- } catch (er) {
1076
- throw this.#resolveError(
1077
- spec,
1078
- options,
1079
- "tar unpack failed",
1080
- { cause: er }
1081
- );
1082
- }
1083
- } else if (st.isDirectory()) {
1084
- const rel = relative(dirname2(target), path);
1085
- await symlink(rel, target, "dir");
1086
- } else {
1087
- throw this.#resolveError(
1088
- spec,
1089
- options,
1090
- "file: specifier does not resolve to directory or tarball"
1091
- );
1092
- }
1093
- return r;
1094
- }
1095
- case "workspace": {
1096
- const ws = this.#getWS(spec, options);
1097
- const rel = relative(dirname2(target), ws.fullpath);
1098
- await symlink(rel, target, "dir");
1099
- return r;
1100
- }
1101
- }
1102
- }
1103
- #getWS(spec, options) {
1104
- const { workspace } = spec;
1105
- if (workspace === void 0)
1106
- throw this.#resolveError(spec, options, "no workspace ID");
1107
- if (!this.monorepo) {
1108
- throw this.#resolveError(
1109
- spec,
1110
- options,
1111
- "Not in a monorepo, cannot resolve workspace spec"
1112
- );
1113
- }
1114
- const ws = this.monorepo.get(workspace);
1115
- if (!ws) {
1116
- throw this.#resolveError(spec, options, "workspace not found", {
1117
- wanted: workspace
1118
- });
1119
- }
1120
- return ws;
1121
- }
1122
- /**
1123
- * Return the manifest cache key for a spec and the current options.
1124
- */
1125
- #manifestCacheKey(spec, options) {
1126
- let extra = "";
1127
- if (options["node-version"]) {
1128
- extra += `${delimiter}node-version:${options["node-version"]}`;
1129
- }
1130
- if (options.os) {
1131
- extra += `${delimiter}os:${options.os}`;
1132
- }
1133
- if (options.arch) {
1134
- extra += `${delimiter}arch:${options.arch}`;
1135
- }
1136
- return encodeURIComponent(
1137
- `${spec.registry ?? ""}${delimiter}${spec}${extra}`
1138
- );
1139
- }
1140
- /**
1141
- * Conditionally return the path to the manifest cache file. The logic
1142
- * to determine if caching should be skipped aligns with `pickManifest`
1143
- * and is used to avoid caching manifest results that can be variable.
1144
- */
1145
- _manifestCachePath(spec, options) {
1146
- if (options.before) {
1147
- return;
1148
- }
1149
- const f = spec.final;
1150
- if (f.distTag || f.range?.isAny) {
1151
- return;
1152
- }
1153
- const key = this.#manifestCacheKey(f, options);
1154
- return pathResolve(this.#cachePath, "package-info", key);
1155
- }
1156
- async tarball(spec, options = {}) {
1157
- if (typeof spec === "string")
1158
- spec = Spec.parse(spec, this.options);
1159
- const f = spec.final;
1160
- switch (f.type) {
1161
- case "registry": {
1162
- const { dist } = await this.manifest(spec, options);
1163
- if (!dist)
1164
- throw this.#resolveError(
1165
- spec,
1166
- options,
1167
- `The registry manifest for ${spec} has no "dist" section, so no tarball can be resolved. The package version may be malformed or unpublished.`
1168
- );
1169
- const { tarball, integrity } = dist;
1170
- if (!tarball) {
1171
- throw this.#resolveError(
1172
- spec,
1173
- options,
1174
- `The registry manifest for ${spec} is missing a tarball URL (dist.tarball). The package version may be malformed or unpublished in this registry.`
1175
- );
1176
- }
1177
- const fetchTarball = async (useCache) => {
1178
- const trustIntegrity = this.#trustedIntegrities.get(tarball) === integrity;
1179
- const response = await this.registryClient.request(
1180
- tarball,
1181
- {
1182
- ...options,
1183
- integrity,
1184
- trustIntegrity,
1185
- ...useCache === false ? { useCache } : {}
1186
- }
1187
- );
1188
- if (response.statusCode !== 200) {
1189
- throw this.#resolveError(
1190
- spec,
1191
- options,
1192
- `Registry returned HTTP ${response.statusCode} when fetching the tarball for ${spec} at ${tarball}. The version may have been unpublished, or the registry may be misconfigured or unreachable.`,
1193
- { response, url: tarball }
1194
- );
1195
- }
1196
- if (!trustIntegrity && response.checkIntegrity({ spec, url: tarball })) {
1197
- this.#trustedIntegrities.set(tarball, response.integrity);
1198
- }
1199
- const buf = response.buffer();
1200
- if (integrity) {
1201
- const hash = createHash("sha512");
1202
- hash.update(buf);
1203
- const computed = `sha512-${hash.digest("base64")}`;
1204
- if (computed !== integrity) {
1205
- throw error("Tarball integrity check failed", {
1206
- code: "EINTEGRITY",
1207
- spec,
1208
- url: tarball,
1209
- wanted: integrity,
1210
- found: computed
1211
- });
1212
- }
1213
- }
1214
- return buf;
1215
- };
1216
- try {
1217
- return await fetchTarball();
1218
- } catch (er) {
1219
- if (er instanceof Error && "cause" in er && er.cause?.code === "EINTEGRITY") {
1220
- return await fetchTarball(false);
1221
- }
1222
- throw er;
1223
- }
1224
- }
1225
- case "git": {
1226
- const {
1227
- remoteURL,
1228
- gitRemote,
1229
- gitCommittish,
1230
- gitSelectorParsed
1231
- } = f;
1232
- const s = spec;
1233
- if (!remoteURL) {
1234
- if (!gitRemote) {
1235
- throw this.#resolveError(
1236
- spec,
1237
- options,
1238
- "no remote on git: specifier"
1239
- );
1240
- }
1241
- const { path } = gitSelectorParsed ?? {};
1242
- return await this.#tmpdir(async (dir) => {
1243
- await clone(gitRemote, gitCommittish, dir + "/package", {
1244
- spec: s
1245
- });
1246
- let cwd = dir;
1247
- if (path !== void 0) {
1248
- const src = pathResolve(dir, "package", path);
1249
- cwd = dirname2(src);
1250
- const pkg = pathResolve(cwd, "package");
1251
- if (src !== pkg) {
1252
- const rand = randomBytes2(6).toString("hex");
1253
- await rename2(pkg, pkg + rand).catch(() => {
1254
- });
1255
- await rename2(src, pkg);
1256
- }
1257
- }
1258
- return Qn({ cwd, gzip: true }, ["package"]).concat();
1259
- });
1260
- }
1261
- }
1262
- case "remote": {
1263
- const { remoteURL } = f;
1264
- if (!remoteURL) {
1265
- throw this.#resolveError(spec, options);
1266
- }
1267
- const response = await this.registryClient.request(remoteURL);
1268
- if (response.statusCode !== 200) {
1269
- throw this.#resolveError(
1270
- spec,
1271
- options,
1272
- "failed to fetch URL",
1273
- { response, url: remoteURL }
1274
- );
1275
- }
1276
- return response.buffer();
1277
- }
1278
- case "file": {
1279
- const { file } = f;
1280
- if (file === void 0)
1281
- throw this.#resolveError(spec, options, "no file path");
1282
- const { from = this.#projectRoot } = options;
1283
- const path = pathResolve(from, file);
1284
- const st = await stat(path);
1285
- if (st.isDirectory()) {
1286
- const p = dirname2(path);
1287
- const b = basename3(path);
1288
- return Qn({ cwd: p, gzip: true }, [b]).concat();
1289
- }
1290
- return readFile(path);
1291
- }
1292
- case "workspace": {
1293
- const ws = this.#getWS(spec, options);
1294
- const p = dirname2(ws.fullpath);
1295
- const b = basename3(ws.fullpath);
1296
- return Qn({ cwd: p, gzip: true }, [b]).concat();
1297
- }
1298
- }
1299
- }
1300
- async manifest(spec, options = {}) {
1301
- const { from = this.#projectRoot } = options;
1302
- if (typeof spec === "string")
1303
- spec = Spec.parse(spec, this.options);
1304
- const f = spec.final;
1305
- switch (f.type) {
1306
- case "registry": {
1307
- const cachePath = this._manifestCachePath(spec, options);
1308
- if (cachePath) {
1309
- try {
1310
- const cached = await readFile(cachePath, "utf8");
1311
- const json = JSON.parse(cached);
1312
- const timestamp = json.__VLT_MANIFEST_CACHE_TIMESTAMP;
1313
- delete json.__VLT_MANIFEST_CACHE_TIMESTAMP;
1314
- if (timestamp != null && timestamp < this.#manifestCacheMinAge) {
1315
- void unlink(cachePath).catch(() => {
1316
- });
1317
- throw new Error("manifest cache expired");
1318
- }
1319
- return json;
1320
- } catch {
1321
- }
1322
- }
1323
- const mani = pickManifest(
1324
- await this.packument(f, options),
1325
- spec,
1326
- options
1327
- );
1328
- if (!mani) throw this.#resolveError(spec, options);
1329
- if (cachePath) {
1330
- const json = JSON.stringify({
1331
- ...mani,
1332
- // append a timestamp to the manifest so that we can quickly
1333
- // check if the cache is still valid when loading it
1334
- __VLT_MANIFEST_CACHE_TIMESTAMP: Date.now()
1335
- });
1336
- void writeFile2(cachePath, json, "utf8").catch(
1337
- (err) => {
1338
- if (err instanceof Error && "code" in err && err.code === "ENOENT") {
1339
- void mkdir2(dirname2(cachePath), {
1340
- recursive: true
1341
- }).then(() => {
1342
- void writeFile2(cachePath, json, "utf8");
1343
- });
1344
- }
1345
- }
1346
- );
1347
- }
1348
- return mani;
1349
- }
1350
- case "git": {
1351
- const {
1352
- gitRemote,
1353
- gitCommittish,
1354
- remoteURL,
1355
- gitSelectorParsed
1356
- } = f;
1357
- if (!remoteURL) {
1358
- const s = spec;
1359
- if (!gitRemote)
1360
- throw this.#resolveError(spec, options, "no git remote");
1361
- return await this.#tmpdir(async (dir) => {
1362
- await clone(gitRemote, gitCommittish, dir, { spec: s });
1363
- const { path } = gitSelectorParsed ?? {};
1364
- const pkgDir = path !== void 0 ? pathResolve(dir, path) : dir;
1365
- return this.packageJson.read(pkgDir);
1366
- });
1367
- }
1368
- }
1369
- case "remote": {
1370
- const { remoteURL } = f;
1371
- if (!remoteURL) {
1372
- throw this.#resolveError(
1373
- spec,
1374
- options,
1375
- "no remoteURL on remote specifier"
1376
- );
1377
- }
1378
- const s = spec;
1379
- return await this.#tmpdir(async (dir) => {
1380
- const response = await this.registryClient.request(remoteURL);
1381
- if (response.statusCode !== 200) {
1382
- throw this.#resolveError(
1383
- s,
1384
- options,
1385
- "failed to fetch URL",
1386
- { response, url: remoteURL }
1387
- );
1388
- }
1389
- const buf = response.buffer();
1390
- const computed = import_ssri.default.fromData(buf, { algorithms: ["sha512"] }).toString();
1391
- try {
1392
- await this.tarPool.unpack(buf, dir);
1393
- } catch (er) {
1394
- throw this.#resolveError(
1395
- s,
1396
- options,
1397
- "tar unpack failed",
1398
- { cause: er }
1399
- );
1400
- }
1401
- const mani = this.packageJson.read(dir);
1402
- mani.dist = { integrity: computed };
1403
- return mani;
1404
- });
1405
- }
1406
- case "file": {
1407
- const { file } = f;
1408
- if (file === void 0)
1409
- throw this.#resolveError(spec, options, "no file path");
1410
- const path = pathResolve(from, file);
1411
- const st = await stat(path);
1412
- if (st.isDirectory()) {
1413
- return this.packageJson.read(path);
1414
- }
1415
- const s = spec;
1416
- return await this.#tmpdir(async (dir) => {
1417
- try {
1418
- await this.tarPool.unpack(await readFile(path), dir);
1419
- } catch (er) {
1420
- throw this.#resolveError(
1421
- s,
1422
- options,
1423
- "tar unpack failed",
1424
- { cause: er }
1425
- );
1426
- }
1427
- return this.packageJson.read(dir);
1428
- });
1429
- }
1430
- case "workspace": {
1431
- return this.#getWS(spec, options).manifest;
1432
- }
1433
- }
1434
- }
1435
- async packument(spec, options = {}) {
1436
- if (typeof spec === "string")
1437
- spec = Spec.parse(spec, this.options);
1438
- const f = spec.final;
1439
- switch (f.type) {
1440
- // RevDoc is the equivalent of a packument for a git repo
1441
- case "git": {
1442
- const { gitRemote } = f;
1443
- if (!gitRemote) {
1444
- throw this.#resolveError(
1445
- spec,
1446
- options,
1447
- "git remote could not be determined"
1448
- );
1449
- }
1450
- const revDoc = await revs(gitRemote, {
1451
- cwd: this.options.projectRoot
1452
- });
1453
- if (!revDoc) throw this.#resolveError(spec, options);
1454
- return asPackument(revDoc);
1455
- }
1456
- // these are all faked packuments
1457
- case "file":
1458
- case "workspace":
1459
- case "remote": {
1460
- const manifest = await this.manifest(f, options);
1461
- return {
1462
- name: manifest.name ?? "",
1463
- "dist-tags": {
1464
- latest: manifest.version ?? ""
1465
- },
1466
- versions: {
1467
- [manifest.version ?? ""]: manifest
1468
- }
1469
- };
1470
- }
1471
- case "registry": {
1472
- const { registry, name: name2 } = f;
1473
- if (!registry) throw noRegistryError(spec);
1474
- const packumentKey = `${registry}${name2}`;
1475
- const inflight = this.#packumentPromises.get(packumentKey);
1476
- if (inflight) return inflight;
1477
- const pakuURL = new URL(name2, registry);
1478
- const promise = this.#fetchPackument(spec, options, pakuURL);
1479
- this.#packumentPromises.set(packumentKey, promise);
1480
- promise.then(
1481
- () => this.#packumentPromises.delete(packumentKey),
1482
- () => this.#packumentPromises.delete(packumentKey)
1483
- );
1484
- return promise;
1485
- }
1486
- }
1487
- }
1488
- async #fetchPackument(spec, options, pakuURL) {
1489
- const response = await this.registryClient.request(pakuURL, {
1490
- headers: { accept: "application/json" }
1491
- });
1492
- if (response.statusCode !== 200) {
1493
- throw this.#resolveError(
1494
- spec,
1495
- options,
1496
- "failed to fetch packument",
1497
- {
1498
- url: pakuURL,
1499
- response
1500
- }
1501
- );
1502
- }
1503
- return response.json();
1504
- }
1505
- async resolve(spec, options = {}) {
1506
- const memoKey = String(spec);
1507
- if (typeof spec === "string")
1508
- spec = Spec.parse(spec, this.options);
1509
- const memo = this.#resolutions.get(memoKey);
1510
- if (memo) return memo;
1511
- const f = spec.final;
1512
- switch (f.type) {
1513
- case "file": {
1514
- const { file } = f;
1515
- if (!file || !f.file) {
1516
- throw this.#resolveError(
1517
- spec,
1518
- options,
1519
- "no path on file: specifier"
1520
- );
1521
- }
1522
- const { from = this.#projectRoot } = options;
1523
- const resolved = pathResolve(from, f.file);
1524
- const r = { resolved, spec };
1525
- this.#resolutions.set(memoKey, r);
1526
- return r;
1527
- }
1528
- case "remote": {
1529
- const { remoteURL } = f;
1530
- if (!remoteURL)
1531
- throw this.#resolveError(
1532
- spec,
1533
- options,
1534
- "no URL in remote specifier"
1535
- );
1536
- const r = { resolved: remoteURL, spec };
1537
- this.#resolutions.set(memoKey, r);
1538
- return r;
1539
- }
1540
- case "workspace": {
1541
- const ws = this.#getWS(spec, options);
1542
- return {
1543
- resolved: ws.fullpath,
1544
- spec
1545
- };
1546
- }
1547
- case "registry": {
1548
- const mani = await this.manifest(spec, options);
1549
- if (mani.dist) {
1550
- const { integrity, tarball, signatures } = mani.dist;
1551
- if (tarball) {
1552
- const r = {
1553
- resolved: tarball,
1554
- integrity,
1555
- signatures,
1556
- spec
1557
- };
1558
- this.#resolutions.set(memoKey, r);
1559
- return r;
1560
- }
1561
- }
1562
- throw this.#resolveError(spec, options);
1563
- }
1564
- case "git": {
1565
- const { gitRemote, remoteURL, gitSelectorParsed } = f;
1566
- if (remoteURL && gitSelectorParsed?.path === void 0) {
1567
- const r = { resolved: remoteURL, spec };
1568
- this.#resolutions.set(memoKey, r);
1569
- return r;
1570
- }
1571
- if (!gitRemote) {
1572
- throw this.#resolveError(
1573
- spec,
1574
- options,
1575
- "no remote on git specifier"
1576
- );
1577
- }
1578
- const rev = await resolve(gitRemote, f.gitCommittish, {
1579
- spec
1580
- });
1581
- if (rev) {
1582
- const r = {
1583
- resolved: `${gitRemote}#${rev.sha}`,
1584
- spec
1585
- };
1586
- if (gitSelectorParsed) {
1587
- r.resolved += Object.entries(gitSelectorParsed).filter(([_, v]) => v).map(([k, v]) => `::${k}:${v}`).join("");
1588
- }
1589
- this.#resolutions.set(memoKey, r);
1590
- return r;
1591
- }
1592
- const s = spec;
1593
- return this.#tmpdir(async (tmpdir) => {
1594
- const sha = await clone(
1595
- gitRemote,
1596
- s.gitCommittish,
1597
- tmpdir,
1598
- {
1599
- spec: s
1600
- }
1601
- );
1602
- const r = {
1603
- resolved: `${gitRemote}#${sha}`,
1604
- spec: s
1605
- };
1606
- this.#resolutions.set(memoKey, r);
1607
- return r;
1608
- });
1609
- }
1610
- }
1611
- }
1612
- async #tmpdir(fn) {
1613
- const p = `package-info/${randomBytes2(6).toString("hex")}`;
1614
- const dir = xdg.runtime(p);
1615
- try {
1616
- return await fn(dir);
1617
- } finally {
1618
- void rm2(dir, { recursive: true, force: true });
1619
- }
1620
- }
1621
- // error resolving
1622
- #resolveError(spec, options = {}, message = "Could not resolve", extra = {}) {
1623
- const { from = this.#projectRoot } = options;
1624
- const er = error(
1625
- message,
1626
- {
1627
- code: "ERESOLVE",
1628
- spec,
1629
- from,
1630
- ...extra
1631
- },
1632
- this.#resolveError
1633
- );
1634
- return er;
1635
- }
1636
- };
1637
-
1638
- export {
1639
- PackageInfoClient
1640
- };