@vltpkg/types 1.3.0 → 1.3.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.
package/dist/index.d.ts CHANGED
@@ -35,14 +35,22 @@ export type Dist = {
35
35
  * reference relative to this `dist`'s `tarball` (e.g. the bare filename
36
36
  * `foo-1.2.3.tar.br`), resolved with `new URL(entry.tarball, tarball)`.
37
37
  *
38
- * An alternate is a *different artifact*, not a different encoding of the
39
- * same bytes: it carries no `integrity` here and hashes differently from
40
- * the `.tgz`. A client that downloads one pins that artifact's own hash,
41
- * taken from the tarball response's RFC 9530 `Repr-Digest`.
38
+ * An alternate is a different artifact, not a re-encoding of the same
39
+ * bytes. It hashes differently from the `.tgz`, so `dist.integrity` does
40
+ * not describe it.
41
+ *
42
+ * The `integrity` field here is the alternate's own hash. It is optional,
43
+ * because a hash does not compress and a registry may prefer to keep
44
+ * packuments small. If a registry does send it, the client pins it like
45
+ * any other integrity, and can look the package up in the global store
46
+ * without downloading anything first. If it does not, the client verifies
47
+ * the download against the tarball response's RFC 9530 `Repr-Digest`
48
+ * header and learns the hash from there.
42
49
  */
43
50
  alternates?: {
44
51
  kind: string;
45
52
  tarball: string;
53
+ integrity?: Integrity;
46
54
  }[];
47
55
  };
48
56
  /** An object used to mark some peerDeps as optional */
@@ -455,7 +463,13 @@ export declare const brotliTarballName: (tgz: string) => string;
455
463
  * those derivations sound -- and costs an unusual reference the
456
464
  * optimization rather than the install.
457
465
  */
458
- export declare const brotliTarballUrl: (tarball: string | undefined, alternates: Dist["alternates"]) => string | undefined;
466
+ export type BrotliAlternate = {
467
+ /** The absolute URL of the `.tar.br`. */
468
+ tarball: string;
469
+ /** The alternate's own hash, if the registry sent one. */
470
+ integrity?: Integrity;
471
+ };
472
+ export declare const brotliTarballUrl: (tarball: string | undefined, alternates: Dist["alternates"]) => BrotliAlternate | undefined;
459
473
  export declare const keyIDRE: RegExp;
460
474
  export declare const isKeyID: (k: unknown) => k is KeyID;
461
475
  export declare const asKeyID: (k: unknown) => KeyID;
package/dist/index.js CHANGED
@@ -566,23 +566,6 @@ export const tarballFormat = (url) => {
566
566
  * and a different extension.
567
567
  */
568
568
  export const brotliTarballName = (tgz) => tgz.replace(/\.tgz$/, BROTLI_TARBALL_EXT);
569
- /**
570
- * The absolute URL of a version's Brotli (`.tar.br`) tarball, from the
571
- * `tar.br` entry in its `dist.alternates` -- but only when that entry
572
- * resolves to the `.tgz`'s own sibling, i.e. {@link brotliTarballName} of
573
- * `tarball`. Anything else reads as no alternate at all.
574
- *
575
- * `alternates[].tarball` is a reference relative to `dist.tarball`, and
576
- * the protocol lets a registry point it anywhere. This client uses only
577
- * the conventional name, because two things downstream re-derive it and
578
- * both would otherwise be wrong: the format is read back off the URL
579
- * suffix (brotli bytes carry no signature to sniff), and a lockfile node
580
- * spends a single flag bit instead of a second URL, rebuilding the
581
- * address from the `.tgz` by this same convention. Narrowing here, at
582
- * the one point where the alternate is chosen, is what makes both of
583
- * those derivations sound -- and costs an unusual reference the
584
- * optimization rather than the install.
585
- */
586
569
  export const brotliTarballUrl = (tarball, alternates) => {
587
570
  if (!tarball)
588
571
  return undefined;
@@ -591,9 +574,17 @@ export const brotliTarballUrl = (tarball, alternates) => {
591
574
  return undefined;
592
575
  try {
593
576
  const href = new URL(entry.tarball, tarball).href;
594
- return href === new URL(brotliTarballName(tarball)).href ?
595
- href
596
- : undefined;
577
+ if (href !== new URL(brotliTarballName(tarball)).href) {
578
+ return undefined;
579
+ }
580
+ // Ignore a hash we cannot parse. Pinning it would fail every check,
581
+ // so it is better to fall back to the Repr-Digest.
582
+ return {
583
+ tarball: href,
584
+ ...(isIntegrity(entry.integrity) && {
585
+ integrity: entry.integrity,
586
+ }),
587
+ };
597
588
  /* c8 ignore start - a malformed reference just means no brotli */
598
589
  }
599
590
  catch {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/types",
3
3
  "description": "definitions for some of vlt's core types",
4
- "version": "1.3.0",
4
+ "version": "1.3.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,10 +13,10 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/dep-id": "1.3.0",
17
- "@vltpkg/error-cause": "1.3.0",
18
- "@vltpkg/semver": "1.3.0",
19
- "@vltpkg/spec": "1.3.0"
16
+ "@vltpkg/dep-id": "1.3.1",
17
+ "@vltpkg/error-cause": "1.3.1",
18
+ "@vltpkg/semver": "1.3.1",
19
+ "@vltpkg/spec": "1.3.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@eslint/js": "^9.39.1",