@vltpkg/package-info 1.3.1 → 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 +15 -3
- package/dist/index.js +51 -31
- package/package.json +14 -14
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
|
|
23
|
-
* know
|
|
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-
|
|
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;
|
|
@@ -83,6 +89,12 @@ export type PackageInfoClientRequestOptions = PickManifestOptions & RegistryClie
|
|
|
83
89
|
* keyed by URL alone, so the two representations never mix.
|
|
84
90
|
*/
|
|
85
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;
|
|
86
98
|
};
|
|
87
99
|
export type PackageInfoClientExtractOptions = PackageInfoClientRequestOptions & {
|
|
88
100
|
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
|
|
36
|
-
* know
|
|
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 = `${
|
|
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
|
/**
|
|
@@ -57,11 +63,16 @@ const noRegistryError = (spec) => error('No registry configured to resolve this
|
|
|
57
63
|
* A selector that can point at a different version tomorrow: a dist tag,
|
|
58
64
|
* or a range matching anything (`*`, empty string). Manifest results for
|
|
59
65
|
* these are not cached to disk, and packument requests for them force a
|
|
60
|
-
* 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.
|
|
61
68
|
*
|
|
62
69
|
* Takes a *final* spec (`spec.final`), same as `pickManifest` sees.
|
|
63
70
|
*/
|
|
64
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;
|
|
65
76
|
/**
|
|
66
77
|
* A selector that cannot land on a prerelease, and so can be answered from
|
|
67
78
|
* the registry's `?stable` packument.
|
|
@@ -94,7 +105,7 @@ export class PackageInfoClient {
|
|
|
94
105
|
packageJson;
|
|
95
106
|
monorepo;
|
|
96
107
|
#trustedIntegrities = new Map();
|
|
97
|
-
// `${registry}${name}` of every packument served as
|
|
108
|
+
// `${registry}${name}` of every packument served as a vlt packument type
|
|
98
109
|
#vltPackuments = new Set();
|
|
99
110
|
#manifestCacheMinAge = Date.now() - manifestCacheMaxAge;
|
|
100
111
|
#cachePath;
|
|
@@ -111,8 +122,8 @@ export class PackageInfoClient {
|
|
|
111
122
|
// In-flight coalescing key is `${registry}${name}` — no representation
|
|
112
123
|
// component. Safe only because every caller requests the same full
|
|
113
124
|
// packument (see #fetchPackument). The one thing that does vary per
|
|
114
|
-
// caller is forceRevalidate, so record
|
|
115
|
-
//
|
|
125
|
+
// caller is forceRevalidate, so record how hard it revalidates and
|
|
126
|
+
// never let a request ride a weaker one (see #packument()).
|
|
116
127
|
#packumentPromises = new Map();
|
|
117
128
|
// unique temp file names for atomic manifest cache writes
|
|
118
129
|
#manifestWriteRandom = randomBytes(6).toString('hex');
|
|
@@ -877,26 +888,30 @@ export class PackageInfoClient {
|
|
|
877
888
|
// #fetchPackument).
|
|
878
889
|
const fullKey = `${registry}${name}`;
|
|
879
890
|
const packumentKey = stable ? `${fullKey}?stable` : fullKey;
|
|
880
|
-
|
|
891
|
+
// 0 pinned, 1 background, 2 forced
|
|
892
|
+
const mode = revalidateMode(f, options);
|
|
893
|
+
const rank = mode === true ? 2
|
|
894
|
+
: mode ? 1
|
|
895
|
+
: 0;
|
|
881
896
|
const inflight = this.#packumentPromises.get(packumentKey) ??
|
|
882
897
|
// the full packument is a superset of the stable one, so an
|
|
883
898
|
// in-flight full request answers a stable ask too, and a package
|
|
884
899
|
// wanted both ways is still fetched once
|
|
885
900
|
(stable ? this.#packumentPromises.get(fullKey) : undefined);
|
|
886
|
-
// a
|
|
887
|
-
//
|
|
888
|
-
//
|
|
889
|
-
//
|
|
890
|
-
// costs at most one extra concurrent GET
|
|
891
|
-
//
|
|
892
|
-
if (inflight &&
|
|
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)
|
|
893
908
|
return inflight.promise;
|
|
894
909
|
// `?stable` is a distinct URL, so it gets its own disk cache entry
|
|
895
910
|
const pakuURL = new URL(stable ? `${name}?stable` : name, registry);
|
|
896
911
|
const promise = this.#fetchPackument(spec, options, pakuURL);
|
|
897
|
-
const record = { promise,
|
|
912
|
+
const record = { promise, rank };
|
|
898
913
|
this.#packumentPromises.set(packumentKey, record);
|
|
899
|
-
// Clean up once settled so we don't leak memory, unless a
|
|
914
|
+
// Clean up once settled so we don't leak memory, unless a stronger
|
|
900
915
|
// request has since taken the slot over.
|
|
901
916
|
// Use .then/.catch instead of .finally to avoid creating
|
|
902
917
|
// an unhandled rejection from the derived promise.
|
|
@@ -912,7 +927,8 @@ export class PackageInfoClient {
|
|
|
912
927
|
}
|
|
913
928
|
async #fetchPackument(spec, options, pakuURL, useCache) {
|
|
914
929
|
// Request vlt's abbreviated packument, falling back to the full one:
|
|
915
|
-
// accept: application/vnd.vlt.packument-
|
|
930
|
+
// accept: application/vnd.vlt.packument-v2+json; q=1.0,
|
|
931
|
+
// application/vnd.vlt.packument-v1+json; q=0.9,
|
|
916
932
|
// application/json; q=0.8, */*; q=0.1
|
|
917
933
|
//
|
|
918
934
|
// npm's corgi (`application/vnd.npm.install-v1+json`) is never
|
|
@@ -930,6 +946,7 @@ export class PackageInfoClient {
|
|
|
930
946
|
// The RegistryClient disk cache key is method + URL only, so every
|
|
931
947
|
// packument request must use this same accept header, and the SWR
|
|
932
948
|
// revalidation child re-requests the representation it was given.
|
|
949
|
+
const mode = revalidateMode(spec.final, options);
|
|
933
950
|
const response = await (await this.getRegistryClient()).request(pakuURL, {
|
|
934
951
|
headers: {
|
|
935
952
|
accept: options.full ? 'application/json' : PACKUMENT_ACCEPT,
|
|
@@ -937,12 +954,11 @@ export class PackageInfoClient {
|
|
|
937
954
|
...(useCache === false || options.full ?
|
|
938
955
|
{ useCache: false }
|
|
939
956
|
: {}),
|
|
940
|
-
//
|
|
941
|
-
//
|
|
942
|
-
//
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
: {}),
|
|
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 }),
|
|
946
962
|
});
|
|
947
963
|
if (response.statusCode !== 200) {
|
|
948
964
|
throw this.#resolveError(spec, options, `failed to fetch packument: ${registryErrorMessage(response)}`, {
|
|
@@ -961,12 +977,16 @@ export class PackageInfoClient {
|
|
|
961
977
|
throw er;
|
|
962
978
|
}
|
|
963
979
|
const { registry, name } = spec.final;
|
|
964
|
-
|
|
980
|
+
const { contentType } = response;
|
|
981
|
+
const v2 = contentType.startsWith(VLT_PACKUMENT_V2_MIME);
|
|
982
|
+
if (v2 || contentType.startsWith(VLT_PACKUMENT_MIME)) {
|
|
965
983
|
this.#vltPackuments.add(`${registry}${name}`);
|
|
966
984
|
}
|
|
967
985
|
/* c8 ignore next - registry specs always have a registry */
|
|
968
|
-
if (registry)
|
|
969
|
-
|
|
986
|
+
if (registry) {
|
|
987
|
+
const base = registry.endsWith('/') ? registry : registry + '/';
|
|
988
|
+
absolutizeTarballs(paku, v2 ? `${base}${name}/-/` : base);
|
|
989
|
+
}
|
|
970
990
|
return paku;
|
|
971
991
|
}
|
|
972
992
|
async resolve(spec, options = {}) {
|
|
@@ -1127,12 +1147,12 @@ export class PackageInfoClient {
|
|
|
1127
1147
|
return er;
|
|
1128
1148
|
}
|
|
1129
1149
|
}
|
|
1130
|
-
// vlt packuments carry dist.tarball relative to the registry base
|
|
1131
|
-
// (`foo/-/foo-1.0.0.tgz
|
|
1150
|
+
// vlt packuments carry dist.tarball relative to `base`: the registry base
|
|
1151
|
+
// for v1 (`foo/-/foo-1.0.0.tgz`, the form conventionalRegistryTarball
|
|
1152
|
+
// builds), the package's `/-/` directory for v2 (`foo-1.0.0.tgz`).
|
|
1132
1153
|
// Nothing downstream sees a relative URL: the manifest cache, the graph
|
|
1133
1154
|
// and the lockfile all get the absolute one.
|
|
1134
|
-
const absolutizeTarballs = (paku,
|
|
1135
|
-
const base = registry.endsWith('/') ? registry : registry + '/';
|
|
1155
|
+
const absolutizeTarballs = (paku, base) => {
|
|
1136
1156
|
for (const { dist } of Object.values(paku.versions)) {
|
|
1137
1157
|
const tarball = dist?.tarball;
|
|
1138
1158
|
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.
|
|
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.
|
|
17
|
-
"@vltpkg/git": "1.3.
|
|
18
|
-
"@vltpkg/output": "1.3.
|
|
19
|
-
"@vltpkg/package-json": "1.3.
|
|
20
|
-
"@vltpkg/pick-manifest": "1.3.
|
|
21
|
-
"@vltpkg/registry-client": "1.3.
|
|
22
|
-
"@vltpkg/spec": "1.3.
|
|
23
|
-
"@vltpkg/tar": "1.3.
|
|
24
|
-
"@vltpkg/types": "1.3.
|
|
25
|
-
"@vltpkg/workspaces": "1.3.
|
|
26
|
-
"@vltpkg/xdg": "1.3.
|
|
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.
|
|
36
|
-
"@vltpkg/vlt-json": "1.3.
|
|
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",
|