@vltpkg/package-info 1.3.2 → 1.3.3

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
@@ -89,6 +89,12 @@ export type PackageInfoClientRequestOptions = PickManifestOptions & RegistryClie
89
89
  * keyed by URL alone, so the two representations never mix.
90
90
  */
91
91
  full?: boolean;
92
+ /**
93
+ * A moving selector whose packument is still within max-age is
94
+ * served from it and revalidated after exit, not before use. Pinned
95
+ * specs are unaffected.
96
+ */
97
+ backgroundRevalidate?: boolean;
92
98
  };
93
99
  export type PackageInfoClientExtractOptions = PackageInfoClientRequestOptions & {
94
100
  integrity?: Integrity;
package/dist/index.js CHANGED
@@ -63,11 +63,16 @@ const noRegistryError = (spec) => error('No registry configured to resolve this
63
63
  * A selector that can point at a different version tomorrow: a dist tag,
64
64
  * or a range matching anything (`*`, empty string). Manifest results for
65
65
  * these are not cached to disk, and packument requests for them force a
66
- * revalidation of the registry client's cache entry.
66
+ * revalidation of the registry client's cache entry, in the background
67
+ * with the `backgroundRevalidate` option.
67
68
  *
68
69
  * Takes a *final* spec (`spec.final`), same as `pickManifest` sees.
69
70
  */
70
71
  const isMovingSelector = (f) => !!(f.distTag || f.range?.isAny);
72
+ /** The registry client's `forceRevalidate` for a packument request. */
73
+ const revalidateMode = (f, options) => !isMovingSelector(f) ? undefined
74
+ : options.backgroundRevalidate ? 'background'
75
+ : true;
71
76
  /**
72
77
  * A selector that cannot land on a prerelease, and so can be answered from
73
78
  * the registry's `?stable` packument.
@@ -117,8 +122,8 @@ export class PackageInfoClient {
117
122
  // In-flight coalescing key is `${registry}${name}` — no representation
118
123
  // component. Safe only because every caller requests the same full
119
124
  // packument (see #fetchPackument). The one thing that does vary per
120
- // caller is forceRevalidate, so record it and let a moving selector
121
- // reuse a forced promise but never a non-forced one (see packument()).
125
+ // caller is forceRevalidate, so record how hard it revalidates and
126
+ // never let a request ride a weaker one (see #packument()).
122
127
  #packumentPromises = new Map();
123
128
  // unique temp file names for atomic manifest cache writes
124
129
  #manifestWriteRandom = randomBytes(6).toString('hex');
@@ -883,26 +888,30 @@ export class PackageInfoClient {
883
888
  // #fetchPackument).
884
889
  const fullKey = `${registry}${name}`;
885
890
  const packumentKey = stable ? `${fullKey}?stable` : fullKey;
886
- const forced = isMovingSelector(f);
891
+ // 0 pinned, 1 background, 2 forced
892
+ const mode = revalidateMode(f, options);
893
+ const rank = mode === true ? 2
894
+ : mode ? 1
895
+ : 0;
887
896
  const inflight = this.#packumentPromises.get(packumentKey) ??
888
897
  // the full packument is a superset of the stable one, so an
889
898
  // in-flight full request answers a stable ask too, and a package
890
899
  // wanted both ways is still fetched once
891
900
  (stable ? this.#packumentPromises.get(fullKey) : undefined);
892
- // a moving selector must not ride along on a non-forced request:
893
- // that one can settle to a fresh-but-stale cache hit, which is
894
- // exactly what forceRevalidate exists to avoid. the other
895
- // direction is fine -- a forced result is never staler.
896
- // costs at most one extra concurrent GET for the same packument
897
- // when both shapes are asked for at once.
898
- if (inflight && (!forced || inflight.forced))
901
+ // a request must not ride along on a weaker one: that can settle
902
+ // to a fresh-but-stale cache hit, which is exactly what
903
+ // forceRevalidate exists to avoid. the other direction is fine --
904
+ // a stronger result is never staler.
905
+ // costs at most one extra concurrent GET per stronger shape
906
+ // asked for at once.
907
+ if (inflight && inflight.rank >= rank)
899
908
  return inflight.promise;
900
909
  // `?stable` is a distinct URL, so it gets its own disk cache entry
901
910
  const pakuURL = new URL(stable ? `${name}?stable` : name, registry);
902
911
  const promise = this.#fetchPackument(spec, options, pakuURL);
903
- const record = { promise, forced };
912
+ const record = { promise, rank };
904
913
  this.#packumentPromises.set(packumentKey, record);
905
- // Clean up once settled so we don't leak memory, unless a forced
914
+ // Clean up once settled so we don't leak memory, unless a stronger
906
915
  // request has since taken the slot over.
907
916
  // Use .then/.catch instead of .finally to avoid creating
908
917
  // an unhandled rejection from the derived promise.
@@ -937,6 +946,7 @@ export class PackageInfoClient {
937
946
  // The RegistryClient disk cache key is method + URL only, so every
938
947
  // packument request must use this same accept header, and the SWR
939
948
  // revalidation child re-requests the representation it was given.
949
+ const mode = revalidateMode(spec.final, options);
940
950
  const response = await (await this.getRegistryClient()).request(pakuURL, {
941
951
  headers: {
942
952
  accept: options.full ? 'application/json' : PACKUMENT_ACCEPT,
@@ -944,12 +954,11 @@ export class PackageInfoClient {
944
954
  ...(useCache === false || options.full ?
945
955
  { useCache: false }
946
956
  : {}),
947
- // costs a conditional GET per moving selector on an otherwise warm
948
- // cache, install included. 304s are cheap but not free; the
949
- // alternative is serving a dist tag that moved (#1656).
950
- ...(isMovingSelector(spec.final) ?
951
- { forceRevalidate: true }
952
- : {}),
957
+ // a moving selector pays a conditional GET before use, so a moved
958
+ // dist tag is seen at once (#1656). with backgroundRevalidate a
959
+ // packument still within max-age is served and revalidated after
960
+ // exit instead.
961
+ ...(mode === undefined ? {} : { forceRevalidate: mode }),
953
962
  });
954
963
  if (response.statusCode !== 200) {
955
964
  throw this.#resolveError(spec, options, `failed to fetch packument: ${registryErrorMessage(response)}`, {
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.2",
4
+ "version": "1.3.3",
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.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",
16
+ "@vltpkg/error-cause": "1.3.3",
17
+ "@vltpkg/git": "1.3.3",
18
+ "@vltpkg/output": "1.3.3",
19
+ "@vltpkg/package-json": "1.3.3",
20
+ "@vltpkg/pick-manifest": "1.3.3",
21
+ "@vltpkg/registry-client": "1.3.3",
22
+ "@vltpkg/spec": "1.3.3",
23
+ "@vltpkg/tar": "1.3.3",
24
+ "@vltpkg/types": "1.3.3",
25
+ "@vltpkg/workspaces": "1.3.3",
26
+ "@vltpkg/xdg": "1.3.3",
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.2",
36
- "@vltpkg/vlt-json": "1.3.2",
35
+ "@vltpkg/cache-unzip": "1.3.3",
36
+ "@vltpkg/vlt-json": "1.3.3",
37
37
  "eslint": "^9.39.1",
38
38
  "pacote": "^21.0.4",
39
39
  "prettier": "^3.7.4",