@vltpkg/package-info 1.6.1 → 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 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,6 +379,17 @@ 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;
@@ -361,6 +417,11 @@ export class PackageInfoClient {
361
417
  ...(brotli && !integrity ? { digestRequired: true } : {}),
362
418
  }
363
419
  : await this.resolve(spec, options);
420
+ const end = span('extract', {
421
+ spec: String(spec),
422
+ url: r.resolved,
423
+ });
424
+ extractSpan.end = end;
364
425
  switch (f.type) {
365
426
  case 'git': {
366
427
  const { gitRemote, gitCommittish, remoteURL, gitSelectorParsed, } = f;
@@ -384,6 +445,7 @@ export class PackageInfoClient {
384
445
  // intentionally not awaited
385
446
  void rm(target + '/.git', { recursive: true });
386
447
  }
448
+ end({ how: 'git' });
387
449
  return r;
388
450
  }
389
451
  // fallthrough if a remote tarball url present
@@ -426,6 +488,7 @@ export class PackageInfoClient {
426
488
  // with no `dist.integrity`), so the lockfile can pin it. same
427
489
  // trust the cache-unpack path below puts in that label.
428
490
  r.integrity ??= cachedIntegrity;
491
+ end({ how });
429
492
  return {
430
493
  ...r,
431
494
  manifest: index.manifest,
@@ -442,12 +505,19 @@ export class PackageInfoClient {
442
505
  // fetch path, which throws its own error if the body is
443
506
  // genuinely bad.
444
507
  const rc = await this.getRegistryClient();
445
- const cached = rc.cachedBody(r.resolved, {
508
+ const cached = rc.cachedTarball(r.resolved, {
446
509
  integrity: r.integrity,
447
510
  });
448
511
  if (cached) {
449
512
  try {
450
- await pool.unpack(cached.body, target, format);
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();
451
521
  logRequest(r.resolved, 'cache');
452
522
  r.integrity ??= cached.integrity;
453
523
  // A warm install writes nothing to the cache, so queue the
@@ -459,6 +529,7 @@ export class PackageInfoClient {
459
529
  if (storeOn || cached.gzip) {
460
530
  rc.queueForStore(cached.key, r.integrity);
461
531
  }
532
+ end({ how: 'cache' });
462
533
  return r;
463
534
  }
464
535
  catch (er) {
@@ -470,12 +541,17 @@ export class PackageInfoClient {
470
541
  }
471
542
  const fetchTarball = async (useCache) => {
472
543
  const trustIntegrity = this.#trustedIntegrities.get(r.resolved) === r.integrity;
544
+ const fetched = span('tarball:fetch', { url: r.resolved });
473
545
  const response = await (await this.getRegistryClient()).request(r.resolved, {
474
546
  integrity: r.integrity,
475
547
  trustIntegrity,
476
548
  verifyDigest: r.digestRequired ? 'required' : true,
477
549
  ...(useCache === false ? { useCache } : {}),
478
550
  });
551
+ fetched({
552
+ status: response.statusCode,
553
+ fromCache: response.fromCache,
554
+ });
479
555
  if (response.statusCode !== 200) {
480
556
  throw this.#resolveError(spec, options, `${registryErrorMessage(response)} when ` +
481
557
  `fetching the tarball for ${spec}. The resolved version ` +
@@ -544,11 +620,17 @@ export class PackageInfoClient {
544
620
  }
545
621
  }
546
622
  try {
623
+ const unpacked = span('tarball:unpack', {
624
+ url: r.resolved,
625
+ bytes: buf.length,
626
+ });
547
627
  await pool.unpack(buf, target, format);
628
+ unpacked();
548
629
  }
549
630
  catch (er) {
550
631
  throw this.#resolveError(spec, options, 'tar unpack failed', { cause: er });
551
632
  }
633
+ end({ how: 'fetch', bytes: buf.length });
552
634
  return r;
553
635
  }
554
636
  case 'remote': {
@@ -665,6 +747,7 @@ export class PackageInfoClient {
665
747
  catch (er) {
666
748
  throw this.#resolveError(spec, options, 'remote tar unpack failed', { cause: er });
667
749
  }
750
+ end({ how: 'remote', bytes: buf.length });
668
751
  return r;
669
752
  }
670
753
  case 'file': {
@@ -693,12 +776,14 @@ export class PackageInfoClient {
693
776
  throw this.#resolveError(spec, options, 'file: specifier does not resolve to directory or tarball');
694
777
  }
695
778
  /* c8 ignore stop */
779
+ end({ how: 'file' });
696
780
  return r;
697
781
  }
698
782
  case 'workspace': {
699
783
  const ws = this.#getWS(spec, options);
700
784
  const rel = relative(dirname(target), ws.fullpath);
701
785
  await symlink(rel, target, 'dir');
786
+ end({ how: 'workspace' });
702
787
  return r;
703
788
  }
704
789
  }
@@ -1091,6 +1176,12 @@ export class PackageInfoClient {
1091
1176
  return this.#resolvedManifests.size;
1092
1177
  }
1093
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) {
1094
1185
  const { from = this.#projectRoot } = options;
1095
1186
  if (typeof spec === 'string')
1096
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.1",
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.1",
17
- "@vltpkg/git": "1.6.1",
18
- "@vltpkg/output": "1.6.1",
19
- "@vltpkg/package-json": "1.6.1",
20
- "@vltpkg/pick-manifest": "1.6.1",
21
- "@vltpkg/registry-client": "1.6.1",
22
- "@vltpkg/spec": "1.6.1",
23
- "@vltpkg/tar": "1.6.1",
24
- "@vltpkg/types": "1.6.1",
25
- "@vltpkg/workspaces": "1.6.1",
26
- "@vltpkg/xdg": "1.6.1",
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.1",
35
- "@vltpkg/vlt-json": "1.6.1",
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",