fix: don't crash when peer ranges cannot be merged (#4136)

close #4134
This commit is contained in:
Zoltan Kochan
2021-12-15 20:12:23 +02:00
committed by GitHub
parent 890549b7d8
commit cb1827b9c2
2 changed files with 15 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
If making an intersection of peer dependency ranges does not succeed, install should not crash [#4134](https://github.com/pnpm/pnpm/issues/4134).

View File

@@ -10,7 +10,7 @@ export function mergePeers (missingPeers: MissingPeerIssuesByPeerName) {
intersections[peerName] = ranges[0].wantedRange
continue
}
const intersection = intersect(...ranges.map(({ wantedRange }) => wantedRange))
const intersection = safeIntersect(ranges.map(({ wantedRange }) => wantedRange))
if (intersection === null) {
conflicts.push(peerName)
} else {
@@ -19,3 +19,11 @@ export function mergePeers (missingPeers: MissingPeerIssuesByPeerName) {
}
return { conflicts, intersections }
}
function safeIntersect (ranges: string[]): null | string {
try {
return intersect(...ranges)
} catch {
return null
}
}