fix: resolving peers from root of workspace when adding new dep (#3667)

This commit is contained in:
Zoltan Kochan
2021-08-13 02:50:43 +03:00
committed by GitHub
parent 6208e2a71e
commit c3d2746ace
3 changed files with 48 additions and 1 deletions

View 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.

View File

@@ -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.')

View File

@@ -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'])
})