@vltpkg/package-info 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +19 -0
- package/dist/index.js +114 -6
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -129,6 +129,25 @@ export declare class PackageInfoClient {
|
|
|
129
129
|
*/
|
|
130
130
|
capabilities(registry: string): Promise<Capabilities>;
|
|
131
131
|
getTarPool(): Promise<Pool>;
|
|
132
|
+
/**
|
|
133
|
+
* Terminate the tar pool's placement worker threads, if any were
|
|
134
|
+
* started. Reify calls this once placement is done; it is a no-op when
|
|
135
|
+
* the pool was never created or ran inline.
|
|
136
|
+
*/
|
|
137
|
+
closeTarPool(): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Start the tar pool's unpack workers for an install about to place
|
|
140
|
+
* `nodes`, so they boot while the first packages are fetched instead
|
|
141
|
+
* of on the critical path of the first unpack. Only the nodes the
|
|
142
|
+
* global store does not already hold count: a store hit is linked on
|
|
143
|
+
* the main thread, so a warm install of all hits starts no worker.
|
|
144
|
+
* Best effort and never rejects: if the pool cannot start, unpacking
|
|
145
|
+
* just runs inline, and a real failure resurfaces at the first
|
|
146
|
+
* extract.
|
|
147
|
+
*/
|
|
148
|
+
warmTarPool(nodes: Iterable<{
|
|
149
|
+
integrity?: Integrity;
|
|
150
|
+
}>): Promise<void>;
|
|
132
151
|
constructor(options?: PackageInfoClientOptions);
|
|
133
152
|
extract(spec: Spec | string, target: string, options?: PackageInfoClientExtractOptions): Promise<ExtractResolution>;
|
|
134
153
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
2
|
import { clone, resolve as gitResolve, revs } from '@vltpkg/git';
|
|
3
3
|
import { logRequest } from '@vltpkg/output';
|
|
4
|
+
import { span } from '@vltpkg/output/trace';
|
|
4
5
|
import { PackageJson } from '@vltpkg/package-json';
|
|
5
6
|
import { pickManifest } from '@vltpkg/pick-manifest';
|
|
6
7
|
// subpath import: keeps the lazy `import('@vltpkg/registry-client')`
|
|
@@ -8,11 +9,13 @@ import { pickManifest } from '@vltpkg/pick-manifest';
|
|
|
8
9
|
import { registryErrorMessage, tokenRefusalAdvice, } from '@vltpkg/registry-client/registry-error';
|
|
9
10
|
import { storeRoot } from '@vltpkg/registry-client/store-root';
|
|
10
11
|
import { Spec } from '@vltpkg/spec';
|
|
12
|
+
import { storeIndexPath } from '@vltpkg/tar/store-index';
|
|
11
13
|
import { asPackument, brotliTarballUrl, integrityHex, tarballFormat, } from '@vltpkg/types';
|
|
12
14
|
import { fetchResolve } from "./resolve-batch.js";
|
|
13
15
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
14
16
|
import { XDG } from '@vltpkg/xdg';
|
|
15
17
|
import { createHash, randomBytes } from 'node:crypto';
|
|
18
|
+
import { lstatSync } from 'node:fs';
|
|
16
19
|
import { mkdir, readFile, rm, stat, symlink, unlink, writeFile, } from 'node:fs/promises';
|
|
17
20
|
import { basename, dirname, resolve as pathResolve, relative, } from 'node:path';
|
|
18
21
|
import { setTimeout } from 'node:timers/promises';
|
|
@@ -298,6 +301,48 @@ export class PackageInfoClient {
|
|
|
298
301
|
});
|
|
299
302
|
return this.#tarPoolPromise;
|
|
300
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Terminate the tar pool's placement worker threads, if any were
|
|
306
|
+
* started. Reify calls this once placement is done; it is a no-op when
|
|
307
|
+
* the pool was never created or ran inline.
|
|
308
|
+
*/
|
|
309
|
+
async closeTarPool() {
|
|
310
|
+
// wait out an in-flight getTarPool() so a pool created concurrently
|
|
311
|
+
// is not missed, then close whatever exists
|
|
312
|
+
await this.#tarPoolPromise;
|
|
313
|
+
await this.#tarPool?.close();
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Start the tar pool's unpack workers for an install about to place
|
|
317
|
+
* `nodes`, so they boot while the first packages are fetched instead
|
|
318
|
+
* of on the critical path of the first unpack. Only the nodes the
|
|
319
|
+
* global store does not already hold count: a store hit is linked on
|
|
320
|
+
* the main thread, so a warm install of all hits starts no worker.
|
|
321
|
+
* Best effort and never rejects: if the pool cannot start, unpacking
|
|
322
|
+
* just runs inline, and a real failure resurfaces at the first
|
|
323
|
+
* extract.
|
|
324
|
+
*/
|
|
325
|
+
async warmTarPool(nodes) {
|
|
326
|
+
try {
|
|
327
|
+
const storeOn = this.#storeLinker !== 'unpack';
|
|
328
|
+
let jobs = 0;
|
|
329
|
+
for (const { integrity } of nodes) {
|
|
330
|
+
const hex = storeOn ? integrityHex(integrity) : undefined;
|
|
331
|
+
if (hex &&
|
|
332
|
+
lstatSync(storeIndexPath(pathResolve(this.#storeRoot, hex)), { throwIfNoEntry: false })) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
jobs++;
|
|
336
|
+
}
|
|
337
|
+
// nothing to unpack: don't even load the tar pool
|
|
338
|
+
if (!jobs)
|
|
339
|
+
return;
|
|
340
|
+
await (await this.getTarPool()).warm(jobs);
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
// unpacking falls back to inline
|
|
344
|
+
}
|
|
345
|
+
}
|
|
301
346
|
/**
|
|
302
347
|
* A version's Brotli (`.tar.br`) alternate: its absolute URL, plus its
|
|
303
348
|
* hash if the registry sent one. Returns undefined if the version has no
|
|
@@ -334,25 +379,49 @@ export class PackageInfoClient {
|
|
|
334
379
|
linker && storeLinkers.has(linker) ? linker : 'unpack';
|
|
335
380
|
}
|
|
336
381
|
async extract(spec, target, options = {}) {
|
|
382
|
+
// #extract hands its span back here, so a failure ends it too
|
|
383
|
+
const extractSpan = {};
|
|
384
|
+
try {
|
|
385
|
+
return await this.#extract(spec, target, options, extractSpan);
|
|
386
|
+
}
|
|
387
|
+
catch (er) {
|
|
388
|
+
extractSpan.end?.({ how: 'error' });
|
|
389
|
+
throw er;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
async #extract(spec, target, options, extractSpan) {
|
|
337
393
|
if (typeof spec === 'string')
|
|
338
394
|
spec = Spec.parse(spec, this.options);
|
|
339
395
|
const { from = this.#projectRoot, integrity, resolved, fromLockfile = false, } = options;
|
|
340
396
|
const f = spec.final;
|
|
397
|
+
// vlt <= 1.6.0 locked hosted git tarballs with the bare git remote
|
|
398
|
+
// as `resolved`, which can't be fetched
|
|
399
|
+
const url = (f.type === 'git' &&
|
|
400
|
+
f.remoteURL &&
|
|
401
|
+
resolved &&
|
|
402
|
+
!/^https?:\/\//.test(resolved)) ?
|
|
403
|
+
f.remoteURL
|
|
404
|
+
: resolved;
|
|
341
405
|
// If the caller already provides both integrity and resolved
|
|
342
406
|
// (from lockfile or prior resolution), skip re-resolving. A
|
|
343
407
|
// `.tar.br` needs only the URL: its hash is not knowable before the
|
|
344
408
|
// download, so the graph can never hand one over, and `Repr-Digest`
|
|
345
409
|
// is what pins it -- `required`, so a registry that serves the
|
|
346
410
|
// alternate unlabelled is rejected rather than trusted.
|
|
347
|
-
const brotli = !!
|
|
348
|
-
const r =
|
|
411
|
+
const brotli = !!url && tarballFormat(url) === 'brotli';
|
|
412
|
+
const r = url && (integrity || brotli) ?
|
|
349
413
|
{
|
|
350
|
-
resolved,
|
|
414
|
+
resolved: url,
|
|
351
415
|
integrity,
|
|
352
416
|
spec,
|
|
353
417
|
...(brotli && !integrity ? { digestRequired: true } : {}),
|
|
354
418
|
}
|
|
355
419
|
: await this.resolve(spec, options);
|
|
420
|
+
const end = span('extract', {
|
|
421
|
+
spec: String(spec),
|
|
422
|
+
url: r.resolved,
|
|
423
|
+
});
|
|
424
|
+
extractSpan.end = end;
|
|
356
425
|
switch (f.type) {
|
|
357
426
|
case 'git': {
|
|
358
427
|
const { gitRemote, gitCommittish, remoteURL, gitSelectorParsed, } = f;
|
|
@@ -376,6 +445,7 @@ export class PackageInfoClient {
|
|
|
376
445
|
// intentionally not awaited
|
|
377
446
|
void rm(target + '/.git', { recursive: true });
|
|
378
447
|
}
|
|
448
|
+
end({ how: 'git' });
|
|
379
449
|
return r;
|
|
380
450
|
}
|
|
381
451
|
// fallthrough if a remote tarball url present
|
|
@@ -395,9 +465,12 @@ export class PackageInfoClient {
|
|
|
395
465
|
// hash off the cache entry, which recorded it when the bytes
|
|
396
466
|
// were verified. Installs that do have a hash skip all of this,
|
|
397
467
|
// so a store hit still never builds a registry client.
|
|
468
|
+
const cachedIntegrity = storeOn && !r.integrity ?
|
|
469
|
+
(await this.getRegistryClient()).cachedIntegrity(r.resolved)
|
|
470
|
+
: undefined;
|
|
398
471
|
const hex = !storeOn ? undefined
|
|
399
472
|
: r.integrity ? integrityHex(r.integrity)
|
|
400
|
-
: integrityHex(
|
|
473
|
+
: integrityHex(cachedIntegrity);
|
|
401
474
|
if (hex) {
|
|
402
475
|
if (debug.enabled && !this.#storeHitRateLogged) {
|
|
403
476
|
this.#storeHitRateLogged = true;
|
|
@@ -409,6 +482,13 @@ export class PackageInfoClient {
|
|
|
409
482
|
this.#storeHits[how]++;
|
|
410
483
|
// a copy is no link: report it as a cache hit
|
|
411
484
|
logRequest(r.resolved, how === 'copy' ? 'cache' : 'store');
|
|
485
|
+
// nothing pinned: the store was hit under the hash the
|
|
486
|
+
// registry client recorded when it fetched these bytes (a
|
|
487
|
+
// `.tar.br` checked against `Repr-Digest`, or a `.tgz` served
|
|
488
|
+
// with no `dist.integrity`), so the lockfile can pin it. same
|
|
489
|
+
// trust the cache-unpack path below puts in that label.
|
|
490
|
+
r.integrity ??= cachedIntegrity;
|
|
491
|
+
end({ how });
|
|
412
492
|
return {
|
|
413
493
|
...r,
|
|
414
494
|
manifest: index.manifest,
|
|
@@ -425,12 +505,19 @@ export class PackageInfoClient {
|
|
|
425
505
|
// fetch path, which throws its own error if the body is
|
|
426
506
|
// genuinely bad.
|
|
427
507
|
const rc = await this.getRegistryClient();
|
|
428
|
-
const cached = rc.
|
|
508
|
+
const cached = rc.cachedTarball(r.resolved, {
|
|
429
509
|
integrity: r.integrity,
|
|
430
510
|
});
|
|
431
511
|
if (cached) {
|
|
432
512
|
try {
|
|
433
|
-
|
|
513
|
+
const unpacked = span('tarball:unpack', {
|
|
514
|
+
url: r.resolved,
|
|
515
|
+
bytes: cached.bytes,
|
|
516
|
+
});
|
|
517
|
+
// only the head was read here: the unpacker reads the body
|
|
518
|
+
// from the file, on a worker when the pool has them
|
|
519
|
+
await pool.unpackCacheEntry(cached.path, target, format);
|
|
520
|
+
unpacked();
|
|
434
521
|
logRequest(r.resolved, 'cache');
|
|
435
522
|
r.integrity ??= cached.integrity;
|
|
436
523
|
// A warm install writes nothing to the cache, so queue the
|
|
@@ -442,6 +529,7 @@ export class PackageInfoClient {
|
|
|
442
529
|
if (storeOn || cached.gzip) {
|
|
443
530
|
rc.queueForStore(cached.key, r.integrity);
|
|
444
531
|
}
|
|
532
|
+
end({ how: 'cache' });
|
|
445
533
|
return r;
|
|
446
534
|
}
|
|
447
535
|
catch (er) {
|
|
@@ -453,12 +541,17 @@ export class PackageInfoClient {
|
|
|
453
541
|
}
|
|
454
542
|
const fetchTarball = async (useCache) => {
|
|
455
543
|
const trustIntegrity = this.#trustedIntegrities.get(r.resolved) === r.integrity;
|
|
544
|
+
const fetched = span('tarball:fetch', { url: r.resolved });
|
|
456
545
|
const response = await (await this.getRegistryClient()).request(r.resolved, {
|
|
457
546
|
integrity: r.integrity,
|
|
458
547
|
trustIntegrity,
|
|
459
548
|
verifyDigest: r.digestRequired ? 'required' : true,
|
|
460
549
|
...(useCache === false ? { useCache } : {}),
|
|
461
550
|
});
|
|
551
|
+
fetched({
|
|
552
|
+
status: response.statusCode,
|
|
553
|
+
fromCache: response.fromCache,
|
|
554
|
+
});
|
|
462
555
|
if (response.statusCode !== 200) {
|
|
463
556
|
throw this.#resolveError(spec, options, `${registryErrorMessage(response)} when ` +
|
|
464
557
|
`fetching the tarball for ${spec}. The resolved version ` +
|
|
@@ -527,11 +620,17 @@ export class PackageInfoClient {
|
|
|
527
620
|
}
|
|
528
621
|
}
|
|
529
622
|
try {
|
|
623
|
+
const unpacked = span('tarball:unpack', {
|
|
624
|
+
url: r.resolved,
|
|
625
|
+
bytes: buf.length,
|
|
626
|
+
});
|
|
530
627
|
await pool.unpack(buf, target, format);
|
|
628
|
+
unpacked();
|
|
531
629
|
}
|
|
532
630
|
catch (er) {
|
|
533
631
|
throw this.#resolveError(spec, options, 'tar unpack failed', { cause: er });
|
|
534
632
|
}
|
|
633
|
+
end({ how: 'fetch', bytes: buf.length });
|
|
535
634
|
return r;
|
|
536
635
|
}
|
|
537
636
|
case 'remote': {
|
|
@@ -648,6 +747,7 @@ export class PackageInfoClient {
|
|
|
648
747
|
catch (er) {
|
|
649
748
|
throw this.#resolveError(spec, options, 'remote tar unpack failed', { cause: er });
|
|
650
749
|
}
|
|
750
|
+
end({ how: 'remote', bytes: buf.length });
|
|
651
751
|
return r;
|
|
652
752
|
}
|
|
653
753
|
case 'file': {
|
|
@@ -676,12 +776,14 @@ export class PackageInfoClient {
|
|
|
676
776
|
throw this.#resolveError(spec, options, 'file: specifier does not resolve to directory or tarball');
|
|
677
777
|
}
|
|
678
778
|
/* c8 ignore stop */
|
|
779
|
+
end({ how: 'file' });
|
|
679
780
|
return r;
|
|
680
781
|
}
|
|
681
782
|
case 'workspace': {
|
|
682
783
|
const ws = this.#getWS(spec, options);
|
|
683
784
|
const rel = relative(dirname(target), ws.fullpath);
|
|
684
785
|
await symlink(rel, target, 'dir');
|
|
786
|
+
end({ how: 'workspace' });
|
|
685
787
|
return r;
|
|
686
788
|
}
|
|
687
789
|
}
|
|
@@ -1074,6 +1176,12 @@ export class PackageInfoClient {
|
|
|
1074
1176
|
return this.#resolvedManifests.size;
|
|
1075
1177
|
}
|
|
1076
1178
|
async manifest(spec, options = {}) {
|
|
1179
|
+
const end = span('manifest', { spec: String(spec) });
|
|
1180
|
+
const mani = await this.#manifest(spec, options);
|
|
1181
|
+
end();
|
|
1182
|
+
return mani;
|
|
1183
|
+
}
|
|
1184
|
+
async #manifest(spec, options) {
|
|
1077
1185
|
const { from = this.#projectRoot } = options;
|
|
1078
1186
|
if (typeof spec === 'string')
|
|
1079
1187
|
spec = Spec.parse(spec, this.options);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/package-info",
|
|
3
3
|
"description": "Resolve and fetch package metadata and tarballs",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/error-cause": "1.6.
|
|
17
|
-
"@vltpkg/git": "1.6.
|
|
18
|
-
"@vltpkg/output": "1.6.
|
|
19
|
-
"@vltpkg/package-json": "1.6.
|
|
20
|
-
"@vltpkg/pick-manifest": "1.6.
|
|
21
|
-
"@vltpkg/registry-client": "1.6.
|
|
22
|
-
"@vltpkg/spec": "1.6.
|
|
23
|
-
"@vltpkg/tar": "1.6.
|
|
24
|
-
"@vltpkg/types": "1.6.
|
|
25
|
-
"@vltpkg/workspaces": "1.6.
|
|
26
|
-
"@vltpkg/xdg": "1.6.
|
|
16
|
+
"@vltpkg/error-cause": "1.6.2",
|
|
17
|
+
"@vltpkg/git": "1.6.2",
|
|
18
|
+
"@vltpkg/output": "1.6.2",
|
|
19
|
+
"@vltpkg/package-json": "1.6.2",
|
|
20
|
+
"@vltpkg/pick-manifest": "1.6.2",
|
|
21
|
+
"@vltpkg/registry-client": "1.6.2",
|
|
22
|
+
"@vltpkg/spec": "1.6.2",
|
|
23
|
+
"@vltpkg/tar": "1.6.2",
|
|
24
|
+
"@vltpkg/types": "1.6.2",
|
|
25
|
+
"@vltpkg/workspaces": "1.6.2",
|
|
26
|
+
"@vltpkg/xdg": "1.6.2",
|
|
27
27
|
"tar": "^7.5.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@types/node": "^22.19.2",
|
|
32
32
|
"@types/pacote": "^11.1.8",
|
|
33
33
|
"@vltpkg/benchmark": "0.0.0",
|
|
34
|
-
"@vltpkg/cache-unzip": "1.6.
|
|
35
|
-
"@vltpkg/vlt-json": "1.6.
|
|
34
|
+
"@vltpkg/cache-unzip": "1.6.2",
|
|
35
|
+
"@vltpkg/vlt-json": "1.6.2",
|
|
36
36
|
"eslint": "^9.39.1",
|
|
37
37
|
"pacote": "^21.0.4",
|
|
38
38
|
"prettier": "^3.7.4",
|