mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-28 02:53:15 -04:00
fix: invalid specifiers for peers on all non-exact version selectors (#11049)
* test: add test for hoist peers when given all range version selectors
* fix: invalid specifiers for peers on non-string version selectors
In tests, the bare specifier for the `@pnpm.e2e/peer-a` dependency
became ` || 1.0.0`. This was because the `versions` array could be
empty, causing the `.join(' || ')` operation to execute on a holey
array.
This caused a test in `installing/commands/test/update/update.ts` to
fail.
This commit is contained in:
6
.changeset/better-states-play.md
Normal file
6
.changeset/better-states-play.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/installing.deps-resolver": patch
|
||||
pnpm: patch
|
||||
---
|
||||
|
||||
Fixed a bug in an internal `hoistPeers` function that could cause peer dependencies to be re-resolved instead of locked to existing versions when upgrading packages in rare cases.
|
||||
@@ -53,7 +53,9 @@ export function hoistPeers (
|
||||
// Use the range directly so pnpm resolves it from the registry.
|
||||
dependencies[peerName] = range
|
||||
} else {
|
||||
dependencies[peerName] = [semver.maxSatisfying(versions, '*', { includePrerelease: true }), ...nonVersions].join(' || ')
|
||||
dependencies[peerName] = [semver.maxSatisfying(versions, '*', { includePrerelease: true }), ...nonVersions]
|
||||
.filter(spec => spec != null)
|
||||
.join(' || ')
|
||||
}
|
||||
} else if (opts.autoInstallPeers) {
|
||||
dependencies[peerName] = range
|
||||
|
||||
@@ -82,6 +82,21 @@ test('hoistPeers reuses higher preferred version when range is not exact', () =>
|
||||
})
|
||||
})
|
||||
|
||||
// Regression test for https://github.com/pnpm/pnpm/pull/11049
|
||||
test('hoistPeers returns valid specifier when given only range preferred version selectors', () => {
|
||||
expect(hoistPeers({
|
||||
autoInstallPeers: true,
|
||||
allPreferredVersions: {
|
||||
foo: {
|
||||
'^2.0.0': 'range',
|
||||
},
|
||||
},
|
||||
workspaceRootDeps: [],
|
||||
}, [['foo', { range: '2' }]])).toStrictEqual({
|
||||
foo: '^2.0.0',
|
||||
})
|
||||
})
|
||||
|
||||
test('hoistPeers handles workspace: protocol range without throwing', () => {
|
||||
expect(hoistPeers({
|
||||
autoInstallPeers: true,
|
||||
|
||||
Reference in New Issue
Block a user