@vltpkg/package-info 1.3.7 → 1.4.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.
package/README.md CHANGED
@@ -39,20 +39,23 @@ const { resolved, integrity } = await resolve('bar@latest')
39
39
 
40
40
  ## Global store
41
41
 
42
- With the `store-linker` option set to `auto`, `hardlink` or `copy`,
43
- `extract()` places a registry package from its global store entry
44
- (`<storeRoot>/<integrity hex>`, `storeRoot` defaults to
42
+ With the `store-linker` option set to `auto`, `hardlink`, `clone` or
43
+ `copy`, `extract()` places a registry package from its global store
44
+ entry (`<storeRoot>/<integrity hex>`, `storeRoot` defaults to
45
45
  `<cache>/store/v1`) when there is one. On a miss it unpacks the cached
46
46
  tarball as usual and queues it for the background child, so the next
47
47
  install finds it in the global store. Missing or unknown
48
48
  `store-linker` means `unpack`. The vlt CLI defaults to `auto`, which
49
- it resolves to `unpack` on platforms other than Linux, so `extract()`
50
- only ever sees `auto` from the CLI on Linux. A gzipped cached tarball
51
- that is not store-linked (`unpack`, git or remote tarballs, no sha512
49
+ it resolves to `clone` on macOS with a Node that can load `node:ffi`
50
+ and to `unpack` on other platforms than Linux, so `extract()` only
51
+ ever sees `auto` from the CLI on Linux. A gzipped cached tarball that
52
+ is not store-linked (`unpack`, git or remote tarballs, no sha512
52
53
  integrity) is queued too, so the child un-gzips it.
53
54
 
54
55
  Packages with install scripts are linked too; reify copies them in
55
- place right before their scripts run.
56
+ place right before their scripts run. A clone is copy-on-write, so
57
+ with `clone` they are cloned like any other package, and reify finds
58
+ nothing to copy.
56
59
 
57
60
  A store link logs its request as `store`, a copy from the store as
58
61
  `cache`. Both also return `manifest` (the package.json as JSON text,
package/dist/index.d.ts CHANGED
@@ -114,6 +114,13 @@ export declare class PackageInfoClient {
114
114
  options: PackageInfoClientOptions;
115
115
  packageJson: PackageJson;
116
116
  monorepo?: Monorepo;
117
+ /**
118
+ * Wind the client down: abort open resolve streams, settle background
119
+ * work (manifest cache writes, capabilities, hedges), drain the registry
120
+ * client (in-flight requests, cache writes). Await before removing the
121
+ * cache dir or exiting.
122
+ */
123
+ drain(): Promise<void>;
117
124
  getRegistryClient(): Promise<RegistryClient>;
118
125
  /**
119
126
  * The vlt extensions `registry` serves, from its
package/dist/index.js CHANGED
@@ -120,7 +120,12 @@ const isStableSelector = (f) => {
120
120
  return !range.isAny && !range.raw.includes('-');
121
121
  };
122
122
  // anything else, eg an unvalidated env value, means `unpack`
123
- const storeLinkers = new Set(['auto', 'hardlink', 'copy']);
123
+ const storeLinkers = new Set([
124
+ 'auto',
125
+ 'hardlink',
126
+ 'clone',
127
+ 'copy',
128
+ ]);
124
129
  // the hash a response answers for. a network body's is the hash of its
125
130
  // bytes: the registry client already checked it against the expected
126
131
  // hash, or recorded it when there was none, and memoized it, so this
@@ -159,13 +164,13 @@ export class PackageInfoClient {
159
164
  #cachePath;
160
165
  #storeRoot;
161
166
  #storeLinker;
162
- #storeHits = { link: 0, copy: 0 };
167
+ #storeHits = { link: 0, clone: 0, copy: 0 };
163
168
  #storeMisses = 0;
164
169
  #storeHitRateLogged = false;
165
170
  #logStoreHitRate = () => {
166
- const { link, copy } = this.#storeHits;
167
- const n = Math.max(1, link + copy + this.#storeMisses);
168
- debug('global store: linked=%d copied=%d missed=%d hit rate=%s%%', link, copy, this.#storeMisses, (((link + copy) / n) * 100).toFixed(1));
171
+ const { link, clone, copy } = this.#storeHits;
172
+ const n = Math.max(1, link + clone + copy + this.#storeMisses);
173
+ debug('global store: linked=%d cloned=%d copied=%d missed=%d hit rate=%s%%', link, clone, copy, this.#storeMisses, (((link + clone + copy) / n) * 100).toFixed(1));
169
174
  };
170
175
  // In-flight coalescing key is `${registry}${name}` — no representation
171
176
  // component. Safe only because every caller requests the same full
@@ -209,6 +214,37 @@ export class PackageInfoClient {
209
214
  #resolveWaiters = new Map();
210
215
  #registryClientPromise;
211
216
  #tarPoolPromise;
217
+ // fire-and-forget work, settled by drain()
218
+ #background = new Set();
219
+ #inBackground(p) {
220
+ const done = () => {
221
+ this.#background.delete(tracked);
222
+ };
223
+ const tracked = p.then(done, done);
224
+ this.#background.add(tracked);
225
+ }
226
+ /**
227
+ * Wind the client down: abort open resolve streams, settle background
228
+ * work (manifest cache writes, capabilities, hedges), drain the registry
229
+ * client (in-flight requests, cache writes). Await before removing the
230
+ * cache dir or exiting.
231
+ */
232
+ async drain() {
233
+ for (const [sent, owner] of this.#resolveOwners) {
234
+ this.#resolveOwners.delete(sent);
235
+ this.#resolveSent.delete(sent);
236
+ owner.controller.abort();
237
+ }
238
+ while (this.#background.size) {
239
+ await Promise.all(this.#background);
240
+ }
241
+ if (this.#registryClientPromise) {
242
+ await (await this.#registryClientPromise).drain();
243
+ }
244
+ /* c8 ignore next - work started while the cache flushed */
245
+ if (this.#background.size)
246
+ await this.drain();
247
+ }
212
248
  async getRegistryClient() {
213
249
  if (this.#registryClient)
214
250
  return this.#registryClient;
@@ -247,7 +283,7 @@ export class PackageInfoClient {
247
283
  if (!client) {
248
284
  // the registry client is built lazily, so the first caller starts it
249
285
  // and the document along with it, and asks optimistically meanwhile
250
- void this.capabilities(registry).catch(() => { });
286
+ this.#inBackground(this.capabilities(registry));
251
287
  return true;
252
288
  }
253
289
  const caps = peekCapabilities(client, registry);
@@ -296,10 +332,6 @@ export class PackageInfoClient {
296
332
  const linker = options['store-linker'];
297
333
  this.#storeLinker =
298
334
  linker && storeLinkers.has(linker) ? linker : 'unpack';
299
- // optionally create its cache directory if it doesn't exist
300
- void mkdir(pathResolve(this.#cachePath, 'package-info'), {
301
- recursive: true,
302
- }).catch(() => { });
303
335
  }
304
336
  async extract(spec, target, options = {}) {
305
337
  if (typeof spec === 'string')
@@ -356,6 +388,7 @@ export class PackageInfoClient {
356
388
  // git tarballs keep the unpack path
357
389
  const storeOn = f.type === 'registry' && this.#storeLinker !== 'unpack';
358
390
  const copy = this.#storeLinker === 'copy';
391
+ const clone = this.#storeLinker === 'clone';
359
392
  // If we already have a hash, that is the store key. Some
360
393
  // tarballs arrive without one: a `.tar.br`, or anything a
361
394
  // registry serves with no `dist.integrity`. For those, read the
@@ -370,12 +403,12 @@ export class PackageInfoClient {
370
403
  this.#storeHitRateLogged = true;
371
404
  process.once('beforeExit', this.#logStoreHitRate);
372
405
  }
373
- const linked = await pool.linkFromStore(pathResolve(this.#storeRoot, hex), target, { copy });
406
+ const linked = await pool.linkFromStore(pathResolve(this.#storeRoot, hex), target, { copy, clone });
374
407
  if (linked) {
375
408
  const { how, index } = linked;
376
409
  this.#storeHits[how]++;
377
410
  // a copy is no link: report it as a cache hit
378
- logRequest(r.resolved, how === 'link' ? 'store' : 'cache');
411
+ logRequest(r.resolved, how === 'copy' ? 'cache' : 'store');
379
412
  return {
380
413
  ...r,
381
414
  manifest: index.manifest,
@@ -910,6 +943,7 @@ export class PackageInfoClient {
910
943
  inflight.lastRecordAt = Date.now();
911
944
  const promise = this.#runResolve(registry, request, owner.controller.signal, inflight);
912
945
  inflight.requests.add(promise);
946
+ this.#inBackground(promise);
913
947
  // dropped once settled, so manifest() stops waiting on a request that
914
948
  // has already delivered everything it is going to
915
949
  const clear = () => {
@@ -1010,6 +1044,8 @@ export class PackageInfoClient {
1010
1044
  return early ?? (await fetch());
1011
1045
  debug('resolve hedge %s', key);
1012
1046
  const hedge = fetch();
1047
+ // stream may answer first; then nobody awaits the hedge
1048
+ this.#inBackground(hedge);
1013
1049
  const outcome = await Promise.race([
1014
1050
  arrival,
1015
1051
  settled,
@@ -1073,7 +1109,7 @@ export class PackageInfoClient {
1073
1109
  if (st.mtimeMs < this.#manifestCacheMinAge ||
1074
1110
  json.__VLT_MANIFEST_CACHE_TIMESTAMP !== undefined) {
1075
1111
  this.#manifestWritePaths.delete(cachePath);
1076
- void unlink(cachePath).catch(() => { });
1112
+ this.#inBackground(unlink(cachePath));
1077
1113
  throw new Error('manifest cache expired');
1078
1114
  }
1079
1115
  // the tarball digest stays required across processes
@@ -1097,7 +1133,7 @@ export class PackageInfoClient {
1097
1133
  if (cachePath && !this.#manifestWritePaths.has(cachePath)) {
1098
1134
  this.#manifestWritePaths.add(cachePath);
1099
1135
  const vlt = this.#vltPackuments.has(`${f.registry}${f.name}`);
1100
- void this.#writeManifestCache(cachePath, JSON.stringify(vlt ? { ...mani, __VLT_PACKUMENT: true } : mani));
1136
+ this.#inBackground(this.#writeManifestCache(cachePath, JSON.stringify(vlt ? { ...mani, __VLT_PACKUMENT: true } : mani)));
1101
1137
  }
1102
1138
  return mani;
1103
1139
  };
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.3.7",
4
+ "version": "1.4.0",
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.3.7",
17
- "@vltpkg/git": "1.3.7",
18
- "@vltpkg/output": "1.3.7",
19
- "@vltpkg/package-json": "1.3.7",
20
- "@vltpkg/pick-manifest": "1.3.7",
21
- "@vltpkg/registry-client": "1.3.7",
22
- "@vltpkg/spec": "1.3.7",
23
- "@vltpkg/tar": "1.3.7",
24
- "@vltpkg/types": "1.3.7",
25
- "@vltpkg/workspaces": "1.3.7",
26
- "@vltpkg/xdg": "1.3.7",
16
+ "@vltpkg/error-cause": "1.4.0",
17
+ "@vltpkg/git": "1.4.0",
18
+ "@vltpkg/output": "1.4.0",
19
+ "@vltpkg/package-json": "1.4.0",
20
+ "@vltpkg/pick-manifest": "1.4.0",
21
+ "@vltpkg/registry-client": "1.4.0",
22
+ "@vltpkg/spec": "1.4.0",
23
+ "@vltpkg/tar": "1.4.0",
24
+ "@vltpkg/types": "1.4.0",
25
+ "@vltpkg/workspaces": "1.4.0",
26
+ "@vltpkg/xdg": "1.4.0",
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.3.7",
35
- "@vltpkg/vlt-json": "1.3.7",
34
+ "@vltpkg/cache-unzip": "1.4.0",
35
+ "@vltpkg/vlt-json": "1.4.0",
36
36
  "eslint": "^9.39.1",
37
37
  "pacote": "^21.0.4",
38
38
  "prettier": "^3.7.4",