mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: resolving peers from root of workspace when adding new dep (#3667)
This commit is contained in:
5
.changeset/purple-files-clap.md
Normal file
5
.changeset/purple-files-clap.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-installation": patch
|
||||
---
|
||||
|
||||
Peer depednencies are resolved from the root of the workspace when a new dependency is added to the root of the workspace.
|
||||
@@ -96,7 +96,7 @@ export default async function recursive (
|
||||
return false
|
||||
}
|
||||
const manifestsByPath: { [dir: string]: Omit<Project, 'dir'> } = {}
|
||||
for (const { dir, manifest, writeProjectManifest } of pkgs) {
|
||||
for (const { dir, manifest, writeProjectManifest } of allProjects) {
|
||||
manifestsByPath[dir] = { manifest, writeProjectManifest }
|
||||
}
|
||||
|
||||
@@ -241,6 +241,19 @@ export default async function recursive (
|
||||
} as MutatedProject)
|
||||
}
|
||||
}))
|
||||
if (!opts.selectedProjectsGraph[opts.workspaceDir] && manifestsByPath[opts.workspaceDir] != null) {
|
||||
const localConfig = await memReadLocalConfig(opts.workspaceDir)
|
||||
const modulesDir = localConfig.modulesDir ?? opts.modulesDir
|
||||
const { manifest, writeProjectManifest } = manifestsByPath[opts.workspaceDir]
|
||||
writeProjectManifests.push(writeProjectManifest)
|
||||
mutatedImporters.push({
|
||||
buildIndex: 0,
|
||||
manifest,
|
||||
modulesDir,
|
||||
mutation: 'install',
|
||||
rootDir: opts.workspaceDir,
|
||||
} as MutatedProject)
|
||||
}
|
||||
if ((mutatedImporters.length === 0) && cmdFullName === 'update') {
|
||||
throw new PnpmError('NO_PACKAGE_IN_DEPENDENCIES',
|
||||
'None of the specified packages were found in the dependencies of any of the projects.')
|
||||
|
||||
@@ -1393,3 +1393,32 @@ test('pnpm run should include the workspace root when --workspace-root option is
|
||||
expect(await exists('test')).toBeTruthy()
|
||||
expect(await exists('project/test')).toBeTruthy()
|
||||
})
|
||||
|
||||
test('peer dependencies are resolved from the root of the workspace when a new dependency is added to a workspace project', async () => {
|
||||
const projects = preparePackages([
|
||||
{
|
||||
location: '.',
|
||||
package: {
|
||||
name: 'project-1',
|
||||
version: '1.0.0',
|
||||
|
||||
dependencies: {
|
||||
ajv: '4.10.4',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'project-2',
|
||||
version: '1.0.0',
|
||||
},
|
||||
])
|
||||
|
||||
await writeYamlFile('pnpm-workspace.yaml', { packages: ['**', '!store/**'] })
|
||||
|
||||
process.chdir('project-2')
|
||||
|
||||
await execPnpm(['add', 'ajv-keywords@1.5.0', '--strict-peer-dependencies'])
|
||||
|
||||
const lockfile = await projects['project-1'].readLockfile()
|
||||
expect(lockfile.packages).toHaveProperty(['/ajv-keywords/1.5.0_ajv@4.10.4'])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user