cli: make Lockfile analyze pick the most specific new version range

This commit is contained in:
Patrik Oldsberg
2020-11-22 14:48:12 +01:00
parent 0145faa6ee
commit 4c64272137
2 changed files with 9 additions and 3 deletions
@@ -122,7 +122,7 @@ describe('Lockfile', () => {
{
name: '@s/a',
oldRange: '^1',
newRange: '*',
newRange: '^2.0.x',
oldVersion: '1.0.1',
newVersion: '2.0.0',
},
+8 -2
View File
@@ -167,9 +167,15 @@ export class Lockfile {
continue;
}
// Find the max version and range that we may want bump older packages to
// Find the max version that we may want bump older packages to
const maxVersion = Array.from(acceptedVersions).sort(semver.rcompare)[0];
const maxEntry = entries.find(e => semver.satisfies(maxVersion, e.range));
// Find all existing ranges that satisfy the new max version, and pick the one that
// results in the highest minimum allowed version, usually being the more specific one
const maxEntry = entries
.filter(e => semver.satisfies(maxVersion, e.range))
.map(e => ({ e, min: semver.minVersion(e.range) }))
.filter(p => p.min)
.sort((a, b) => semver.rcompare(a.min!, b.min!))[0]?.e;
if (!maxEntry) {
throw new Error(
`No entry found that satisfies max version '${maxVersion}'`,