@vltpkg/package-info 1.7.0 → 1.8.1

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 (2) hide show
  1. package/dist/index.js +43 -5
  2. package/package.json +14 -14
package/dist/index.js CHANGED
@@ -83,8 +83,9 @@ const SELECTION_OPTIONS = [
83
83
  // the maximum duration of a manifest cache file
84
84
  const manifestCacheMaxAge = 5 * 60 * 1000;
85
85
  /**
86
- * There is no default registry. Anything that needs to build a registry
87
- * URL fails with a `ECONFIG` error when none has been configured.
86
+ * Anything that needs to build a registry URL fails with a `ECONFIG`
87
+ * error when the spec has no registry (e.g. `default-registry-alias`
88
+ * names an alias with no URL).
88
89
  */
89
90
  const noRegistryError = (spec) => error('No registry configured to resolve this spec. Set "registry" in ' +
90
91
  'vlt.json, pass --registry, or run `vlt login --registry=<url>`. ' +
@@ -206,6 +207,9 @@ export class PackageInfoClient {
206
207
  // `${registry}${name}@${range}` for every spec that chose a version and
207
208
  // `${registry}${name}@${version}` for the version itself.
208
209
  #resolvedManifests = new Map();
210
+ // what each of those is cached as, taken when manifest() first hands it
211
+ // out: callers change the object after that
212
+ #resolvedJson = new WeakMap();
209
213
  /**
210
214
  * The resolve requests in flight against each registry, with when the
211
215
  * registry last delivered a record: the grace a lookup gives the stream
@@ -855,6 +859,9 @@ export class PackageInfoClient {
855
859
  if (options.arch) {
856
860
  extra += `${delimiter}arch:${options.arch}`;
857
861
  }
862
+ if (options.libc) {
863
+ extra += `${delimiter}libc:${options.libc}`;
864
+ }
858
865
  return encodeURIComponent(`${spec.registry ?? ''}${delimiter}${spec}${extra}`);
859
866
  }
860
867
  /**
@@ -903,6 +910,25 @@ export class PackageInfoClient {
903
910
  // failing to write the manifest cache is not an install failure
904
911
  }
905
912
  }
913
+ /**
914
+ * Cache a manifest the resolve stream delivered, as fromPackument caches
915
+ * a picked one, unless the file on disk is still fresh.
916
+ */
917
+ #cacheResolved(cachePath, mani) {
918
+ let json = this.#resolvedJson.get(mani);
919
+ if (json === undefined) {
920
+ // a resolve record is a vlt manifest
921
+ json = JSON.stringify({ ...mani, __VLT_PACKUMENT: true });
922
+ this.#resolvedJson.set(mani, json);
923
+ }
924
+ if (!cachePath || this.#manifestWritePaths.has(cachePath))
925
+ return;
926
+ this.#manifestWritePaths.add(cachePath);
927
+ const write = () => this.#writeManifestCache(cachePath, json);
928
+ this.#inBackground(stat(cachePath).then(st => st.mtimeMs < this.#manifestCacheMinAge ?
929
+ write()
930
+ : undefined, write));
931
+ }
906
932
  async tarball(spec, options = {}) {
907
933
  if (typeof spec === 'string')
908
934
  spec = Spec.parse(spec, this.options);
@@ -1165,7 +1191,8 @@ export class PackageInfoClient {
1165
1191
  }
1166
1192
  /**
1167
1193
  * The manifest for `key` from an in-flight resolve, or from `fetch` when
1168
- * the resolve is not carrying it. Undefined when nothing is in flight.
1194
+ * the resolve is not carrying it. Undefined when the key has not arrived
1195
+ * and nothing is in flight.
1169
1196
  *
1170
1197
  * A stream that is delivering gets a short grace to carry the key, since
1171
1198
  * its records come in the order the build asks for them; one that has
@@ -1176,6 +1203,11 @@ export class PackageInfoClient {
1176
1203
  * fails while the stream is still open waits for the stream's verdict.
1177
1204
  */
1178
1205
  async #awaitResolved(registry, key, fetch) {
1206
+ // a record that landed since manifest() looked, on a stream that may
1207
+ // have settled since
1208
+ const landed = this.#resolvedManifests.get(key);
1209
+ if (landed)
1210
+ return landed;
1179
1211
  const inflight = this.#resolveInflight.get(registry);
1180
1212
  if (!inflight?.requests.size)
1181
1213
  return undefined;
@@ -1254,8 +1286,10 @@ export class PackageInfoClient {
1254
1286
  const resolveKey = `${f.registry ?? ''}${f.name}@${f.bareSpec}`;
1255
1287
  if (!selecting) {
1256
1288
  const resolved = this.#resolvedManifests.get(resolveKey);
1257
- if (resolved)
1289
+ if (resolved) {
1290
+ this.#cacheResolved(this._manifestCachePath(spec, options), resolved);
1258
1291
  return resolved;
1292
+ }
1259
1293
  }
1260
1294
  // Check if manifest is cached, if so just return it earlier
1261
1295
  const cachePath = this._manifestCachePath(spec, options);
@@ -1309,8 +1343,12 @@ export class PackageInfoClient {
1309
1343
  // key, so it gets a moment before the packument is fetched too
1310
1344
  if (!selecting && f.registry) {
1311
1345
  const resolved = await this.#awaitResolved(f.registry, resolveKey, fromPackument);
1312
- if (resolved)
1346
+ if (resolved) {
1347
+ // the stream's answer; fromPackument caches its own
1348
+ if (resolved === this.#resolvedManifests.get(resolveKey))
1349
+ this.#cacheResolved(cachePath, resolved);
1313
1350
  return resolved;
1351
+ }
1314
1352
  }
1315
1353
  return fromPackument();
1316
1354
  }
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.7.0",
4
+ "version": "1.8.1",
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.7.0",
17
- "@vltpkg/git": "1.7.0",
18
- "@vltpkg/output": "1.7.0",
19
- "@vltpkg/package-json": "1.7.0",
20
- "@vltpkg/pick-manifest": "1.7.0",
21
- "@vltpkg/registry-client": "1.7.0",
22
- "@vltpkg/spec": "1.7.0",
23
- "@vltpkg/tar": "1.7.0",
24
- "@vltpkg/types": "1.7.0",
25
- "@vltpkg/workspaces": "1.7.0",
26
- "@vltpkg/xdg": "1.7.0",
16
+ "@vltpkg/error-cause": "1.8.1",
17
+ "@vltpkg/git": "1.8.1",
18
+ "@vltpkg/output": "1.8.1",
19
+ "@vltpkg/package-json": "1.8.1",
20
+ "@vltpkg/pick-manifest": "1.8.1",
21
+ "@vltpkg/registry-client": "1.8.1",
22
+ "@vltpkg/spec": "1.8.1",
23
+ "@vltpkg/tar": "1.8.1",
24
+ "@vltpkg/types": "1.8.1",
25
+ "@vltpkg/workspaces": "1.8.1",
26
+ "@vltpkg/xdg": "1.8.1",
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.7.0",
35
- "@vltpkg/vlt-json": "1.7.0",
34
+ "@vltpkg/cache-unzip": "1.8.1",
35
+ "@vltpkg/vlt-json": "1.8.1",
36
36
  "eslint": "^10.14.0",
37
37
  "pacote": "^21.0.4",
38
38
  "prettier": "^3.7.4",