mirror of
https://github.com/pnpm/pnpm.git
synced 2026-02-08 22:22:05 -05:00
fix: installation with filtering and dedupe-peer-dependents=true (#8270)
close #6300
This commit is contained in:
6
.changeset/three-dingos-roll.md
Normal file
6
.changeset/three-dingos-roll.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Installation with filtering should work, when `dedupe-peer-dependents` is set to `true` [#6300](https://github.com/pnpm/pnpm/issues/6300).
|
||||
@@ -241,7 +241,7 @@ export async function mutateModules (
|
||||
throw new PnpmError('OPTIONAL_DEPS_REQUIRE_PROD_DEPS', 'Optional dependencies cannot be installed without production dependencies')
|
||||
}
|
||||
|
||||
const installsOnly = projects.every((project) => project.mutation === 'install' && !project.update && !project.updateMatching)
|
||||
const installsOnly = allMutationsAreInstalls(projects)
|
||||
if (!installsOnly) opts.strictPeerDependencies = false
|
||||
// @ts-expect-error
|
||||
opts['forceNewModules'] = installsOnly
|
||||
@@ -1437,6 +1437,10 @@ const _installInContext: InstallFunction = async (projects, ctx, opts) => {
|
||||
}
|
||||
}
|
||||
|
||||
function allMutationsAreInstalls (projects: MutatedProject[]): boolean {
|
||||
return projects.every((project) => project.mutation === 'install' && !project.update && !project.updateMatching)
|
||||
}
|
||||
|
||||
const installInContext: InstallFunction = async (projects, ctx, opts) => {
|
||||
try {
|
||||
const isPathInsideWorkspace = isSubdir.bind(null, opts.lockfileDir)
|
||||
@@ -1445,6 +1449,7 @@ const installInContext: InstallFunction = async (projects, ctx, opts) => {
|
||||
.filter((project) => isPathInsideWorkspace(project.rootDirRealPath ?? project.rootDir))
|
||||
if (allProjectsLocatedInsideWorkspace.length > projects.length) {
|
||||
if (
|
||||
allMutationsAreInstalls(projects) &&
|
||||
await allProjectsAreUpToDate(allProjectsLocatedInsideWorkspace, {
|
||||
catalogs: opts.catalogs,
|
||||
autoInstallPeers: opts.autoInstallPeers,
|
||||
|
||||
@@ -183,12 +183,11 @@ export async function recursive (
|
||||
mutation = (params.length === 0 && !updateToLatest ? 'install' : 'installSome')
|
||||
break
|
||||
}
|
||||
const writeProjectManifests = [] as Array<(manifest: ProjectManifest) => Promise<void>>
|
||||
const mutatedImporters = [] as MutatedProject[]
|
||||
await Promise.all(importers.map(async ({ rootDir }) => {
|
||||
const localConfig = await memReadLocalConfig(rootDir)
|
||||
const modulesDir = localConfig.modulesDir ?? opts.modulesDir
|
||||
const { manifest, writeProjectManifest } = manifestsByPath[rootDir]
|
||||
const { manifest } = manifestsByPath[rootDir]
|
||||
let currentInput = [...params]
|
||||
if (updateMatch != null) {
|
||||
currentInput = matchDependencies(updateMatch, manifest, includeDirect)
|
||||
@@ -207,7 +206,6 @@ export async function recursive (
|
||||
currentInput = createWorkspaceSpecs(currentInput, workspacePackages)
|
||||
}
|
||||
}
|
||||
writeProjectManifests.push(writeProjectManifest)
|
||||
switch (mutation) {
|
||||
case 'uninstallSome':
|
||||
mutatedImporters.push({
|
||||
@@ -249,24 +247,11 @@ export async function recursive (
|
||||
}
|
||||
}))
|
||||
if (!opts.selectedProjectsGraph[opts.workspaceDir] && manifestsByPath[opts.workspaceDir] != null) {
|
||||
const { writeProjectManifest } = manifestsByPath[opts.workspaceDir]
|
||||
writeProjectManifests.push(writeProjectManifest)
|
||||
mutatedImporters.push({
|
||||
mutation: 'install',
|
||||
rootDir: opts.workspaceDir,
|
||||
})
|
||||
}
|
||||
if (opts.dedupePeerDependents) {
|
||||
for (const rootDir of Object.keys(opts.allProjectsGraph)) {
|
||||
if (opts.selectedProjectsGraph[rootDir] || rootDir === opts.workspaceDir) continue
|
||||
const { writeProjectManifest } = manifestsByPath[rootDir]
|
||||
writeProjectManifests.push(writeProjectManifest)
|
||||
mutatedImporters.push({
|
||||
mutation: 'install',
|
||||
rootDir,
|
||||
})
|
||||
}
|
||||
}
|
||||
if ((mutatedImporters.length === 0) && cmdFullName === 'update' && opts.depth === 0) {
|
||||
throw new PnpmError('NO_PACKAGE_IN_DEPENDENCIES',
|
||||
'None of the specified packages were found in the dependencies of any of the projects.')
|
||||
@@ -278,7 +263,9 @@ export async function recursive (
|
||||
if (opts.save !== false) {
|
||||
await Promise.all(
|
||||
mutatedPkgs
|
||||
.map(async ({ originalManifest, manifest }, index) => writeProjectManifests[index](originalManifest ?? manifest))
|
||||
.map(async ({ originalManifest, manifest, rootDir }) => {
|
||||
return manifestsByPath[rootDir].writeProjectManifest(originalManifest ?? manifest)
|
||||
})
|
||||
)
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user