@vltpkg/package-info 1.3.0 → 1.3.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
@@ -17,10 +17,16 @@ export declare const delimiter = "~";
17
17
  * `dist.tarball` relative to the registry base.
18
18
  */
19
19
  export declare const VLT_PACKUMENT_MIME = "application/vnd.vlt.packument-v1+json";
20
+ /**
21
+ * {@link VLT_PACKUMENT_MIME} with each `dist.tarball` reduced to the
22
+ * tarball's basename (`foo-1.0.0.tgz`), which resolves against the
23
+ * package's `{registry}{name}/-/` directory.
24
+ */
25
+ export declare const VLT_PACKUMENT_V2_MIME = "application/vnd.vlt.packument-v2+json";
20
26
  /**
21
27
  * Accept header for packument requests. Prefers vlt's abbreviated
22
- * packument and falls back to the full one on registries that do not
23
- * know the type. See `PackageInfoClient.#fetchPackument`.
28
+ * packument, v2 over v1, and falls back to the full one on registries
29
+ * that know neither. See `PackageInfoClient.#fetchPackument`.
24
30
  *
25
31
  * The trailing wildcard range carries an explicit `q=0.1` so that it stays
26
32
  * below `application/json`. A media range with no `q` defaults to `q=1.0`
@@ -30,7 +36,7 @@ export declare const VLT_PACKUMENT_MIME = "application/vnd.vlt.packument-v1+json
30
36
  * only so a registry that rejects what it cannot satisfy exactly still
31
37
  * has something to match.
32
38
  */
33
- export declare const PACKUMENT_ACCEPT = "application/vnd.vlt.packument-v1+json; q=1.0, application/json; q=0.8, */*; q=0.1";
39
+ export declare const PACKUMENT_ACCEPT = "application/vnd.vlt.packument-v2+json; q=1.0, application/vnd.vlt.packument-v1+json; q=0.9, application/json; q=0.8, */*; q=0.1";
34
40
  export type Resolution = {
35
41
  resolved: string;
36
42
  integrity?: Integrity;
package/dist/index.js CHANGED
@@ -30,10 +30,16 @@ export const delimiter = '~';
30
30
  * `dist.tarball` relative to the registry base.
31
31
  */
32
32
  export const VLT_PACKUMENT_MIME = 'application/vnd.vlt.packument-v1+json';
33
+ /**
34
+ * {@link VLT_PACKUMENT_MIME} with each `dist.tarball` reduced to the
35
+ * tarball's basename (`foo-1.0.0.tgz`), which resolves against the
36
+ * package's `{registry}{name}/-/` directory.
37
+ */
38
+ export const VLT_PACKUMENT_V2_MIME = 'application/vnd.vlt.packument-v2+json';
33
39
  /**
34
40
  * Accept header for packument requests. Prefers vlt's abbreviated
35
- * packument and falls back to the full one on registries that do not
36
- * know the type. See `PackageInfoClient.#fetchPackument`.
41
+ * packument, v2 over v1, and falls back to the full one on registries
42
+ * that know neither. See `PackageInfoClient.#fetchPackument`.
37
43
  *
38
44
  * The trailing wildcard range carries an explicit `q=0.1` so that it stays
39
45
  * below `application/json`. A media range with no `q` defaults to `q=1.0`
@@ -43,7 +49,7 @@ export const VLT_PACKUMENT_MIME = 'application/vnd.vlt.packument-v1+json';
43
49
  * only so a registry that rejects what it cannot satisfy exactly still
44
50
  * has something to match.
45
51
  */
46
- export const PACKUMENT_ACCEPT = `${VLT_PACKUMENT_MIME}; q=1.0, application/json; q=0.8, */*; q=0.1`;
52
+ export const PACKUMENT_ACCEPT = `${VLT_PACKUMENT_V2_MIME}; q=1.0, ${VLT_PACKUMENT_MIME}; q=0.9, application/json; q=0.8, */*; q=0.1`;
47
53
  // the maximum duration of a manifest cache file
48
54
  const manifestCacheMaxAge = 5 * 60 * 1000;
49
55
  /**
@@ -94,7 +100,7 @@ export class PackageInfoClient {
94
100
  packageJson;
95
101
  monorepo;
96
102
  #trustedIntegrities = new Map();
97
- // `${registry}${name}` of every packument served as VLT_PACKUMENT_MIME
103
+ // `${registry}${name}` of every packument served as a vlt packument type
98
104
  #vltPackuments = new Set();
99
105
  #manifestCacheMinAge = Date.now() - manifestCacheMaxAge;
100
106
  #cachePath;
@@ -179,11 +185,12 @@ export class PackageInfoClient {
179
185
  return this.#tarPoolPromise;
180
186
  }
181
187
  /**
182
- * The absolute URL of a version's Brotli (`.tar.br`) tarball, or
183
- * undefined when the registry advertised none, advertised one this
184
- * client does not use (see {@link brotliTarballUrl}), or
185
- * `--no-brotli-tarballs` is set. `dist.tarball` is already absolute
186
- * here -- see `absolutizeTarballs`.
188
+ * A version's Brotli (`.tar.br`) alternate: its absolute URL, plus its
189
+ * hash if the registry sent one. Returns undefined if the version has no
190
+ * alternate, if it has one this client does not use (see
191
+ * {@link brotliTarballUrl}), or if `--no-brotli-tarballs` is set.
192
+ * `dist.tarball` is already absolute by this point; see
193
+ * `absolutizeTarballs`.
187
194
  */
188
195
  #brotliTarball(tarball, alternates) {
189
196
  if (this.options['brotli-tarballs'] === false)
@@ -269,10 +276,17 @@ export class PackageInfoClient {
269
276
  // below has to be told; gzip and raw tar are sniffed.
270
277
  const format = tarballFormat(r.resolved);
271
278
  // git tarballs keep the unpack path
272
- const hex = f.type === 'registry' && this.#storeLinker !== 'unpack' ?
273
- integrityHex(r.integrity)
274
- : undefined;
279
+ const storeOn = f.type === 'registry' && this.#storeLinker !== 'unpack';
275
280
  const copy = this.#storeLinker === 'copy' || installScripts;
281
+ // If we already have a hash, that is the store key. Some
282
+ // tarballs arrive without one: a `.tar.br`, or anything a
283
+ // registry serves with no `dist.integrity`. For those, read the
284
+ // hash off the cache entry, which recorded it when the bytes
285
+ // were verified. Installs that do have a hash skip all of this,
286
+ // so a store hit still never builds a registry client.
287
+ const hex = !storeOn ? undefined
288
+ : r.integrity ? integrityHex(r.integrity)
289
+ : integrityHex((await this.getRegistryClient()).cachedIntegrity(r.resolved));
276
290
  if (hex) {
277
291
  if (debug.enabled && !this.#storeHitRateLogged) {
278
292
  this.#storeHitRateLogged = true;
@@ -308,12 +322,13 @@ export class PackageInfoClient {
308
322
  await pool.unpack(cached.body, target, format);
309
323
  logRequest(r.resolved, 'cache');
310
324
  r.integrity ??= cached.integrity;
311
- // a warm install writes nothing to the cache, so queue the
312
- // store miss here or an existing cache never converges,
313
- // and a gzipped body with no store link, to unzip it.
314
- // (a brotli body is never rewritten: cache-unzip only
315
- // un-gzips, and leaving it compressed keeps the cache small.)
316
- if (hex || cached.gzip) {
325
+ // A warm install writes nothing to the cache, so queue the
326
+ // store miss here. Without this an existing cache would
327
+ // never catch up. Also queue a gzipped body that did not
328
+ // come from the store, so it gets un-gzipped. A brotli body
329
+ // is left alone: cache-unzip only handles gzip, and keeping
330
+ // it compressed keeps the cache small.
331
+ if (storeOn || cached.gzip) {
317
332
  rc.queueForStore(cached.key, r.integrity);
318
333
  }
319
334
  return r;
@@ -903,7 +918,8 @@ export class PackageInfoClient {
903
918
  }
904
919
  async #fetchPackument(spec, options, pakuURL, useCache) {
905
920
  // Request vlt's abbreviated packument, falling back to the full one:
906
- // accept: application/vnd.vlt.packument-v1+json; q=1.0,
921
+ // accept: application/vnd.vlt.packument-v2+json; q=1.0,
922
+ // application/vnd.vlt.packument-v1+json; q=0.9,
907
923
  // application/json; q=0.8, */*; q=0.1
908
924
  //
909
925
  // npm's corgi (`application/vnd.npm.install-v1+json`) is never
@@ -952,12 +968,16 @@ export class PackageInfoClient {
952
968
  throw er;
953
969
  }
954
970
  const { registry, name } = spec.final;
955
- if (response.contentType.startsWith(VLT_PACKUMENT_MIME)) {
971
+ const { contentType } = response;
972
+ const v2 = contentType.startsWith(VLT_PACKUMENT_V2_MIME);
973
+ if (v2 || contentType.startsWith(VLT_PACKUMENT_MIME)) {
956
974
  this.#vltPackuments.add(`${registry}${name}`);
957
975
  }
958
976
  /* c8 ignore next - registry specs always have a registry */
959
- if (registry)
960
- absolutizeTarballs(paku, registry);
977
+ if (registry) {
978
+ const base = registry.endsWith('/') ? registry : registry + '/';
979
+ absolutizeTarballs(paku, v2 ? `${base}${name}/-/` : base);
980
+ }
961
981
  return paku;
962
982
  }
963
983
  async resolve(spec, options = {}) {
@@ -1007,7 +1027,19 @@ export class PackageInfoClient {
1007
1027
  // registry that advertised it always sends -- hence `required`.
1008
1028
  const brotli = this.#brotliTarball(tarball, alternates);
1009
1029
  const r = brotli ?
1010
- { resolved: brotli, spec, digestRequired: true }
1030
+ {
1031
+ resolved: brotli.tarball,
1032
+ spec,
1033
+ // Pin the alternate's own hash if the registry sent
1034
+ // one. That also means we can look the package up in
1035
+ // the global store before downloading it. If there is
1036
+ // no hash, the Repr-Digest header is the only check we
1037
+ // get, so require it instead of treating it as
1038
+ // optional.
1039
+ ...(brotli.integrity ?
1040
+ { integrity: brotli.integrity }
1041
+ : { digestRequired: true }),
1042
+ }
1011
1043
  : { resolved: tarball, integrity, signatures, spec };
1012
1044
  if (!brotli &&
1013
1045
  !integrity &&
@@ -1106,12 +1138,12 @@ export class PackageInfoClient {
1106
1138
  return er;
1107
1139
  }
1108
1140
  }
1109
- // vlt packuments carry dist.tarball relative to the registry base
1110
- // (`foo/-/foo-1.0.0.tgz`), the form conventionalRegistryTarball builds.
1141
+ // vlt packuments carry dist.tarball relative to `base`: the registry base
1142
+ // for v1 (`foo/-/foo-1.0.0.tgz`, the form conventionalRegistryTarball
1143
+ // builds), the package's `/-/` directory for v2 (`foo-1.0.0.tgz`).
1111
1144
  // Nothing downstream sees a relative URL: the manifest cache, the graph
1112
1145
  // and the lockfile all get the absolute one.
1113
- const absolutizeTarballs = (paku, registry) => {
1114
- const base = registry.endsWith('/') ? registry : registry + '/';
1146
+ const absolutizeTarballs = (paku, base) => {
1115
1147
  for (const { dist } of Object.values(paku.versions)) {
1116
1148
  const tarball = dist?.tarball;
1117
1149
  if (tarball && !/^[a-z][a-z0-9+.-]*:/i.test(tarball)) {
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.0",
4
+ "version": "1.3.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.3.0",
17
- "@vltpkg/git": "1.3.0",
18
- "@vltpkg/output": "1.3.0",
19
- "@vltpkg/package-json": "1.3.0",
20
- "@vltpkg/pick-manifest": "1.3.0",
21
- "@vltpkg/registry-client": "1.3.0",
22
- "@vltpkg/spec": "1.3.0",
23
- "@vltpkg/tar": "1.3.0",
24
- "@vltpkg/types": "1.3.0",
25
- "@vltpkg/workspaces": "1.3.0",
26
- "@vltpkg/xdg": "1.3.0",
16
+ "@vltpkg/error-cause": "1.3.2",
17
+ "@vltpkg/git": "1.3.2",
18
+ "@vltpkg/output": "1.3.2",
19
+ "@vltpkg/package-json": "1.3.2",
20
+ "@vltpkg/pick-manifest": "1.3.2",
21
+ "@vltpkg/registry-client": "1.3.2",
22
+ "@vltpkg/spec": "1.3.2",
23
+ "@vltpkg/tar": "1.3.2",
24
+ "@vltpkg/types": "1.3.2",
25
+ "@vltpkg/workspaces": "1.3.2",
26
+ "@vltpkg/xdg": "1.3.2",
27
27
  "ssri": "^13.0.0",
28
28
  "tar": "^7.5.2"
29
29
  },
@@ -32,8 +32,8 @@
32
32
  "@types/node": "^22.19.2",
33
33
  "@types/pacote": "^11.1.8",
34
34
  "@vltpkg/benchmark": "0.0.0",
35
- "@vltpkg/cache-unzip": "1.3.0",
36
- "@vltpkg/vlt-json": "1.3.0",
35
+ "@vltpkg/cache-unzip": "1.3.2",
36
+ "@vltpkg/vlt-json": "1.3.2",
37
37
  "eslint": "^9.39.1",
38
38
  "pacote": "^21.0.4",
39
39
  "prettier": "^3.7.4",