Fix: install peerDeps which is not optional on headless install (#5243)

* fix: install peerDeps which is not optional on headless install

* chore: add testcase for install peerDependencies which is not optional

* refactor: auto install

Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
Shinobu Hayashi
2022-08-23 09:27:44 +09:00
committed by GitHub
parent c242672f5a
commit 1beb1b4bd4
6 changed files with 63 additions and 4 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/filter-lockfile": patch
"@pnpm/headless": patch
"pnpm": patch
---
Auto install peer dependencies when auto-install-peers is set to true and the lockfile is up to date [#5213](https://github.com/pnpm/pnpm/issues/5213).

View File

@@ -161,10 +161,7 @@ function pkgAllDeps (
...pkgSnapshot.dependencies,
...(opts.include.optionalDependencies ? pkgSnapshot.optionalDependencies : {}),
})
.map(([pkgName, ref]) => {
if (pkgSnapshot.peerDependencies?.[pkgName]) return null
return dp.refToRelative(ref, pkgName)
})
.map(([pkgName, ref]) => dp.refToRelative(ref, pkgName))
.filter((nodeId) => nodeId !== null) as string[]
pkgAllDeps(ctx, nextRelDepPaths, installable, opts)

View File

@@ -0,0 +1 @@
auto-install-peers=true

View File

@@ -0,0 +1,7 @@
{
"name": "reinstall-peer-deps",
"version": "1.0.0",
"devDependencies": {
"@pnpm.e2e/abc": "1.0.0"
}
}

View File

@@ -0,0 +1,37 @@
lockfileVersion: 5.4
specifiers:
'@pnpm.e2e/abc': 1.0.0
devDependencies:
'@pnpm.e2e/abc': 1.0.0_glqo5zmflraj4jc2fza4v4hjou
packages:
/@pnpm.e2e/abc/1.0.0_glqo5zmflraj4jc2fza4v4hjou:
resolution: {integrity: sha512-/BCMmCRQ58DLWtF5iU97Lbf0s+llpWHvvZvQfFnCYFBpa1pfYnlJW1k6+Z4UzcUdYrUvyDmYPwxGVvPStAUw1w==}
peerDependencies:
'@pnpm.e2e/peer-a': ^1.0.0
'@pnpm.e2e/peer-b': ^1.0.0
'@pnpm.e2e/peer-c': ^1.0.0
dependencies:
'@pnpm.e2e/dep-of-pkg-with-1-dep': 100.0.0
'@pnpm.e2e/peer-a': 1.0.1
'@pnpm.e2e/peer-b': 1.0.0
'@pnpm.e2e/peer-c': 1.0.1
dev: true
/@pnpm.e2e/dep-of-pkg-with-1-dep/100.0.0:
resolution: {integrity: sha512-KUmwlEiE3pzpmPCfrLkoOO7fmL4Tft+dcm6YQlUfOUJvHO73xlcKVoA/xOHP/ayUO8GiPlIqWRbKHrsxvXGE8g==}
dev: true
/@pnpm.e2e/peer-a/1.0.1:
resolution: {integrity: sha512-eKxesosmflSp5xnW1gyRhMZ75RLI7SupTZNe1SK6EPDDgNmswNxbwdpyUDFUDWa3yHd5WSQbRDH2IysqMWIs2g==}
dev: true
/@pnpm.e2e/peer-b/1.0.0:
resolution: {integrity: sha512-jvRKPPRU2qx/AxfcpyO/aSX8TQclpXUXOnUbSLxgBi+P4+InCRkK2u+jFQbcc+b8rIFzR0jr7YCIYLIjRDPPcw==}
dev: true
/@pnpm.e2e/peer-c/1.0.1:
resolution: {integrity: sha512-6ag+AQOLJgsioiG8aInnOJGautKz7lNf3zKQ8FJHOb4b3yIclmUofTaDwth9ydp9W56qzwbHWXjkdrqfW5JViQ==}
dev: true

View File

@@ -528,6 +528,16 @@ test('installation of a dependency that has a resolved peer in subdeps', async (
expect(project.requireModule('pnpm-default-reporter')).toBeTruthy()
})
test('install peer dependencies that are in prod dependencies', async () => {
const prefix = f.prepare('reinstall-peer-deps')
await headless(await testDefaults({ lockfileDir: prefix }))
const project = assertProject(prefix)
await project.has('.pnpm/@pnpm.e2e+peer-a@1.0.1/node_modules/@pnpm.e2e/peer-a')
})
test('installing with hoistPattern=*', async () => {
const prefix = f.prepare('simple-shamefully-flatten')
const reporter = jest.fn()