Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto-install-peers #4855

Merged
merged 11 commits into from Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/strange-ants-remain.md
@@ -0,0 +1,6 @@
---
"pnpm": patch
"@pnpm/resolve-dependencies": patch
---

When the same package is found several times in the dependency graph, correctly autoinstall its missing peer dependencies at all times [#4820](https://github.com/pnpm/pnpm/issues/4820).
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,8 @@
"preinstall": "npx only-allow pnpm",
"prepare": "husky install",
"pretest": "pnpm run compile-only && pnpm --dir=fixtures run prepareFixtures",
"lint": "pnpm lint:meta && syncpack list-mismatches && eslint **/src/**/*.ts **/test/**/*.ts",
"lint": "pnpm lint:meta && syncpack list-mismatches && pnpm run lint:ts",
"lint:ts": "eslint **/src/**/*.ts **/test/**/*.ts",
"test-main": "pnpm pretest && pnpm lint --quiet && run-p -r verdaccio test-pkgs-main",
"remove-temp-dir": "shx rm -rf ../pnpm_tmp",
"test-pkgs-main": "pnpm remove-temp-dir && cross-env PNPM_REGISTRY_MOCK_UPLINK=http://localhost:7348 pnpm --filter=./packages/** --filter=./privatePackages/** run --no-sort --workspace-concurrency=2 _test",
Expand Down Expand Up @@ -38,7 +39,7 @@
"@commitlint/prompt-cli": "^16.0.0",
"@pnpm/eslint-config": "workspace:*",
"@pnpm/meta-updater": "0.0.6",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/tsconfig": "workspace:*",
"@types/jest": "^27.4.0",
"@types/node": "^14.17.32",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -74,7 +74,7 @@
"@pnpm/logger": "^4.0.0",
"@pnpm/package-store": "workspace:13.0.6",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/store-path": "workspace:6.0.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/fs-extra": "^9.0.5",
Expand Down
79 changes: 78 additions & 1 deletion packages/core/test/install/autoInstallPeers.ts
@@ -1,6 +1,6 @@
import { addDependenciesToPackage } from '@pnpm/core'
import { prepareEmpty, preparePackages } from '@pnpm/prepare'
import { addDistTag } from '@pnpm/registry-mock'
import { addDistTag, REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import { testDefaults } from '../utils'

test('auto install non-optional peer dependencies', async () => {
Expand Down Expand Up @@ -61,3 +61,80 @@ test('don\'t fail on linked package, when peers are auto installed', async () =>
const updatedManifest = await addDependenciesToPackage(pkgManifest, ['peer-b'], await testDefaults({ autoInstallPeers: true }))
expect(Object.keys(updatedManifest.dependencies ?? {})).toStrictEqual(['linked', 'peer-b'])
})

test('hoist a peer dependency in order to reuse it by other dependencies, when it satisfies them', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, ['@pnpm/xyz-parent-parent-parent-parent', '@pnpm/xyz-parent-parent-with-xyz'], await testDefaults({ autoInstallPeers: true }))
const lockfile = await project.readLockfile()
expect(Object.keys(lockfile.packages)).toStrictEqual([
'/@pnpm/x/1.0.0',
'/@pnpm/xyz-parent-parent-parent-parent/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/xyz-parent-parent-parent/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/xyz-parent-parent-with-xyz/1.0.0',
'/@pnpm/xyz-parent-parent/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/xyz-parent/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/xyz/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/y/1.0.0',
'/@pnpm/z/1.0.0',
])
})

test('don\'t hoist a peer dependency when there is a root dependency by that name', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, [
'@pnpm/xyz-parent-parent-parent-parent',
'@pnpm/xyz-parent-parent-with-xyz',
'@pnpm/x@npm:peer-a@1.0.0',
`http://localhost:${REGISTRY_MOCK_PORT}/@pnpm/y/-/y-2.0.0.tgz`,
], await testDefaults({ autoInstallPeers: true }))
const lockfile = await project.readLockfile()
expect(Object.keys(lockfile.packages)).toStrictEqual([
'/@pnpm/x/1.0.0',
'/@pnpm/xyz-parent-parent-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent-parent-with-xyz/1.0.0',
'/@pnpm/xyz-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/xyz/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz/1.0.0_e5suan7fvtov6fikg25btc2odi',
'/@pnpm/y/1.0.0',
'/@pnpm/y/2.0.0',
'/@pnpm/z/1.0.0',
'/peer-a/1.0.0',
])
})

test('don\'t auto-install a peer dependency, when that dependency is in the root', async () => {
const project = prepareEmpty()
await addDependenciesToPackage({}, [
'@pnpm/xyz-parent-parent-parent-parent',
'@pnpm/x@npm:peer-a@1.0.0',
`http://localhost:${REGISTRY_MOCK_PORT}/@pnpm/y/-/y-2.0.0.tgz`,
], await testDefaults({ autoInstallPeers: true }))
const lockfile = await project.readLockfile()
expect(Object.keys(lockfile.packages)).toStrictEqual([
'/@pnpm/xyz-parent-parent-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz-parent/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/xyz/1.0.0_c3hmehglzcfufab5hu6m6d76li',
'/@pnpm/y/2.0.0',
'/@pnpm/z/1.0.0',
'/peer-a/1.0.0',
])
})

test('don\'t install the same missing peer dependency twice', async () => {
await addDistTag({ package: '@pnpm/y', version: '2.0.0', distTag: 'latest' })
const project = prepareEmpty()
await addDependenciesToPackage({}, [
'has-has-y-peer-peer',
], await testDefaults({ autoInstallPeers: true }))
const lockfile = await project.readLockfile()
expect(Object.keys(lockfile.packages)).toStrictEqual([
'/@pnpm/y/1.0.0',
'/has-has-y-peer-peer/1.0.0_c7ewbmm644hn6ztbh6kbjiyhkq',
'/has-y-peer/1.0.0_@pnpm+y@1.0.0',
])
})
2 changes: 1 addition & 1 deletion packages/headless/package.json
Expand Up @@ -22,7 +22,7 @@
"@pnpm/package-store": "workspace:13.0.6",
"@pnpm/prepare": "workspace:*",
"@pnpm/read-projects-context": "workspace:6.0.3",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/store-path": "workspace:6.0.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/fs-extra": "^9.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/package-requester/package.json
Expand Up @@ -65,7 +65,7 @@
"@pnpm/create-cafs-store": "workspace:1.0.2",
"@pnpm/logger": "^4.0.0",
"@pnpm/package-requester": "workspace:18.0.6",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/normalize-path": "^3.0.0",
"@types/ramda": "0.27.39",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-installation/package.json
Expand Up @@ -39,7 +39,7 @@
"@pnpm/modules-yaml": "workspace:10.0.1",
"@pnpm/plugin-commands-installation": "workspace:10.0.11",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/is-ci": "^3.0.0",
"@types/proxyquire": "^1.3.28",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-listing/package.json
Expand Up @@ -38,7 +38,7 @@
"@pnpm/plugin-commands-installation": "workspace:10.0.11",
"@pnpm/plugin-commands-listing": "workspace:5.0.10",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@types/ramda": "0.27.39",
"execa": "npm:safe-execa@^0.1.1",
"strip-ansi": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-outdated/package.json
Expand Up @@ -38,7 +38,7 @@
"@pnpm/plugin-commands-installation": "workspace:10.0.11",
"@pnpm/plugin-commands-outdated": "workspace:6.0.10",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@types/lru-cache": "^5.1.0",
"@types/ramda": "0.27.39",
"@types/wrap-ansi": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-publishing/package.json
Expand Up @@ -39,7 +39,7 @@
"@pnpm/logger": "^4.0.0",
"@pnpm/plugin-commands-publishing": "workspace:5.0.11",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@types/cross-spawn": "^6.0.2",
"@types/is-ci": "^3.0.0",
"@types/is-windows": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-rebuild/package.json
Expand Up @@ -37,7 +37,7 @@
"@pnpm/logger": "^4.0.0",
"@pnpm/plugin-commands-rebuild": "workspace:6.1.9",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/ramda": "0.27.39",
"@types/semver": "^7.3.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-script-runners/package.json
Expand Up @@ -38,7 +38,7 @@
"@pnpm/logger": "^4.0.0",
"@pnpm/plugin-commands-script-runners": "workspace:5.0.12",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@types/is-windows": "^1.0.0",
"@types/ramda": "0.27.39",
"is-windows": "^1.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-store/package.json
Expand Up @@ -38,7 +38,7 @@
"@pnpm/logger": "^4.0.0",
"@pnpm/plugin-commands-store": "workspace:5.1.9",
"@pnpm/prepare": "workspace:*",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@types/archy": "0.0.31",
"@types/ramda": "0.27.39",
"@types/ssri": "^7.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/pnpm/package.json
Expand Up @@ -55,7 +55,7 @@
"@pnpm/prepare": "workspace:*",
"@pnpm/read-package-json": "workspace:6.0.2",
"@pnpm/read-project-manifest": "workspace:3.0.2",
"@pnpm/registry-mock": "2.17.0",
"@pnpm/registry-mock": "2.19.0",
"@pnpm/run-npm": "workspace:4.0.1",
"@pnpm/tabtab": "^0.1.2",
"@pnpm/types": "workspace:8.0.1",
Expand Down