From c3d2746aceea23af2a3eb690ac547dff1e0d328b Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Fri, 13 Aug 2021 02:50:43 +0300 Subject: [PATCH] fix: resolving peers from root of workspace when adding new dep (#3667) --- .changeset/purple-files-clap.md | 5 ++++ .../src/recursive.ts | 15 +++++++++- packages/pnpm/test/monorepo/index.ts | 29 +++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 .changeset/purple-files-clap.md diff --git a/.changeset/purple-files-clap.md b/.changeset/purple-files-clap.md new file mode 100644 index 0000000000..3f1b0f61f5 --- /dev/null +++ b/.changeset/purple-files-clap.md @@ -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. diff --git a/packages/plugin-commands-installation/src/recursive.ts b/packages/plugin-commands-installation/src/recursive.ts index 5ca940e206..5e0872f6d7 100755 --- a/packages/plugin-commands-installation/src/recursive.ts +++ b/packages/plugin-commands-installation/src/recursive.ts @@ -96,7 +96,7 @@ export default async function recursive ( return false } const manifestsByPath: { [dir: string]: Omit } = {} - 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.') diff --git a/packages/pnpm/test/monorepo/index.ts b/packages/pnpm/test/monorepo/index.ts index 651f3625b6..77ee2617e6 100644 --- a/packages/pnpm/test/monorepo/index.ts +++ b/packages/pnpm/test/monorepo/index.ts @@ -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']) +})