Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(resolvePeers): fix deduplication when version missmatch (#6606)
When dedupe-peer-dependents is enabled (default), use the path to determine compatibility. When multiple dependency groups can be deduplicated, the latter ones are sorted according to number of peers to allow them to benefit from deduplication. close #6605 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
- Loading branch information
Showing
3 changed files
with
164 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
"@pnpm/resolve-dependencies": patch | ||
"pnpm": patch | ||
--- | ||
|
||
When `dedupe-peer-dependents` is enabled (default), use the path (not id) to | ||
determine compatibility. | ||
|
||
When multiple dependency groups can be deduplicated, the | ||
latter ones are sorted according to number of peers to allow them to | ||
benefit from deduplication. | ||
|
||
Resolves: [#6605](https://github.com/pnpm/pnpm/issues/6605) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
pkg-manager/resolve-dependencies/test/dedupeDepPaths.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { resolvePeers } from '../lib/resolvePeers' | ||
|
||
test('packages are not deduplicated when versions do not match', () => { | ||
const fooPkg = { | ||
name: 'foo', | ||
version: '1.0.0', | ||
depPath: 'foo/1.0.0', | ||
peerDependencies: { | ||
bar: '1.0.0 || 2.0.0', | ||
baz: '1.0.0 || 2.0.0', | ||
}, | ||
peerDependenciesMeta: { | ||
baz: { | ||
optional: true, | ||
}, | ||
}, | ||
} | ||
|
||
const peers = Object.fromEntries( | ||
[ | ||
['bar', '1.0.0'], | ||
['bar', '2.0.0'], | ||
['baz', '1.0.0'], | ||
['baz', '2.0.0'], | ||
].map(([name, version]) => [ | ||
`${name}_${version.replace(/\./g, '_')}`, | ||
{ | ||
name, | ||
version, | ||
depPath: `${name}/${version}`, | ||
peerDependencies: {}, | ||
}, | ||
]) | ||
) | ||
|
||
const { dependenciesByProjectId } = resolvePeers({ | ||
projects: [ | ||
{ | ||
directNodeIdsByAlias: { | ||
foo: '>project1>foo/1.0.0>', | ||
bar: '>project1>bar/1.0.0>', | ||
}, | ||
topParents: [], | ||
rootDir: '', | ||
id: 'project1', | ||
}, | ||
{ | ||
directNodeIdsByAlias: { | ||
foo: '>project2>foo/1.0.0>', | ||
bar: '>project2>bar/1.0.0>', | ||
baz: '>project2>baz/1.0.0>', | ||
}, | ||
topParents: [], | ||
rootDir: '', | ||
id: 'project2', | ||
}, | ||
{ | ||
directNodeIdsByAlias: { | ||
foo: '>project3>foo/1.0.0>', | ||
bar: '>project3>bar/2.0.0>', | ||
}, | ||
topParents: [], | ||
rootDir: '', | ||
id: 'project3', | ||
}, | ||
{ | ||
directNodeIdsByAlias: { | ||
foo: '>project4>foo/1.0.0>', | ||
bar: '>project4>bar/2.0.0>', | ||
baz: '>project4>baz/2.0.0>', | ||
}, | ||
topParents: [], | ||
rootDir: '', | ||
id: 'project4', | ||
}, | ||
], | ||
dependenciesTree: Object.fromEntries([ | ||
['>project1>foo/1.0.0>', fooPkg], | ||
['>project1>bar/1.0.0>', peers.bar_1_0_0], | ||
|
||
['>project2>foo/1.0.0>', fooPkg], | ||
['>project2>bar/1.0.0>', peers.bar_1_0_0], | ||
['>project2>baz/1.0.0>', peers.baz_1_0_0], | ||
|
||
['>project3>foo/1.0.0>', fooPkg], | ||
['>project3>bar/2.0.0>', peers.bar_2_0_0], | ||
|
||
['>project4>foo/1.0.0>', fooPkg], | ||
['>project4>bar/2.0.0>', peers.bar_2_0_0], | ||
['>project4>baz/2.0.0>', peers.baz_2_0_0], | ||
|
||
].map(([path, resolvedPackage]) => [path, { | ||
children: {}, | ||
installable: {}, | ||
resolvedPackage, | ||
depth: 0, | ||
}])), | ||
dedupePeerDependents: true, | ||
virtualStoreDir: '', | ||
lockfileDir: '', | ||
}) | ||
|
||
expect(dependenciesByProjectId.project1.foo).toEqual(dependenciesByProjectId.project2.foo) | ||
expect(dependenciesByProjectId.project1.foo).not.toEqual(dependenciesByProjectId.project3.foo) | ||
expect(dependenciesByProjectId.project3.foo).toEqual(dependenciesByProjectId.project4.foo) | ||
}) |