fix: dependency deduplication (#7385)

fixes regression introduced via #7359
This commit is contained in:
Zoltan Kochan
2023-12-06 15:43:46 +01:00
committed by GitHub
parent 8a86facc06
commit 5462cb6d4e
6 changed files with 20 additions and 29 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/resolve-dependencies": patch
---
Fix dependencies deduplication.

View File

@@ -601,7 +601,6 @@ describe('patch and commit in workspaces', () => {
await install.handler({
...DEFAULT_OPTS,
cacheDir,
dedupeDirectDeps: true,
storeDir,
allProjects,
allProjectsGraph,
@@ -634,7 +633,6 @@ describe('patch and commit in workspaces', () => {
allProjects,
allProjectsGraph,
selectedProjectsGraph,
dedupeDirectDeps: true,
dir: process.cwd(),
rootProjectManifestDir: process.cwd(),
cacheDir,

View File

@@ -11,7 +11,6 @@ export const DEFAULT_OPTS = {
ca: undefined,
cacheDir: '../cache',
cert: undefined,
dedupeDirectDeps: false,
extraEnv: {},
cliOptions: {},
fetchRetries: 2,

View File

@@ -342,7 +342,6 @@ test('auto install peer deps in a workspace. test #1', async () => {
rootDir: path.resolve('project'),
},
],
dedupeDirectDeps: false,
}))
})
@@ -382,7 +381,6 @@ test('auto install peer deps in a workspace. test #2', async () => {
rootDir: path.resolve('project'),
},
],
dedupeDirectDeps: false,
}))
})

View File

@@ -221,7 +221,6 @@ export async function resolveDependencies (
} = resolvePeers({
dependenciesTree,
dedupePeerDependents: opts.dedupePeerDependents,
dedupeDirectDeps: opts.dedupeDirectDeps,
lockfileDir: opts.lockfileDir,
projects: projectsToLink,
virtualStoreDir: opts.virtualStoreDir,
@@ -252,6 +251,19 @@ export async function resolveDependencies (
}
}
}
if (opts.dedupeDirectDeps) {
const rootDeps = dependenciesByProjectId['.']
if (rootDeps) {
for (const [id, deps] of Object.entries(dependenciesByProjectId)) {
if (id === '.') continue
for (const [alias, depPath] of Object.entries(deps)) {
if (depPath === rootDeps[alias]) {
delete deps[alias]
}
}
}
}
}
const { newLockfile, pendingRequiresBuilds } = updateLockfile({
dependenciesGraph,

View File

@@ -63,7 +63,6 @@ export function resolvePeers<T extends PartialResolvedPackage> (
lockfileDir: string
resolvePeersFromWorkspaceRoot?: boolean
dedupePeerDependents?: boolean
dedupeDirectDeps?: boolean
}
): {
dependenciesGraph: GenericDependenciesGraph<T>
@@ -109,28 +108,8 @@ export function resolvePeers<T extends PartialResolvedPackage> (
})
const dependenciesByProjectId: { [id: string]: Record<string, string> } = {}
if (opts.dedupeDirectDeps) {
const rootProject = opts.projects.find(({ id }) => id === '.')
if (rootProject) {
dependenciesByProjectId['.'] = mapValues((nodeId) => pathsByNodeId.get(nodeId)!, rootProject.directNodeIdsByAlias)
}
const rootDeps = dependenciesByProjectId['.'] ?? {}
for (const { directNodeIdsByAlias, id } of opts.projects) {
if (id !== '.') {
const deps: Record<string, string> = {}
for (const [alias, nodeId] of Object.entries(directNodeIdsByAlias)) {
const depPath = pathsByNodeId.get(nodeId)!
if (rootDeps[alias] !== depPath) {
deps[alias] = depPath
}
}
dependenciesByProjectId[id] = deps
}
}
} else {
for (const { directNodeIdsByAlias, id } of opts.projects) {
dependenciesByProjectId[id] = mapValues((nodeId) => pathsByNodeId.get(nodeId)!, directNodeIdsByAlias)
}
for (const { directNodeIdsByAlias, id } of opts.projects) {
dependenciesByProjectId[id] = mapValues((nodeId) => pathsByNodeId.get(nodeId)!, directNodeIdsByAlias)
}
if (opts.dedupePeerDependents) {
const duplicates = Array.from(depPathsByPkgId.values()).filter((item) => item.size > 1)