mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 02:53:15 -04:00
fix: handle non-string version selectors in hoistPeers (#11048)
* test: add test for version selector with weight in hoistPeers * fix: handle non-string version selectors in hoistPeers
This commit is contained in:
6
.changeset/plenty-jokes-wave.md
Normal file
6
.changeset/plenty-jokes-wave.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/installing.deps-resolver": patch
|
||||
pnpm: patch
|
||||
---
|
||||
|
||||
Improved handling of non-string version selectors in an internal function (e.g. `hoistPeers`).
|
||||
@@ -29,7 +29,8 @@ export function hoistPeers (
|
||||
if (opts.allPreferredVersions![peerName]) {
|
||||
const versions: string[] = []
|
||||
const nonVersions: string[] = []
|
||||
for (const [spec, specType] of Object.entries(opts.allPreferredVersions![peerName])) {
|
||||
for (const [spec, selector] of Object.entries(opts.allPreferredVersions![peerName])) {
|
||||
const specType = typeof selector === 'string' ? selector : selector.selectorType
|
||||
if (specType === 'version') {
|
||||
versions.push(spec)
|
||||
} else {
|
||||
|
||||
@@ -96,6 +96,21 @@ test('hoistPeers handles workspace: protocol range without throwing', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// Regression test for https://github.com/pnpm/pnpm/pull/11048
|
||||
test('hoistPeers handles version selector with weight', () => {
|
||||
expect(hoistPeers({
|
||||
autoInstallPeers: true,
|
||||
allPreferredVersions: {
|
||||
foo: {
|
||||
'1.0.0': { selectorType: 'version', weight: 1 },
|
||||
},
|
||||
},
|
||||
workspaceRootDeps: [],
|
||||
}, [['foo', { range: '1' }]])).toStrictEqual({
|
||||
foo: '1.0.0',
|
||||
})
|
||||
})
|
||||
|
||||
test('getHoistableOptionalPeers only picks a version that satisfies all optional ranges', () => {
|
||||
expect(getHoistableOptionalPeers({
|
||||
foo: ['2', '2.1'],
|
||||
|
||||
Reference in New Issue
Block a user