@vltpkg/package-info 1.3.3 → 1.3.4
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/README.md +2 -2
- package/dist/index.d.ts +13 -5
- package/dist/index.js +318 -28
- package/dist/resolve-batch.d.ts +51 -0
- package/dist/resolve-batch.js +76 -0
- package/package.json +14 -15
package/README.md
CHANGED
|
@@ -51,8 +51,8 @@ only ever sees `auto` from the CLI on Linux. A gzipped cached tarball
|
|
|
51
51
|
that is not store-linked (`unpack`, git or remote tarballs, no sha512
|
|
52
52
|
integrity) is queued too, so the child un-gzips it.
|
|
53
53
|
|
|
54
|
-
Packages with install scripts are
|
|
55
|
-
|
|
54
|
+
Packages with install scripts are linked too; reify copies them in
|
|
55
|
+
place right before their scripts run.
|
|
56
56
|
|
|
57
57
|
A store link logs its request as `store`, a copy from the store as
|
|
58
58
|
`cache`. Both also return `manifest` (the package.json as JSON text,
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { SpecOptions } from '@vltpkg/spec';
|
|
|
5
5
|
import { Spec } from '@vltpkg/spec';
|
|
6
6
|
import type { Pool, StoreLinker } from '@vltpkg/tar';
|
|
7
7
|
import type { Integrity, Manifest, Packument } from '@vltpkg/types';
|
|
8
|
+
import type { ResolveRequest } from './resolve-batch.ts';
|
|
9
|
+
export type { ResolveRequest } from './resolve-batch.ts';
|
|
8
10
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
9
11
|
import type { Capabilities } from './capabilities.ts';
|
|
10
12
|
export type { Capabilities } from './capabilities.ts';
|
|
@@ -106,11 +108,6 @@ export type PackageInfoClientExtractOptions = PackageInfoClientRequestOptions &
|
|
|
106
108
|
* Other network bodies are always checked.
|
|
107
109
|
*/
|
|
108
110
|
fromLockfile?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* The manifest declares install scripts: copy the package from the
|
|
111
|
-
* global store, never link it, even if its package.json has none.
|
|
112
|
-
*/
|
|
113
|
-
installScripts?: boolean;
|
|
114
111
|
};
|
|
115
112
|
export declare class PackageInfoClient {
|
|
116
113
|
#private;
|
|
@@ -134,6 +131,17 @@ export declare class PackageInfoClient {
|
|
|
134
131
|
*/
|
|
135
132
|
_manifestCachePath(spec: Spec, options: PackageInfoClientRequestOptions): string | undefined;
|
|
136
133
|
tarball(spec: Spec | string, options?: PackageInfoClientExtractOptions): Promise<Buffer>;
|
|
134
|
+
/**
|
|
135
|
+
* Start a server-side resolve for `request` against `registry` and
|
|
136
|
+
* return without waiting. `manifest()` answers from what has arrived,
|
|
137
|
+
* and blocks on the request only when it needs a key that has not.
|
|
138
|
+
*
|
|
139
|
+
* A no-op unless the registry says it serves the endpoint. Anything it
|
|
140
|
+
* does not deliver is left to `manifest()`.
|
|
141
|
+
*/
|
|
142
|
+
prefetchResolve(registry: string, request: ResolveRequest): void;
|
|
143
|
+
/** How many manifests resolve batches have delivered. For tests. */
|
|
144
|
+
get resolvedManifestCount(): number;
|
|
137
145
|
manifest(spec: Spec | string, options?: PackageInfoClientRequestOptions): Promise<Manifest | import("@vltpkg/types").Override<Manifest, import("@vltpkg/types").NormalizedFields>>;
|
|
138
146
|
/**
|
|
139
147
|
* The packument for `spec`, with every version the registry has. Callers
|
package/dist/index.js
CHANGED
|
@@ -9,12 +9,13 @@ import { registryErrorMessage, tokenRefusalAdvice, } from '@vltpkg/registry-clie
|
|
|
9
9
|
import { storeRoot } from '@vltpkg/registry-client/store-root';
|
|
10
10
|
import { Spec } from '@vltpkg/spec';
|
|
11
11
|
import { asPackument, brotliTarballUrl, integrityHex, tarballFormat, } from '@vltpkg/types';
|
|
12
|
-
import
|
|
12
|
+
import { fetchResolve } from "./resolve-batch.js";
|
|
13
13
|
import { Monorepo } from '@vltpkg/workspaces';
|
|
14
14
|
import { XDG } from '@vltpkg/xdg';
|
|
15
15
|
import { createHash, randomBytes } from 'node:crypto';
|
|
16
16
|
import { mkdir, readFile, rm, stat, symlink, unlink, writeFile, } from 'node:fs/promises';
|
|
17
17
|
import { basename, dirname, resolve as pathResolve, relative, } from 'node:path';
|
|
18
|
+
import { setTimeout } from 'node:timers/promises';
|
|
18
19
|
import { debuglog } from 'node:util';
|
|
19
20
|
import { create as tarC } from 'tar';
|
|
20
21
|
import { getCapabilities, peekCapabilities } from "./capabilities.js";
|
|
@@ -50,6 +51,30 @@ export const VLT_PACKUMENT_V2_MIME = 'application/vnd.vlt.packument-v2+json';
|
|
|
50
51
|
* has something to match.
|
|
51
52
|
*/
|
|
52
53
|
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`;
|
|
54
|
+
/**
|
|
55
|
+
* How long `manifest()` waits on an in-flight resolve that is not delivering
|
|
56
|
+
* anything before fetching the packument itself. A stream that keeps
|
|
57
|
+
* delivering records is waited on for as long as it does; one that goes
|
|
58
|
+
* quiet for this long is left to finish on its own.
|
|
59
|
+
*/
|
|
60
|
+
const resolveWaitMs = () => {
|
|
61
|
+
const configured = Number(process.env.VLT_BATCH_RESOLVE_WAIT_MS);
|
|
62
|
+
return Number.isFinite(configured) && configured >= 0 ?
|
|
63
|
+
configured
|
|
64
|
+
: 1000;
|
|
65
|
+
};
|
|
66
|
+
// what a resolve wait's timer resolves to, so it cannot be mistaken for a
|
|
67
|
+
// manifest
|
|
68
|
+
const stalled = Symbol('stalled');
|
|
69
|
+
// request options that change which manifest is picked, or how; a batch
|
|
70
|
+
// entry never went through pickManifest under them, so they bypass it
|
|
71
|
+
const SELECTION_OPTIONS = [
|
|
72
|
+
'before',
|
|
73
|
+
'os',
|
|
74
|
+
'arch',
|
|
75
|
+
'libc',
|
|
76
|
+
'node-version',
|
|
77
|
+
];
|
|
53
78
|
// the maximum duration of a manifest cache file
|
|
54
79
|
const manifestCacheMaxAge = 5 * 60 * 1000;
|
|
55
80
|
/**
|
|
@@ -96,6 +121,29 @@ const isStableSelector = (f) => {
|
|
|
96
121
|
};
|
|
97
122
|
// anything else, eg an unvalidated env value, means `unpack`
|
|
98
123
|
const storeLinkers = new Set(['auto', 'hardlink', 'copy']);
|
|
124
|
+
// the hash a response answers for. a network body's is the hash of its
|
|
125
|
+
// bytes: the registry client already checked it against the expected
|
|
126
|
+
// hash, or recorded it when there was none, and memoized it, so this
|
|
127
|
+
// is no second pass.
|
|
128
|
+
//
|
|
129
|
+
// a cache hit answers with the hash the entry was stored under, never
|
|
130
|
+
// a fresh one: cache-unzip rewrites cached bodies un-gzipped in place,
|
|
131
|
+
// so hashing one again would pin a hash of bytes no other machine has.
|
|
132
|
+
// an entry stored before that hash was recorded can still be hashed
|
|
133
|
+
// while its body is the bytes that came off the wire, i.e. still
|
|
134
|
+
// gzipped; once rewritten it cannot be verified at all.
|
|
135
|
+
//
|
|
136
|
+
// nor can an entry with no content-type. request() labels a body
|
|
137
|
+
// served without one as it stores it under the hash it checked or
|
|
138
|
+
// recorded, so an entry with none was not stored that way. it may be
|
|
139
|
+
// from v1.2.0 to v1.3.3, which un-gzipped a gzipped one in memory and
|
|
140
|
+
// only then hashed it: its stored hash may be of that copy, which no
|
|
141
|
+
// cold cache reproduces. a body served un-gzipped hashes the same
|
|
142
|
+
// either way, so there is no telling which, and none is trusted.
|
|
143
|
+
const storedIntegrity = (response) => !response.fromCache ? response.integrityActual
|
|
144
|
+
: !response.contentType ? undefined
|
|
145
|
+
: (response.integrity ??
|
|
146
|
+
(response.isGzip ? response.integrityActual : undefined));
|
|
99
147
|
export class PackageInfoClient {
|
|
100
148
|
#registryClient;
|
|
101
149
|
#projectRoot;
|
|
@@ -134,6 +182,26 @@ export class PackageInfoClient {
|
|
|
134
182
|
// needed. entries are removed when the on-disk file is invalidated
|
|
135
183
|
// so the refreshed manifest can be written again.
|
|
136
184
|
#manifestWritePaths = new Set();
|
|
185
|
+
// Manifests a resolve batch delivered, keyed both as
|
|
186
|
+
// `${registry}${name}@${range}` for every spec that chose a version and
|
|
187
|
+
// `${registry}${name}@${version}` for the version itself.
|
|
188
|
+
#resolvedManifests = new Map();
|
|
189
|
+
// The resolves still streaming, per registry, each settling when its
|
|
190
|
+
// stream ends. The requests overlap whatever the graph build does before
|
|
191
|
+
// it asks for its first manifest.
|
|
192
|
+
#resolveInflight = new Map();
|
|
193
|
+
// Requests already sent, so the same ask is not repeated. Keyed on the
|
|
194
|
+
// request rather than the registry: a later step asking for a different
|
|
195
|
+
// root set is a different question.
|
|
196
|
+
#resolveSent = new Set();
|
|
197
|
+
// Keys `manifest()` is waiting for, each woken by the record that carries
|
|
198
|
+
// it. Waiting per key rather than on the whole response is what lets a
|
|
199
|
+
// build place level N while the server still walks level N+1.
|
|
200
|
+
#resolveWaiters = new Map();
|
|
201
|
+
// When each registry's resolve last delivered a record, which is what a
|
|
202
|
+
// waiter checks to tell a stream that is still coming from one that has
|
|
203
|
+
// stalled.
|
|
204
|
+
#resolveLastRecordAt = new Map();
|
|
137
205
|
#registryClientPromise;
|
|
138
206
|
#tarPoolPromise;
|
|
139
207
|
async getRegistryClient() {
|
|
@@ -231,7 +299,7 @@ export class PackageInfoClient {
|
|
|
231
299
|
async extract(spec, target, options = {}) {
|
|
232
300
|
if (typeof spec === 'string')
|
|
233
301
|
spec = Spec.parse(spec, this.options);
|
|
234
|
-
const { from = this.#projectRoot, integrity, resolved, fromLockfile = false,
|
|
302
|
+
const { from = this.#projectRoot, integrity, resolved, fromLockfile = false, } = options;
|
|
235
303
|
const f = spec.final;
|
|
236
304
|
// If the caller already provides both integrity and resolved
|
|
237
305
|
// (from lockfile or prior resolution), skip re-resolving. A
|
|
@@ -282,7 +350,7 @@ export class PackageInfoClient {
|
|
|
282
350
|
const format = tarballFormat(r.resolved);
|
|
283
351
|
// git tarballs keep the unpack path
|
|
284
352
|
const storeOn = f.type === 'registry' && this.#storeLinker !== 'unpack';
|
|
285
|
-
const copy = this.#storeLinker === 'copy'
|
|
353
|
+
const copy = this.#storeLinker === 'copy';
|
|
286
354
|
// If we already have a hash, that is the store key. Some
|
|
287
355
|
// tarballs arrive without one: a `.tar.br`, or anything a
|
|
288
356
|
// registry serves with no `dist.integrity`. For those, read the
|
|
@@ -429,28 +497,113 @@ export class PackageInfoClient {
|
|
|
429
497
|
return r;
|
|
430
498
|
}
|
|
431
499
|
case 'remote': {
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
500
|
+
const rc = await this.getRegistryClient();
|
|
501
|
+
// lazy for the same reason getRegistryClient() is
|
|
502
|
+
const { CacheEntry: Entry, cacheKey } = await import('@vltpkg/registry-client');
|
|
503
|
+
const key = cacheKey('GET', new URL(r.resolved));
|
|
504
|
+
// v1.2.0 to v1.3.3 hashed a remote tarball after the registry
|
|
505
|
+
// client had un-gzipped it: always, for one served with no
|
|
506
|
+
// content-type, and on a cache hit once cache-unzip had
|
|
507
|
+
// rewritten the entry, so a lockfile they wrote may pin that
|
|
508
|
+
// hash. it pins the same tar: a body that un-gzips to it is
|
|
509
|
+
// accepted, and r.integrity re-pinned to the hash the body is
|
|
510
|
+
// stored under, the one reported. the graph keeps the hash a
|
|
511
|
+
// node was locked with, so the lockfile is never rewritten and
|
|
512
|
+
// every install from it takes this path. a body that will not
|
|
513
|
+
// un-gzip is no match.
|
|
514
|
+
const unzipped = (entry) => {
|
|
515
|
+
try {
|
|
516
|
+
return entry.unzippedIntegrity() === r.integrity;
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
const fetchTarball = async (readCache) => {
|
|
523
|
+
let response;
|
|
524
|
+
try {
|
|
525
|
+
response = await rc.request(r.resolved, {
|
|
526
|
+
integrity: r.integrity,
|
|
527
|
+
...(readCache === false ? { readCache } : {}),
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
catch (er) {
|
|
531
|
+
// the registry client rejects a network body that does not
|
|
532
|
+
// hash to r.integrity before anything is written. store one
|
|
533
|
+
// that un-gzips to it the way the client would have: under
|
|
534
|
+
// the hash of its bytes it recorded for the check, labelled
|
|
535
|
+
// like one it stores (see storedIntegrity), and for a url
|
|
536
|
+
// that redirects, under the url the lockfile names only,
|
|
537
|
+
// all a cache hit needs.
|
|
538
|
+
const cause = er.cause;
|
|
539
|
+
if (cause?.code !== 'EINTEGRITY' ||
|
|
540
|
+
!(cause.response instanceof Entry) ||
|
|
541
|
+
!unzipped(cause.response)) {
|
|
542
|
+
throw er;
|
|
543
|
+
}
|
|
544
|
+
response = cause.response;
|
|
545
|
+
r.integrity = response.integrityActual;
|
|
546
|
+
response.labelArtifact();
|
|
547
|
+
rc.cache.set(key, response.encode(), {
|
|
548
|
+
integrity: r.integrity,
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
if (response.statusCode !== 200) {
|
|
552
|
+
throw this.#resolveError(spec, options, `failed to fetch remote tarball: ${registryErrorMessage(response)}`, {
|
|
553
|
+
url: r.resolved,
|
|
554
|
+
response,
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
return response;
|
|
558
|
+
};
|
|
559
|
+
let response = await fetchTarball();
|
|
560
|
+
let found = storedIntegrity(response);
|
|
561
|
+
// a cache hit that un-gzips to the lockfile hash, see above
|
|
562
|
+
if (response.fromCache &&
|
|
563
|
+
found &&
|
|
564
|
+
r.integrity &&
|
|
565
|
+
r.integrity !== found &&
|
|
566
|
+
unzipped(response)) {
|
|
567
|
+
r.integrity = found;
|
|
438
568
|
}
|
|
439
|
-
|
|
440
|
-
//
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
569
|
+
// a cached entry that does not match the lockfile, or that
|
|
570
|
+
// cannot be verified any more: evict it and fetch again, once,
|
|
571
|
+
// so the cache converges on an entry that carries its hash.
|
|
572
|
+
// the link under r.integrity goes too: the lookup by it links
|
|
573
|
+
// the value file there when nothing was, and the disk write
|
|
574
|
+
// trusts an integrity file it finds, so it would link the old
|
|
575
|
+
// bytes back over the new ones. the refetch reads nothing from
|
|
576
|
+
// the cache, on this url or any it redirects to: a url that
|
|
577
|
+
// redirects has an entry under the final url too, stored by
|
|
578
|
+
// the same fetch and out of the eviction's reach.
|
|
579
|
+
if (response.fromCache &&
|
|
580
|
+
(!found || (r.integrity && r.integrity !== found))) {
|
|
581
|
+
rc.cache.delete(key, true, found);
|
|
582
|
+
if (r.integrity)
|
|
583
|
+
rc.cache.delete(key, true, r.integrity);
|
|
584
|
+
await rc.cache.promise();
|
|
585
|
+
response = await fetchTarball(false);
|
|
586
|
+
found = storedIntegrity(response);
|
|
587
|
+
}
|
|
588
|
+
/* c8 ignore start - defense in depth: anything but a cache hit
|
|
589
|
+
* that matched is a network body, the refetch included, since
|
|
590
|
+
* it reads nothing from the cache on any redirect hop. the
|
|
591
|
+
* registry client checks every network body against
|
|
592
|
+
* r.integrity before anything is written, and records the hash
|
|
593
|
+
* of one it had no expectation for; one it rejected is only
|
|
594
|
+
* here with r.integrity re-pinned to its hash. */
|
|
595
|
+
if (!found || (r.integrity && r.integrity !== found)) {
|
|
445
596
|
throw error('Integrity check failure', {
|
|
446
597
|
code: 'EINTEGRITY',
|
|
447
598
|
spec,
|
|
448
599
|
url: r.resolved,
|
|
449
600
|
wanted: r.integrity,
|
|
450
|
-
found
|
|
601
|
+
found,
|
|
451
602
|
});
|
|
452
603
|
}
|
|
453
|
-
|
|
604
|
+
/* c8 ignore stop */
|
|
605
|
+
r.integrity = found;
|
|
606
|
+
const buf = response.buffer();
|
|
454
607
|
try {
|
|
455
608
|
await (await this.getTarPool()).unpack(buf, target);
|
|
456
609
|
}
|
|
@@ -712,6 +865,121 @@ export class PackageInfoClient {
|
|
|
712
865
|
}
|
|
713
866
|
}
|
|
714
867
|
}
|
|
868
|
+
/**
|
|
869
|
+
* Start a server-side resolve for `request` against `registry` and
|
|
870
|
+
* return without waiting. `manifest()` answers from what has arrived,
|
|
871
|
+
* and blocks on the request only when it needs a key that has not.
|
|
872
|
+
*
|
|
873
|
+
* A no-op unless the registry says it serves the endpoint. Anything it
|
|
874
|
+
* does not deliver is left to `manifest()`.
|
|
875
|
+
*/
|
|
876
|
+
prefetchResolve(registry, request) {
|
|
877
|
+
if (!request.roots.length)
|
|
878
|
+
return;
|
|
879
|
+
// keyed the way a spec names its registry, with the trailing slash
|
|
880
|
+
if (!registry.endsWith('/'))
|
|
881
|
+
registry += '/';
|
|
882
|
+
const sent = `${registry}${JSON.stringify(request)}`;
|
|
883
|
+
if (this.#resolveSent.has(sent))
|
|
884
|
+
return;
|
|
885
|
+
this.#resolveSent.add(sent);
|
|
886
|
+
const promise = this.#runResolve(registry, request);
|
|
887
|
+
let inflight = this.#resolveInflight.get(registry);
|
|
888
|
+
if (!inflight)
|
|
889
|
+
this.#resolveInflight.set(registry, (inflight = new Set()));
|
|
890
|
+
inflight.add(promise);
|
|
891
|
+
// dropped once settled, so manifest() stops waiting on a request that
|
|
892
|
+
// has already delivered everything it is going to
|
|
893
|
+
const clear = () => inflight.delete(promise);
|
|
894
|
+
promise.then(clear, clear);
|
|
895
|
+
}
|
|
896
|
+
/** Never rejects: a resolve that fails leaves every spec to manifest(). */
|
|
897
|
+
async #runResolve(registry, request) {
|
|
898
|
+
try {
|
|
899
|
+
if ((await this.capabilities(registry)).resolve === undefined)
|
|
900
|
+
return;
|
|
901
|
+
const client = await this.getRegistryClient();
|
|
902
|
+
this.#resolveLastRecordAt.set(registry, Date.now());
|
|
903
|
+
await fetchResolve(client, registry, request, record => {
|
|
904
|
+
this.#resolveLastRecordAt.set(registry, Date.now());
|
|
905
|
+
// A resolve record is a vlt manifest: `dist.tarball` is the
|
|
906
|
+
// tarball's basename, resolved against the package's `/-/`
|
|
907
|
+
// directory like a v2 packument's, and a tarball without a hash
|
|
908
|
+
// must carry a Repr-Digest.
|
|
909
|
+
absolutizeTarball(record.manifest, `${registry}${record.name}/-/`);
|
|
910
|
+
this.#vltPackuments.add(`${registry}${record.name}`);
|
|
911
|
+
// Indexed both ways: by the ranges that chose the version, which
|
|
912
|
+
// is what the graph build asks for, and by the exact version, for
|
|
913
|
+
// a lookup that already knows it.
|
|
914
|
+
for (const spec of record.requested) {
|
|
915
|
+
this.#deliverResolved(`${registry}${record.name}@${spec}`, record.manifest);
|
|
916
|
+
}
|
|
917
|
+
this.#deliverResolved(`${registry}${record.name}@${record.version}`, record.manifest);
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
catch {
|
|
921
|
+
// The per-name path still has every spec.
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
/** Record an arrived manifest and wake whoever was waiting for it. */
|
|
925
|
+
#deliverResolved(key, manifest) {
|
|
926
|
+
debug('resolve delivered %s', key);
|
|
927
|
+
this.#resolvedManifests.set(key, manifest);
|
|
928
|
+
const waiters = this.#resolveWaiters.get(key);
|
|
929
|
+
if (waiters) {
|
|
930
|
+
this.#resolveWaiters.delete(key);
|
|
931
|
+
for (const wake of waiters)
|
|
932
|
+
wake(manifest);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* The manifest an in-flight resolve is expected to carry for `key`, or
|
|
937
|
+
* undefined once waiting stopped being worth it: every request settled
|
|
938
|
+
* without the key, or no record of any kind arrived for a whole wait.
|
|
939
|
+
*
|
|
940
|
+
* A stream that is still delivering is worth waiting on, since its records
|
|
941
|
+
* come in the order the build needs them; one that has stalled is not, and
|
|
942
|
+
* the packument fetch was the alternative anyway.
|
|
943
|
+
*/
|
|
944
|
+
async #awaitResolved(registry, key) {
|
|
945
|
+
const inflight = this.#resolveInflight.get(registry);
|
|
946
|
+
if (!inflight?.size)
|
|
947
|
+
return undefined;
|
|
948
|
+
let wake;
|
|
949
|
+
const arrival = new Promise(res => {
|
|
950
|
+
wake = res;
|
|
951
|
+
});
|
|
952
|
+
let waiters = this.#resolveWaiters.get(key);
|
|
953
|
+
if (!waiters)
|
|
954
|
+
this.#resolveWaiters.set(key, (waiters = new Set()));
|
|
955
|
+
waiters.add(wake);
|
|
956
|
+
const settled = Promise.all([...inflight]).then(() => this.#resolvedManifests.get(key));
|
|
957
|
+
const waitMs = resolveWaitMs();
|
|
958
|
+
try {
|
|
959
|
+
for (;;) {
|
|
960
|
+
const outcome = await Promise.race([
|
|
961
|
+
arrival,
|
|
962
|
+
settled,
|
|
963
|
+
// unref'd: a pending wait must never be what keeps the process up
|
|
964
|
+
setTimeout(waitMs, stalled, { ref: false }),
|
|
965
|
+
]);
|
|
966
|
+
if (outcome !== stalled)
|
|
967
|
+
return outcome;
|
|
968
|
+
const lastRecordAt = this.#resolveLastRecordAt.get(registry) ?? 0;
|
|
969
|
+
if (Date.now() - lastRecordAt >= waitMs)
|
|
970
|
+
return undefined;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
finally {
|
|
974
|
+
waiters.delete(wake);
|
|
975
|
+
if (!waiters.size)
|
|
976
|
+
this.#resolveWaiters.delete(key);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
/** How many manifests resolve batches have delivered. For tests. */
|
|
980
|
+
get resolvedManifestCount() {
|
|
981
|
+
return this.#resolvedManifests.size;
|
|
982
|
+
}
|
|
715
983
|
async manifest(spec, options = {}) {
|
|
716
984
|
const { from = this.#projectRoot } = options;
|
|
717
985
|
if (typeof spec === 'string')
|
|
@@ -719,6 +987,23 @@ export class PackageInfoClient {
|
|
|
719
987
|
const f = spec.final;
|
|
720
988
|
switch (f.type) {
|
|
721
989
|
case 'registry': {
|
|
990
|
+
// a resolve entry never went through pickManifest under any
|
|
991
|
+
// selection option, so those take the packument path
|
|
992
|
+
if (!SELECTION_OPTIONS.some(k => options[k] !== undefined)) {
|
|
993
|
+
const key = `${f.registry ?? ''}${f.name}@${f.bareSpec}`;
|
|
994
|
+
const resolved = this.#resolvedManifests.get(key);
|
|
995
|
+
if (resolved)
|
|
996
|
+
return resolved;
|
|
997
|
+
// Not here yet: give the in-flight resolve a bounded moment to
|
|
998
|
+
// deliver this one key rather than fetching a packument for a
|
|
999
|
+
// manifest that is probably already on its way.
|
|
1000
|
+
if (f.registry) {
|
|
1001
|
+
const arrived = await this.#awaitResolved(f.registry, key);
|
|
1002
|
+
if (arrived)
|
|
1003
|
+
return arrived;
|
|
1004
|
+
debug('resolve miss %s', key);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
722
1007
|
// Check if manifest is cached, if so just return it earlier
|
|
723
1008
|
const cachePath = this._manifestCachePath(spec, options);
|
|
724
1009
|
if (cachePath) {
|
|
@@ -793,19 +1078,20 @@ export class PackageInfoClient {
|
|
|
793
1078
|
throw this.#resolveError(s, options, `failed to fetch URL: ${registryErrorMessage(response)}`, { response, url: remoteURL });
|
|
794
1079
|
}
|
|
795
1080
|
const buf = response.buffer();
|
|
796
|
-
//
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
1081
|
+
// the graph hands this back to extract() as the lockfile
|
|
1082
|
+
// hash: the hash the entry is stored under, or none for an
|
|
1083
|
+
// entry that cannot be verified, which extract() then
|
|
1084
|
+
// fetches again and records
|
|
1085
|
+
const integrity = storedIntegrity(response);
|
|
800
1086
|
try {
|
|
801
1087
|
await (await this.getTarPool()).unpack(buf, dir);
|
|
802
1088
|
}
|
|
803
1089
|
catch (er) {
|
|
804
1090
|
throw this.#resolveError(s, options, 'tar unpack failed', { cause: er });
|
|
805
1091
|
}
|
|
806
|
-
// return manifest with computed integrity
|
|
807
1092
|
const mani = this.#readExtracted(dir, s, options);
|
|
808
|
-
|
|
1093
|
+
if (integrity)
|
|
1094
|
+
mani.dist = { integrity };
|
|
809
1095
|
return mani;
|
|
810
1096
|
});
|
|
811
1097
|
}
|
|
@@ -1153,10 +1439,14 @@ export class PackageInfoClient {
|
|
|
1153
1439
|
// Nothing downstream sees a relative URL: the manifest cache, the graph
|
|
1154
1440
|
// and the lockfile all get the absolute one.
|
|
1155
1441
|
const absolutizeTarballs = (paku, base) => {
|
|
1156
|
-
for (const
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1442
|
+
for (const manifest of Object.values(paku.versions)) {
|
|
1443
|
+
absolutizeTarball(manifest, base);
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
/** Resolve a relative `dist.tarball` against `base`; an absolute one stays. */
|
|
1447
|
+
const absolutizeTarball = (manifest, base) => {
|
|
1448
|
+
const dist = manifest.dist;
|
|
1449
|
+
if (dist?.tarball && !/^[a-z][a-z0-9+.-]*:/i.test(dist.tarball)) {
|
|
1450
|
+
dist.tarball = String(new URL(dist.tarball, base));
|
|
1161
1451
|
}
|
|
1162
1452
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { RegistryClient } from '@vltpkg/registry-client';
|
|
2
|
+
import type { Manifest } from '@vltpkg/types';
|
|
3
|
+
/**
|
|
4
|
+
* Server-side range resolution against a vlt registry's `/-/vlt/resolve`
|
|
5
|
+
* endpoint.
|
|
6
|
+
*
|
|
7
|
+
* One request resolves many `name@range` pairs and streams back the chosen
|
|
8
|
+
* manifests for the whole dependency closure. Records reach the caller as
|
|
9
|
+
* each line arrives, in the breadth-first order the server emits them, so
|
|
10
|
+
* the graph build can place level N while the server still walks level N+1.
|
|
11
|
+
*
|
|
12
|
+
* Everything here fails soft: a registry that does not answer, a request
|
|
13
|
+
* that errors, a stream that dies mid-body, and a record that does not
|
|
14
|
+
* parse all leave the caller with fewer manifests than it asked for, and
|
|
15
|
+
* the per-name path fills the rest in.
|
|
16
|
+
*/
|
|
17
|
+
/** The request body `/-/vlt/resolve` takes. */
|
|
18
|
+
export type ResolveRequest = {
|
|
19
|
+
roots: {
|
|
20
|
+
name: string;
|
|
21
|
+
spec: string;
|
|
22
|
+
}[];
|
|
23
|
+
platform?: {
|
|
24
|
+
os?: string;
|
|
25
|
+
cpu?: string;
|
|
26
|
+
libc?: string;
|
|
27
|
+
node?: string;
|
|
28
|
+
};
|
|
29
|
+
tag?: string;
|
|
30
|
+
have?: string[];
|
|
31
|
+
stop?: {
|
|
32
|
+
names?: string[];
|
|
33
|
+
scopes?: string[];
|
|
34
|
+
};
|
|
35
|
+
closure?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/** One resolved version, as the caller receives it. */
|
|
38
|
+
export type ResolveRecord = {
|
|
39
|
+
name: string;
|
|
40
|
+
version: string;
|
|
41
|
+
/** every spec of its level that chose this version */
|
|
42
|
+
requested: string[];
|
|
43
|
+
manifest: Manifest;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Resolve `request` against `registry`, calling `onRecord` for each version
|
|
47
|
+
* the server resolves, as its line arrives. Settles when the stream ends,
|
|
48
|
+
* however it ends: a caller waiting on a record that never came learns that
|
|
49
|
+
* from the request settling, not from an error.
|
|
50
|
+
*/
|
|
51
|
+
export declare const fetchResolve: (client: RegistryClient, registry: string, request: ResolveRequest, onRecord: (record: ResolveRecord) => void) => Promise<void>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve `request` against `registry`, calling `onRecord` for each version
|
|
4
|
+
* the server resolves, as its line arrives. Settles when the stream ends,
|
|
5
|
+
* however it ends: a caller waiting on a record that never came learns that
|
|
6
|
+
* from the request settling, not from an error.
|
|
7
|
+
*/
|
|
8
|
+
export const fetchResolve = async (client, registry, request, onRecord) => {
|
|
9
|
+
if (!request.roots.length)
|
|
10
|
+
return;
|
|
11
|
+
let body;
|
|
12
|
+
try {
|
|
13
|
+
const response = await client.requestStream(new URL('-/vlt/resolve', registry), {
|
|
14
|
+
// POST, not QUERY: CloudFront's allowed-method sets are fixed and
|
|
15
|
+
// none includes QUERY. The registry answers both.
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'content-type': 'application/json',
|
|
19
|
+
accept: 'application/x-ndjson',
|
|
20
|
+
},
|
|
21
|
+
body: JSON.stringify(request),
|
|
22
|
+
});
|
|
23
|
+
if (response.statusCode !== 207) {
|
|
24
|
+
response.body.resume();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
body = response.body;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
// One record per line, so lines are the unit of work: a partial line
|
|
34
|
+
// left by a dead stream is simply never emitted.
|
|
35
|
+
for await (const line of createInterface({ input: body })) {
|
|
36
|
+
const record = parseRecord(line);
|
|
37
|
+
if (record)
|
|
38
|
+
onRecord(record);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// A stream that died mid-body leaves the records it did not carry to
|
|
43
|
+
// the per-name path, the same as specs the server did not resolve.
|
|
44
|
+
body.destroy();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const parseRecord = (l) => {
|
|
48
|
+
// parsed wire data: nothing about its shape can be assumed
|
|
49
|
+
let record;
|
|
50
|
+
try {
|
|
51
|
+
record = JSON.parse(l);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { status, name, requested, manifest } = record;
|
|
57
|
+
if (status !== 200 || typeof name !== 'string')
|
|
58
|
+
return;
|
|
59
|
+
if (!Array.isArray(requested) ||
|
|
60
|
+
!requested.every(s => typeof s === 'string'))
|
|
61
|
+
return;
|
|
62
|
+
if (typeof manifest !== 'object' || manifest === null)
|
|
63
|
+
return;
|
|
64
|
+
const mani = manifest;
|
|
65
|
+
// the manifest must be the package its record names, and carry the
|
|
66
|
+
// version it resolved to: these entries are handed out by key, so a
|
|
67
|
+
// registry mixup would poison the lookup
|
|
68
|
+
if (mani.name !== name || typeof mani.version !== 'string')
|
|
69
|
+
return;
|
|
70
|
+
return {
|
|
71
|
+
name,
|
|
72
|
+
version: mani.version,
|
|
73
|
+
requested: requested,
|
|
74
|
+
manifest: mani,
|
|
75
|
+
};
|
|
76
|
+
};
|
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.4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,18 +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.
|
|
27
|
-
"ssri": "^13.0.0",
|
|
16
|
+
"@vltpkg/error-cause": "1.3.4",
|
|
17
|
+
"@vltpkg/git": "1.3.4",
|
|
18
|
+
"@vltpkg/output": "1.3.4",
|
|
19
|
+
"@vltpkg/package-json": "1.3.4",
|
|
20
|
+
"@vltpkg/pick-manifest": "1.3.4",
|
|
21
|
+
"@vltpkg/registry-client": "1.3.4",
|
|
22
|
+
"@vltpkg/spec": "1.3.4",
|
|
23
|
+
"@vltpkg/tar": "1.3.4",
|
|
24
|
+
"@vltpkg/types": "1.3.4",
|
|
25
|
+
"@vltpkg/workspaces": "1.3.4",
|
|
26
|
+
"@vltpkg/xdg": "1.3.4",
|
|
28
27
|
"tar": "^7.5.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
@@ -32,8 +31,8 @@
|
|
|
32
31
|
"@types/node": "^22.19.2",
|
|
33
32
|
"@types/pacote": "^11.1.8",
|
|
34
33
|
"@vltpkg/benchmark": "0.0.0",
|
|
35
|
-
"@vltpkg/cache-unzip": "1.3.
|
|
36
|
-
"@vltpkg/vlt-json": "1.3.
|
|
34
|
+
"@vltpkg/cache-unzip": "1.3.4",
|
|
35
|
+
"@vltpkg/vlt-json": "1.3.4",
|
|
37
36
|
"eslint": "^9.39.1",
|
|
38
37
|
"pacote": "^21.0.4",
|
|
39
38
|
"prettier": "^3.7.4",
|