fix: rendering of missing peer dependencies output (#8745)

close #8538
This commit is contained in:
Zoltan Kochan
2024-11-11 10:16:09 +01:00
committed by GitHub
parent 8c3de19fc1
commit ee5dde3894
6 changed files with 65 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/render-peer-issues": patch
---
Don't fail to render missing peer dependencies, when the parents field is an empty array.

View File

@@ -0,0 +1,6 @@
---
"@pnpm/resolve-dependencies": patch
"pnpm": patch
---
Fix `Cannot read properties of undefined (reading 'name')` that is printed while trying to render the missing peer dependencies warning message [#8538](https://github.com/pnpm/pnpm/issues/8538).

View File

@@ -114,6 +114,11 @@ interface PkgNode {
}
function createTree (pkgNode: PkgNode, pkgs: Array<{ name: string, version: string }>, issueText: string): void {
if (pkgs.length === 0) {
// This will happen if incorrect data is passed to the reporter.
// It is better to print something instead of crashing.
pkgs = [{ name: '<unknown>', version: '<unknown>' }]
}
const [pkg, ...rest] = pkgs
const label = `${pkg.name} ${chalk.grey(pkg.version)}`
if (!pkgNode.dependencies[label]) {

View File

@@ -382,3 +382,33 @@ test('renderPeerIssues() format correctly the version ranges with spaces and "*"
},
}, { width: 500 }))).toMatchSnapshot()
})
test('renderPeerIssues() do not fail if the parents array is empty', () => {
expect(stripAnsi(renderPeerIssues({
'.': {
missing: {
foo: [
{
parents: [],
optional: false,
wantedRange: '>=1.0.0 <3.0.0',
},
],
},
bad: {},
conflicts: [],
intersections: {
foo: '^1.0.0',
},
},
}, {
rules: {
ignoreMissing: [],
},
width: 500,
})).trim()).toBe(`.
└─┬ <unknown> <unknown>
└── ✕ missing peer foo@">=1.0.0 <3.0.0"
Peer dependencies that should be installed:
foo@^1.0.0`)
})

View File

@@ -437,7 +437,10 @@ async function resolvePeersOfNode<T extends PartialResolvedPackage> (
if (ctx.peerDependencyIssues.missing[peerName] == null) {
ctx.peerDependencyIssues.missing[peerName] = []
}
const { parents } = getLocationFromParentNodeIds(ctx)
const { parents } = getLocationFromParentNodeIds({
dependenciesTree: ctx.dependenciesTree,
parentNodeIds,
})
ctx.peerDependencyIssues.missing[peerName].push({
optional,
parents,

View File

@@ -533,3 +533,18 @@ test('installation fails when the stored package name and version do not match t
await execPnpm(['install', '--config.strict-store-pkg-content-check=false', ...settings])
})
// Covers https://github.com/pnpm/pnpm/issues/8538
test('do not fail to render peer dependencies warning, when cache was hit during peer resolution', () => {
prepare({
dependencies: {
'@udecode/plate-ui-table': '18.15.0',
'@udecode/plate-ui-toolbar': '18.15.0',
},
})
const result = execPnpmSync(['install', '--config.auto-install-peers=false'])
expect(result.status).toBe(0)
expect(result.stdout.toString()).toContain('Issues with peer dependencies found')
})