fix: peerDependencyRules with * as range (#4370)

This commit is contained in:
Zoltan Kochan
2022-02-22 00:38:47 +02:00
parent 863fd20cea
commit 076c3753a5
3 changed files with 14 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/core": patch
"pnpm": patch
---
When a peer dependency range is extended with `*`, just replace any range with `*`.

View File

@@ -18,7 +18,11 @@ export default function (
peerDependencyRules.allowedVersions?.[peerName] &&
peerVersion !== '*'
) {
pkg.peerDependencies![peerName] += ` || ${peerDependencyRules.allowedVersions[peerName]}`
if (peerDependencyRules.allowedVersions[peerName] === '*') {
pkg.peerDependencies![peerName] = '*'
} else {
pkg.peerDependencies![peerName] += ` || ${peerDependencyRules.allowedVersions[peerName]}`
}
}
}
return pkg

View File

@@ -22,6 +22,7 @@ test('createPeerDependencyPatcher() extends peer ranges', () => {
allowedVersions: {
foo: '1',
qar: '1',
baz: '*',
},
})
const patchedPkg = patcher({
@@ -29,11 +30,13 @@ test('createPeerDependencyPatcher() extends peer ranges', () => {
foo: '0',
bar: '0',
qar: '*',
baz: '1',
},
})
expect(patchedPkg['peerDependencies']).toStrictEqual({
foo: '0 || 1',
bar: '0',
qar: '*',
baz: '*',
})
})