@pnpm/resolving.npm-resolver 1103.2.1 → 1104.1.0
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/CHANGELOG.md +93 -0
- package/lib/createNpmResolutionVerifier.d.ts +13 -10
- package/lib/createNpmResolutionVerifier.js +171 -45
- package/lib/fetch.js +5 -3
- package/lib/index.d.ts +21 -7
- package/lib/index.js +224 -38
- package/lib/parseBareSpecifier.d.ts +2 -1
- package/lib/parseBareSpecifier.js +31 -7
- package/lib/pickPackage.d.ts +20 -1
- package/lib/pickPackage.js +100 -13
- package/lib/pickPackageFromMeta.d.ts +7 -1
- package/lib/pickPackageFromMeta.js +82 -3
- package/lib/publishTimes.d.ts +24 -0
- package/lib/publishTimes.js +35 -0
- package/lib/trustChecks.d.ts +14 -0
- package/lib/trustChecks.js +5 -0
- package/lib/violationCodes.d.ts +1 -0
- package/lib/violationCodes.js +1 -0
- package/package.json +22 -21
package/lib/pickPackage.js
CHANGED
|
@@ -12,7 +12,8 @@ import { renameOverwrite } from 'rename-overwrite';
|
|
|
12
12
|
import semver from 'semver';
|
|
13
13
|
import { clearMeta, retainsFullMeta } from './clearMeta.js';
|
|
14
14
|
import { notModifiedWithoutCacheError, } from './fetch.js';
|
|
15
|
-
import { pickLowestVersionByVersionRange, pickPackageFromMeta, pickVersionByVersionRange, } from './pickPackageFromMeta.js';
|
|
15
|
+
import { getDominantLockfileVersion, pickLowestVersionByVersionRange, pickPackageFromMeta, pickStableCachedRangeVersion, pickVersionByVersionRange, } from './pickPackageFromMeta.js';
|
|
16
|
+
import { dropIncompletePublishTimes } from './publishTimes.js';
|
|
16
17
|
import { toRaw } from './toRaw.js';
|
|
17
18
|
/**
|
|
18
19
|
* prevents simultaneous operations on the meta.json
|
|
@@ -39,6 +40,13 @@ async function runLimited(pkgMirror, fn) {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
}
|
|
43
|
+
function canReuseStableCachedRange(spec, opts) {
|
|
44
|
+
return (spec.type === 'range' &&
|
|
45
|
+
!opts.includeLatestTag &&
|
|
46
|
+
!opts.updateChecksums &&
|
|
47
|
+
opts.publishedBy == null &&
|
|
48
|
+
opts.trustPolicy !== 'no-downgrade');
|
|
49
|
+
}
|
|
42
50
|
// When includeLatestTag is set, the "latest" dist-tag is added as a candidate
|
|
43
51
|
// alongside the requested spec, and the higher-versioned pick wins.
|
|
44
52
|
function runPicker(pickerOpts, spec, pickOne) {
|
|
@@ -97,7 +105,7 @@ function pickMatchingVersionFinal(pickerOpts, spec, meta) {
|
|
|
97
105
|
}
|
|
98
106
|
catch (err) {
|
|
99
107
|
if (pickerOpts.ignoreMissingTimeField && isMissingTimeError(err)) {
|
|
100
|
-
warnMissingTimeFieldOnce(meta.name);
|
|
108
|
+
warnMissingTimeFieldOnce(meta.name, 'minimumReleaseAge');
|
|
101
109
|
return pickMatchingVersionFast({
|
|
102
110
|
...pickerOpts,
|
|
103
111
|
publishedBy: undefined,
|
|
@@ -152,7 +160,12 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
152
160
|
validatePackageName(spec.name);
|
|
153
161
|
// Use full metadata for optional dependencies to get libc field.
|
|
154
162
|
// See: https://github.com/pnpm/pnpm/issues/9950
|
|
155
|
-
|
|
163
|
+
// The per-registry answer is authoritative when the caller can give one: it
|
|
164
|
+
// already folds in the reasons that hold for every registry, so a registry
|
|
165
|
+
// that carries `time` is free to stay on abbreviated metadata while the
|
|
166
|
+
// others do not.
|
|
167
|
+
const policyWantsFullMetadata = ctx.needsFullMetadataFor?.(opts.registry) ?? ctx.fullMetadata === true;
|
|
168
|
+
const fullMetadata = opts.optional === true || policyWantsFullMetadata;
|
|
156
169
|
const metaDir = fullMetadata
|
|
157
170
|
? (ctx.filterMetadata ? FULL_FILTERED_META_DIR : FULL_META_DIR)
|
|
158
171
|
: ABBREVIATED_META_DIR;
|
|
@@ -177,7 +190,19 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
177
190
|
ctx.metaCache.set(cacheKey, metaForCache);
|
|
178
191
|
}
|
|
179
192
|
const pickedPackage = pickMatchingVersionFinal(pickerOpts, spec, metaForCache);
|
|
180
|
-
|
|
193
|
+
const unverified = unverifiedDiskPackuments.has(metaForCache);
|
|
194
|
+
const stableCachedRangeVersion = unverified &&
|
|
195
|
+
canReuseStableCachedRange(spec, opts)
|
|
196
|
+
? getDominantLockfileVersion(spec.fetchSpec, opts.preferredVersionSelectors)
|
|
197
|
+
: null;
|
|
198
|
+
const unverifiedPickIsSafe = ctx.preferOffline === true ||
|
|
199
|
+
opts.pickLowestVersion === true ||
|
|
200
|
+
spec.type === 'version' ||
|
|
201
|
+
(pickedPackage != null && pickedPackage.version === stableCachedRangeVersion);
|
|
202
|
+
const cacheResultCanReturn = ctx.offline === true ||
|
|
203
|
+
!unverified ||
|
|
204
|
+
(pickedPackage != null && unverifiedPickIsSafe);
|
|
205
|
+
if (cacheResultCanReturn) {
|
|
181
206
|
return {
|
|
182
207
|
meta: metaForCache,
|
|
183
208
|
pickedPackage,
|
|
@@ -271,6 +296,35 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
271
296
|
}
|
|
272
297
|
}
|
|
273
298
|
}
|
|
299
|
+
const dominantLockfileVersion = canReuseStableCachedRange(spec, opts)
|
|
300
|
+
? getDominantLockfileVersion(spec.fetchSpec, opts.preferredVersionSelectors)
|
|
301
|
+
: null;
|
|
302
|
+
if (dominantLockfileVersion != null) {
|
|
303
|
+
diskMeta = diskMeta ?? await limit(loadMetaCondensed);
|
|
304
|
+
if (diskMeta != null) {
|
|
305
|
+
try {
|
|
306
|
+
const stableVersion = pickStableCachedRangeVersion({
|
|
307
|
+
meta: diskMeta,
|
|
308
|
+
preferredVersionSelectors: opts.preferredVersionSelectors,
|
|
309
|
+
versionRange: spec.fetchSpec,
|
|
310
|
+
});
|
|
311
|
+
if (stableVersion != null) {
|
|
312
|
+
// Strict dominance makes the preferred tier a singleton, so the
|
|
313
|
+
// highest-version picker used by the proof and the normal picker
|
|
314
|
+
// agree even if pickLowestVersion reaches this code in the future.
|
|
315
|
+
const pickedPackage = pickMatchingVersionFast(pickerOpts, spec, diskMeta);
|
|
316
|
+
if (pickedPackage?.version === stableVersion) {
|
|
317
|
+
cacheDiskLoadedMeta(ctx.metaCache, cacheKey, diskMeta);
|
|
318
|
+
return { meta: diskMeta, pickedPackage };
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// Any malformed cached metadata falls through to normal online
|
|
324
|
+
// resolution, matching the neighboring disk fast paths.
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
274
328
|
if (opts.publishedBy && opts.publishedByExclude?.(spec.name) !== true) {
|
|
275
329
|
const mtime = await limit(async () => getFileMtime(pkgMirror));
|
|
276
330
|
if (mtime != null && mtime >= opts.publishedBy) {
|
|
@@ -377,6 +431,7 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
377
431
|
// and most packages won't have been modified recently enough to need the full
|
|
378
432
|
// document. We only upgrade to full metadata when the package's modification
|
|
379
433
|
// date is recent enough that some versions might not yet be "mature."
|
|
434
|
+
let attemptedReleaseAgeUpgrade = false;
|
|
380
435
|
if (opts.publishedBy &&
|
|
381
436
|
!fullMetadata &&
|
|
382
437
|
meta.time == null &&
|
|
@@ -393,6 +448,7 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
393
448
|
if (!opts.dryRun) {
|
|
394
449
|
saveMetaBestEffort(pkgMirror, prepareJsonForDisk(resultToSave.meta, resultToSave.etag, resultToSave.jsonText));
|
|
395
450
|
}
|
|
451
|
+
attemptedReleaseAgeUpgrade = true;
|
|
396
452
|
const fullFetchResult = await ctx.fetch(spec.name, {
|
|
397
453
|
authHeaderValue: opts.authHeaderValue,
|
|
398
454
|
fullMetadata: true,
|
|
@@ -405,6 +461,9 @@ export async function pickPackage(ctx, spec, opts) {
|
|
|
405
461
|
}
|
|
406
462
|
}
|
|
407
463
|
meta = condenseMetaForCache(ctx, meta);
|
|
464
|
+
if (attemptedReleaseAgeUpgrade) {
|
|
465
|
+
ctx.releaseAgeUpgradeCheckedPackuments?.add(meta);
|
|
466
|
+
}
|
|
408
467
|
if (!opts.dryRun) {
|
|
409
468
|
// Mirror the raw registry body, unless the retained form is
|
|
410
469
|
// deliberately narrower: `filterMetadata` always mirrors the stripped
|
|
@@ -441,6 +500,7 @@ async function maybeUpgradeAbbreviatedMetaForReleaseAge(ctx, spec, opts, meta) {
|
|
|
441
500
|
if (ctx.offline === true ||
|
|
442
501
|
!opts.publishedBy ||
|
|
443
502
|
meta.time != null ||
|
|
503
|
+
ctx.releaseAgeUpgradeCheckedPackuments?.has(meta) === true ||
|
|
444
504
|
opts.publishedByExclude?.(spec.name) === true) {
|
|
445
505
|
return { meta };
|
|
446
506
|
}
|
|
@@ -468,8 +528,11 @@ async function maybeUpgradeAbbreviatedMetaForReleaseAge(ctx, spec, opts, meta) {
|
|
|
468
528
|
registry: opts.registry,
|
|
469
529
|
});
|
|
470
530
|
if (fullFetchResult.notModified) {
|
|
471
|
-
// Upgrade fetch came back 304:
|
|
472
|
-
// `pickMatchingVersionFinal`
|
|
531
|
+
// Upgrade fetch came back 304: the registry has no fuller form of this
|
|
532
|
+
// document, so keep it and let `pickMatchingVersionFinal` fall through to
|
|
533
|
+
// its warn-and-skip path. Remember the outcome against the packument
|
|
534
|
+
// itself so no other pick in this resolver repeats the request.
|
|
535
|
+
ctx.releaseAgeUpgradeCheckedPackuments?.add(meta);
|
|
473
536
|
return { meta };
|
|
474
537
|
}
|
|
475
538
|
return { meta: fullFetchResult.meta, upgradedFrom: fullFetchResult };
|
|
@@ -480,12 +543,26 @@ async function maybeUpgradeAbbreviatedMetaForReleaseAge(ctx, spec, opts, meta) {
|
|
|
480
543
|
* pre-upgrade abbreviated form without `time`, and every future install
|
|
481
544
|
* would re-trigger the upgrade fetch.
|
|
482
545
|
*/
|
|
546
|
+
/**
|
|
547
|
+
* The document to serve and cache after an upgrade attempt, marked so no
|
|
548
|
+
* later pick in this resolver repeats the request.
|
|
549
|
+
*
|
|
550
|
+
* Marking belongs here rather than in
|
|
551
|
+
* {@link maybeUpgradeAbbreviatedMetaForReleaseAge} because persisting the
|
|
552
|
+
* response to the mirror can hand back a different object, and only the one
|
|
553
|
+
* that reaches the cache is worth remembering. A registry whose full form is
|
|
554
|
+
* no more complete than its abbreviated one answers `200` rather than `304`,
|
|
555
|
+
* so both outcomes have to be marked — otherwise every dependency edge
|
|
556
|
+
* re-asks for the same full document.
|
|
557
|
+
*/
|
|
483
558
|
function upgradeMetaForCache(ctx, upgrade, opts) {
|
|
484
559
|
if (upgrade.upgradedFrom == null)
|
|
485
560
|
return upgrade.meta;
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
561
|
+
const meta = opts.dryRun
|
|
562
|
+
? condenseMetaForCache(ctx, upgrade.meta)
|
|
563
|
+
: persistUpgradedMeta(ctx, opts.pkgMirror, upgrade.upgradedFrom);
|
|
564
|
+
ctx.releaseAgeUpgradeCheckedPackuments?.add(meta);
|
|
565
|
+
return meta;
|
|
489
566
|
}
|
|
490
567
|
// A condensing resolver keeps and mirrors the condensed form — the mirror
|
|
491
568
|
// only has to carry `time` into the next install; otherwise the raw response
|
|
@@ -586,8 +663,17 @@ function isMissingTimeError(err) {
|
|
|
586
663
|
// memory via this Set as they resolve ever more distinct packages.
|
|
587
664
|
const MAX_WARNED_MISSING_TIME = 1024;
|
|
588
665
|
const warnedMissingTimeFor = new Set();
|
|
589
|
-
|
|
590
|
-
|
|
666
|
+
/**
|
|
667
|
+
* At most one warning per package per check. `minimumReleaseAge` and
|
|
668
|
+
* `trustPolicy` both go dark on the same missing field, so keying by package
|
|
669
|
+
* alone would let whichever check ran first silence the other and leave the
|
|
670
|
+
* user told about only one of the two skips.
|
|
671
|
+
*/
|
|
672
|
+
export function warnMissingTimeFieldOnce(pkgName, skippedCheck) {
|
|
673
|
+
// A package name cannot contain ':', so the check name prefix cannot
|
|
674
|
+
// collide with a name that happens to embed it.
|
|
675
|
+
const key = `${skippedCheck}:${pkgName}`;
|
|
676
|
+
if (warnedMissingTimeFor.has(key))
|
|
591
677
|
return;
|
|
592
678
|
if (warnedMissingTimeFor.size >= MAX_WARNED_MISSING_TIME) {
|
|
593
679
|
// Set preserves insertion order, so the first entry is the oldest.
|
|
@@ -595,8 +681,8 @@ export function warnMissingTimeFieldOnce(pkgName) {
|
|
|
595
681
|
if (oldest != null)
|
|
596
682
|
warnedMissingTimeFor.delete(oldest);
|
|
597
683
|
}
|
|
598
|
-
warnedMissingTimeFor.add(
|
|
599
|
-
globalWarn(`The metadata of ${pkgName} is missing the "time" field; skipping the
|
|
684
|
+
warnedMissingTimeFor.add(key);
|
|
685
|
+
globalWarn(`The metadata of ${pkgName} is missing the "time" field; skipping the ${skippedCheck} check for this package.`);
|
|
600
686
|
}
|
|
601
687
|
async function getFileMtime(filePath) {
|
|
602
688
|
try {
|
|
@@ -648,6 +734,7 @@ export async function loadMeta(pkgMirror) {
|
|
|
648
734
|
return null;
|
|
649
735
|
const headers = JSON.parse(data.slice(0, newlineIdx));
|
|
650
736
|
const meta = JSON.parse(data.slice(newlineIdx + 1));
|
|
737
|
+
dropIncompletePublishTimes(meta);
|
|
651
738
|
meta.etag = headers.etag;
|
|
652
739
|
return meta;
|
|
653
740
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PackageInRegistry, PackageMeta, PackageMetaWithTime } from '@pnpm/resolving.registry.types';
|
|
2
|
-
import type
|
|
2
|
+
import { type VersionSelectors } from '@pnpm/resolving.resolver-base';
|
|
3
3
|
import type { PackageVersionPolicy } from '@pnpm/types';
|
|
4
4
|
import type { RegistryPackageSpec } from './parseBareSpecifier.js';
|
|
5
5
|
export interface PickVersionByVersionRangeOptions {
|
|
@@ -41,3 +41,9 @@ export declare function applyPublishedByPolicy(meta: PackageMeta, publishedBy: D
|
|
|
41
41
|
export declare function assertMetaHasTime(meta: PackageMeta): asserts meta is PackageMetaWithTime;
|
|
42
42
|
export declare function pickLowestVersionByVersionRange({ meta, versionRange, preferredVersionSelectors }: PickVersionByVersionRangeOptions): string | null;
|
|
43
43
|
export declare function pickVersionByVersionRange({ meta, versionRange, preferredVersionSelectors }: PickVersionByVersionRangeOptions): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the cached version only when lockfile preferences prove that no
|
|
46
|
+
* version missing from the cached packument could tie or outrank it.
|
|
47
|
+
*/
|
|
48
|
+
export declare function pickStableCachedRangeVersion({ meta, preferredVersionSelectors, versionRange, }: PickVersionByVersionRangeOptions): string | null;
|
|
49
|
+
export declare function getDominantLockfileVersion(versionRange: string, preferredVersionSelectors?: VersionSelectors): string | null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import util from 'node:util';
|
|
2
2
|
import { PnpmError } from '@pnpm/error';
|
|
3
3
|
import { filterPkgMetadataByPublishDate } from '@pnpm/resolving.registry.pkg-metadata-filter';
|
|
4
|
+
import { EXISTING_VERSION_SELECTOR_WEIGHT, } from '@pnpm/resolving.resolver-base';
|
|
4
5
|
import semver from 'semver';
|
|
5
6
|
export function pickPackageFromMeta(pickVersionByVersionRangeFn, { preferredVersionSelectors, publishedBy, publishedByExclude, }, meta, spec) {
|
|
6
7
|
if (publishedBy) {
|
|
@@ -152,6 +153,86 @@ export function pickVersionByVersionRange({ meta, versionRange, preferredVersion
|
|
|
152
153
|
}
|
|
153
154
|
return maxVersion;
|
|
154
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Returns the cached version only when lockfile preferences prove that no
|
|
158
|
+
* version missing from the cached packument could tie or outrank it.
|
|
159
|
+
*/
|
|
160
|
+
export function pickStableCachedRangeVersion({ meta, preferredVersionSelectors, versionRange, }) {
|
|
161
|
+
const dominantLockfileVersion = getDominantLockfileVersion(versionRange, preferredVersionSelectors);
|
|
162
|
+
if (dominantLockfileVersion == null || meta.versions[dominantLockfileVersion] == null)
|
|
163
|
+
return null;
|
|
164
|
+
try {
|
|
165
|
+
const pickedVersion = pickVersionByVersionRange({ meta, preferredVersionSelectors, versionRange });
|
|
166
|
+
return pickedVersion === dominantLockfileVersion ? dominantLockfileVersion : null;
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
export function getDominantLockfileVersion(versionRange, preferredVersionSelectors) {
|
|
173
|
+
if (preferredVersionSelectors == null)
|
|
174
|
+
return null;
|
|
175
|
+
let lockfileVersion;
|
|
176
|
+
for (const [selector, value] of Object.entries(preferredVersionSelectors)) {
|
|
177
|
+
if (selector === versionRange)
|
|
178
|
+
continue;
|
|
179
|
+
const { selectorType, weight } = preferredSelectorInfo(value);
|
|
180
|
+
if (!Number.isSafeInteger(weight) || weight <= 0)
|
|
181
|
+
return null;
|
|
182
|
+
if (selectorType === 'version' &&
|
|
183
|
+
weight >= EXISTING_VERSION_SELECTOR_WEIGHT &&
|
|
184
|
+
semverSatisfiesLoose(selector, versionRange)) {
|
|
185
|
+
if (lockfileVersion != null)
|
|
186
|
+
return null;
|
|
187
|
+
lockfileVersion = selector;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (lockfileVersion == null)
|
|
191
|
+
return null;
|
|
192
|
+
let guaranteedLockfileWeight = 0;
|
|
193
|
+
let maximumOtherVersionWeight = 0;
|
|
194
|
+
for (const [selector, value] of Object.entries(preferredVersionSelectors)) {
|
|
195
|
+
if (selector === versionRange)
|
|
196
|
+
continue;
|
|
197
|
+
const { selectorType, weight } = preferredSelectorInfo(value);
|
|
198
|
+
switch (selectorType) {
|
|
199
|
+
case 'version':
|
|
200
|
+
if (selector === lockfileVersion) {
|
|
201
|
+
guaranteedLockfileWeight += weight;
|
|
202
|
+
}
|
|
203
|
+
else if (weight < EXISTING_VERSION_SELECTOR_WEIGHT &&
|
|
204
|
+
semverSatisfiesLoose(selector, versionRange)) {
|
|
205
|
+
maximumOtherVersionWeight += weight;
|
|
206
|
+
}
|
|
207
|
+
break;
|
|
208
|
+
case 'range':
|
|
209
|
+
if (semverSatisfiesLoose(lockfileVersion, selector)) {
|
|
210
|
+
guaranteedLockfileWeight += weight;
|
|
211
|
+
}
|
|
212
|
+
// Conservatively assume an unseen version can satisfy every preferred
|
|
213
|
+
// range, even when proving range intersection would be more precise.
|
|
214
|
+
maximumOtherVersionWeight += weight;
|
|
215
|
+
break;
|
|
216
|
+
case 'tag':
|
|
217
|
+
// A registry can move a tag between requests. Do not count its current
|
|
218
|
+
// target toward the lockfile version, and assume all tags could move to
|
|
219
|
+
// the same unseen version.
|
|
220
|
+
maximumOtherVersionWeight += weight;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
if (!Number.isSafeInteger(guaranteedLockfileWeight) ||
|
|
224
|
+
!Number.isSafeInteger(maximumOtherVersionWeight))
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
return guaranteedLockfileWeight > maximumOtherVersionWeight
|
|
228
|
+
? lockfileVersion
|
|
229
|
+
: null;
|
|
230
|
+
}
|
|
231
|
+
function preferredSelectorInfo(value) {
|
|
232
|
+
return typeof value === 'string'
|
|
233
|
+
? { selectorType: value, weight: 1 }
|
|
234
|
+
: value;
|
|
235
|
+
}
|
|
155
236
|
function prioritizePreferredVersions(meta, versionRange, preferredVerSelectors) {
|
|
156
237
|
const preferredVerSelectorsArr = Object.entries(preferredVerSelectors ?? {});
|
|
157
238
|
const versionsPrioritizer = new PreferredVersionsPrioritizer();
|
|
@@ -163,9 +244,7 @@ function prioritizePreferredVersions(meta, versionRange, preferredVerSelectors)
|
|
|
163
244
|
}
|
|
164
245
|
// Then apply weights from preferred selectors
|
|
165
246
|
for (const [preferredSelector, preferredSelectorType] of preferredVerSelectorsArr) {
|
|
166
|
-
const { selectorType, weight } =
|
|
167
|
-
? { selectorType: preferredSelectorType, weight: 1 }
|
|
168
|
-
: preferredSelectorType;
|
|
247
|
+
const { selectorType, weight } = preferredSelectorInfo(preferredSelectorType);
|
|
169
248
|
if (preferredSelector === versionRange)
|
|
170
249
|
continue;
|
|
171
250
|
switch (selectorType) {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PackageMeta } from '@pnpm/resolving.registry.types';
|
|
2
|
+
/**
|
|
3
|
+
* Drops `time` unless it carries a publish timestamp for every version the
|
|
4
|
+
* packument lists.
|
|
5
|
+
*
|
|
6
|
+
* Registries may answer with a partial map: npmmirror adds `time` to its
|
|
7
|
+
* abbreviated documents but fills it in only for the versions it has synced
|
|
8
|
+
* since it started recording publish times, leaving the rest out. A partial
|
|
9
|
+
* map is indistinguishable from a complete one at the point of use, so the
|
|
10
|
+
* `minimumReleaseAge` filter reads every absent timestamp as "not mature"
|
|
11
|
+
* and silently drops the version — resolution then falls back to the lowest
|
|
12
|
+
* match.
|
|
13
|
+
*
|
|
14
|
+
* A map that can't decide maturity is worth nothing to the resolver, so it
|
|
15
|
+
* is normalized away where the document is parsed. Every packument past that
|
|
16
|
+
* point then carries either a complete `time` or none at all — the shape the
|
|
17
|
+
* npm registry's own abbreviated documents have, and the one the rest of the
|
|
18
|
+
* resolver is written against.
|
|
19
|
+
*
|
|
20
|
+
* A packument with no versions keeps whatever `time` it has — there is
|
|
21
|
+
* nothing for the map to be incomplete about — and a version whose entry is
|
|
22
|
+
* an empty string counts as absent.
|
|
23
|
+
*/
|
|
24
|
+
export declare function dropIncompletePublishTimes(meta: PackageMeta): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drops `time` unless it carries a publish timestamp for every version the
|
|
3
|
+
* packument lists.
|
|
4
|
+
*
|
|
5
|
+
* Registries may answer with a partial map: npmmirror adds `time` to its
|
|
6
|
+
* abbreviated documents but fills it in only for the versions it has synced
|
|
7
|
+
* since it started recording publish times, leaving the rest out. A partial
|
|
8
|
+
* map is indistinguishable from a complete one at the point of use, so the
|
|
9
|
+
* `minimumReleaseAge` filter reads every absent timestamp as "not mature"
|
|
10
|
+
* and silently drops the version — resolution then falls back to the lowest
|
|
11
|
+
* match.
|
|
12
|
+
*
|
|
13
|
+
* A map that can't decide maturity is worth nothing to the resolver, so it
|
|
14
|
+
* is normalized away where the document is parsed. Every packument past that
|
|
15
|
+
* point then carries either a complete `time` or none at all — the shape the
|
|
16
|
+
* npm registry's own abbreviated documents have, and the one the rest of the
|
|
17
|
+
* resolver is written against.
|
|
18
|
+
*
|
|
19
|
+
* A packument with no versions keeps whatever `time` it has — there is
|
|
20
|
+
* nothing for the map to be incomplete about — and a version whose entry is
|
|
21
|
+
* an empty string counts as absent.
|
|
22
|
+
*/
|
|
23
|
+
export function dropIncompletePublishTimes(meta) {
|
|
24
|
+
if (meta.time == null)
|
|
25
|
+
return;
|
|
26
|
+
for (const version in meta.versions) {
|
|
27
|
+
if (!Object.hasOwn(meta.versions, version))
|
|
28
|
+
continue;
|
|
29
|
+
if (!Object.hasOwn(meta.time, version) || !meta.time[version]) {
|
|
30
|
+
delete meta.time;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=publishTimes.js.map
|
package/lib/trustChecks.d.ts
CHANGED
|
@@ -4,6 +4,20 @@ type TrustEvidence = 'provenance' | 'trustedPublisher' | 'stagedPublish';
|
|
|
4
4
|
export declare function failIfTrustDowngraded(meta: PackageMeta, version: string, opts?: {
|
|
5
5
|
trustPolicyExclude?: PackageVersionPolicy;
|
|
6
6
|
trustPolicyIgnoreAfter?: number;
|
|
7
|
+
/**
|
|
8
|
+
* The `minimumReleaseAgeIgnoreMissingTime` opt-in, which declares that
|
|
9
|
+
* the registry cannot date its releases. The downgrade check orders
|
|
10
|
+
* history by publish date, so a packument with no `time` map leaves it
|
|
11
|
+
* nothing to order and the check is skipped with a warning rather than
|
|
12
|
+
* aborting the install.
|
|
13
|
+
*
|
|
14
|
+
* Scoped to the whole map being absent, which `dropIncompletePublishTimes`
|
|
15
|
+
* makes the only shape a registry that dates some of its versions can
|
|
16
|
+
* reach here in. A packument that dates every version it lists is instead
|
|
17
|
+
* saying it does not have this one, so that shape keeps failing closed
|
|
18
|
+
* however this flag is set.
|
|
19
|
+
*/
|
|
20
|
+
ignoreMissingTimeField?: boolean;
|
|
7
21
|
}): void;
|
|
8
22
|
export declare function getTrustEvidence(manifest: PackageInRegistry): TrustEvidence | undefined;
|
|
9
23
|
export {};
|
package/lib/trustChecks.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PnpmError } from '@pnpm/error';
|
|
2
2
|
import semver from 'semver';
|
|
3
|
+
import { warnMissingTimeFieldOnce } from './pickPackage.js';
|
|
3
4
|
import { assertMetaHasTime } from './pickPackageFromMeta.js';
|
|
4
5
|
const TRUST_RANK = {
|
|
5
6
|
stagedPublish: 3,
|
|
@@ -16,6 +17,10 @@ export function failIfTrustDowngraded(meta, version, opts) {
|
|
|
16
17
|
return;
|
|
17
18
|
}
|
|
18
19
|
}
|
|
20
|
+
if (meta.time == null && opts?.ignoreMissingTimeField) {
|
|
21
|
+
warnMissingTimeFieldOnce(meta.name, 'trustPolicy');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
19
24
|
assertMetaHasTime(meta);
|
|
20
25
|
const versionPublishedAt = meta.time[version];
|
|
21
26
|
if (!versionPublishedAt) {
|
package/lib/violationCodes.d.ts
CHANGED
|
@@ -11,5 +11,6 @@
|
|
|
11
11
|
export declare const MINIMUM_RELEASE_AGE_VIOLATION_CODE = "MINIMUM_RELEASE_AGE_VIOLATION";
|
|
12
12
|
export declare const TRUST_DOWNGRADE_VIOLATION_CODE = "TRUST_DOWNGRADE";
|
|
13
13
|
export declare const TARBALL_URL_MISMATCH_VIOLATION_CODE = "TARBALL_URL_MISMATCH";
|
|
14
|
+
export declare const TARBALL_REVISION_MISMATCH_VIOLATION_CODE = "TARBALL_REVISION_MISMATCH";
|
|
14
15
|
export declare const MISSING_TARBALL_INTEGRITY_VIOLATION_CODE = "MISSING_TARBALL_INTEGRITY";
|
|
15
16
|
export declare const MISSING_NAMED_REGISTRY_VIOLATION_CODE = "MISSING_NAMED_REGISTRY";
|
package/lib/violationCodes.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
export const MINIMUM_RELEASE_AGE_VIOLATION_CODE = 'MINIMUM_RELEASE_AGE_VIOLATION';
|
|
12
12
|
export const TRUST_DOWNGRADE_VIOLATION_CODE = 'TRUST_DOWNGRADE';
|
|
13
13
|
export const TARBALL_URL_MISMATCH_VIOLATION_CODE = 'TARBALL_URL_MISMATCH';
|
|
14
|
+
export const TARBALL_REVISION_MISMATCH_VIOLATION_CODE = 'TARBALL_REVISION_MISMATCH';
|
|
14
15
|
export const MISSING_TARBALL_INTEGRITY_VIOLATION_CODE = 'MISSING_TARBALL_INTEGRITY';
|
|
15
16
|
export const MISSING_NAMED_REGISTRY_VIOLATION_CODE = 'MISSING_NAMED_REGISTRY';
|
|
16
17
|
//# sourceMappingURL=violationCodes.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/resolving.npm-resolver",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1104.1.0",
|
|
4
4
|
"description": "Resolver for npm-hosted packages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -29,24 +29,25 @@
|
|
|
29
29
|
"!*.map"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@pnpm/config.normalize-registries": "
|
|
33
|
-
"@pnpm/config.pick-registry-for-package": "
|
|
34
|
-
"@pnpm/config.version-policy": "1100.2.
|
|
35
|
-
"@pnpm/constants": "
|
|
36
|
-
"@pnpm/core-loggers": "1100.3.
|
|
37
|
-
"@pnpm/crypto.hash": "1100.0.
|
|
38
|
-
"@pnpm/deps.path": "
|
|
39
|
-
"@pnpm/error": "1100.1.
|
|
32
|
+
"@pnpm/config.normalize-registries": "1101.0.1",
|
|
33
|
+
"@pnpm/config.pick-registry-for-package": "1101.0.1",
|
|
34
|
+
"@pnpm/config.version-policy": "1100.2.2",
|
|
35
|
+
"@pnpm/constants": "1102.0.0",
|
|
36
|
+
"@pnpm/core-loggers": "1100.3.4",
|
|
37
|
+
"@pnpm/crypto.hash": "1100.0.3",
|
|
38
|
+
"@pnpm/deps.path": "1101.0.1",
|
|
39
|
+
"@pnpm/error": "1100.1.3",
|
|
40
40
|
"@pnpm/fetching.types": "1100.0.3",
|
|
41
|
-
"@pnpm/fs.graceful-fs": "1100.
|
|
42
|
-
"@pnpm/pkg-manifest.utils": "1100.4.
|
|
43
|
-
"@pnpm/resolving.jsr-specifier-parser": "1100.0.
|
|
44
|
-
"@pnpm/resolving.registry.pkg-metadata-filter": "1100.0.
|
|
45
|
-
"@pnpm/resolving.registry.types": "1100.
|
|
46
|
-
"@pnpm/resolving.resolver-base": "1101.
|
|
47
|
-
"@pnpm/
|
|
48
|
-
"@pnpm/store.
|
|
49
|
-
"@pnpm/
|
|
41
|
+
"@pnpm/fs.graceful-fs": "1100.2.0",
|
|
42
|
+
"@pnpm/pkg-manifest.utils": "1100.4.2",
|
|
43
|
+
"@pnpm/resolving.jsr-specifier-parser": "1100.0.6",
|
|
44
|
+
"@pnpm/resolving.registry.pkg-metadata-filter": "1100.0.18",
|
|
45
|
+
"@pnpm/resolving.registry.types": "1100.2.0",
|
|
46
|
+
"@pnpm/resolving.resolver-base": "1101.2.0",
|
|
47
|
+
"@pnpm/resolving.tarball-url": "1101.1.0",
|
|
48
|
+
"@pnpm/store.cafs": "1100.3.0",
|
|
49
|
+
"@pnpm/store.index": "1100.3.0",
|
|
50
|
+
"@pnpm/types": "1102.1.0",
|
|
50
51
|
"@pnpm/workspace.range-resolver": "1100.0.3",
|
|
51
52
|
"@pnpm/workspace.spec-parser": "1100.0.1",
|
|
52
53
|
"@zkochan/retry": "^0.2.0",
|
|
@@ -65,13 +66,13 @@
|
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
68
|
"@pnpm/logger": "^1100.0.0",
|
|
68
|
-
"@pnpm/worker": "^1100.
|
|
69
|
+
"@pnpm/worker": "^1100.4.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@jest/globals": "30.4.1",
|
|
72
73
|
"@pnpm/logger": "1100.0.0",
|
|
73
|
-
"@pnpm/network.fetch": "1100.1.
|
|
74
|
-
"@pnpm/resolving.npm-resolver": "
|
|
74
|
+
"@pnpm/network.fetch": "1100.1.14",
|
|
75
|
+
"@pnpm/resolving.npm-resolver": "1104.1.0",
|
|
75
76
|
"@pnpm/test-fixtures": "1100.0.1",
|
|
76
77
|
"@pnpm/testing.mock-agent": "1101.0.7",
|
|
77
78
|
"@types/normalize-path": "^3.0.2",
|