fix: allowedVersions corner case when only parent>child selectors exist (#6148)

This commit is contained in:
jereklas
2023-02-28 04:57:02 -08:00
committed by GitHub
parent 059c6e83bd
commit d583fbb2ad
3 changed files with 28 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/hooks.read-package-hook": patch
---
Fixed issue where allowedVersions wouldn't apply correctly if only parent>child selectors were used

View File

@@ -36,11 +36,10 @@ export function createPeerDependencyPatcher (
pkg.peerDependencies![peerName] = '*'
continue
}
if (
!peerDependencyRules.allowedVersions?.[peerName] ||
peerVersion === '*'
) continue
if (peerDependencyRules.allowedVersions[peerName] === '*') {
if (!allowedVersions?.[peerName] || peerVersion === '*') {
continue
}
if (allowedVersions?.[peerName].includes('*')) {
pkg.peerDependencies![peerName] = '*'
continue
}

View File

@@ -168,6 +168,25 @@ test('createPeerDependencyPatcher() overrides peerDependencies when parent>child
})
})
// corner case exists when a 'parent>child' allowedVersion selector is used without a 'child' selector
test('createPeerDependencyPatcher() corner case correctly applies override', () => {
const patcher = createPeerDependencyPatcher({
allowedVersions: {
'foo>bar': '2',
},
})
const patchedPkg = patcher({
name: 'foo',
peerDependencies: {
bar: '0 || 1',
},
}) as ProjectManifest
expect(patchedPkg.peerDependencies).toStrictEqual({
bar: '0 || 1 || 2',
})
})
test('createPeerDependencyPathcer() throws expected error if parent>child selector cannot parse', () => {
expect(() => createPeerDependencyPatcher({
allowedVersions: {