Skip to content

Commit

Permalink
Fix: install peerDeps which is not optional on headless install (#5243)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Shinyaigeek and zkochan committed Aug 23, 2022
1 parent c242672 commit 1beb1b4
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/calm-windows-study.md
@@ -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).
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/headless/test/fixtures/reinstall-peer-deps/.npmrc
@@ -0,0 +1 @@
auto-install-peers=true
@@ -0,0 +1,7 @@
{
"name": "reinstall-peer-deps",
"version": "1.0.0",
"devDependencies": {
"@pnpm.e2e/abc": "1.0.0"
}
}
37 changes: 37 additions & 0 deletions packages/headless/test/fixtures/reinstall-peer-deps/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions packages/headless/test/index.ts
Expand Up @@ -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()
Expand Down

0 comments on commit 1beb1b4

Please sign in to comment.