fix(print-peer-issues): escape the "*" range

This commit is contained in:
Zoltan Kochan
2021-12-18 04:10:00 +02:00
parent 40dc2f954f
commit 6058f76cdf
4 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/render-peer-issues": patch
---
When printing peer dependency issues, print the "\*" range in double quotes. This will make it easier to copy the package resolutions and put them to the end of a `pnpm add` command for execution.

View File

@@ -54,7 +54,7 @@ export default function (
}
function formatNameAndRange (name: string, range: string) {
if (range.includes(' ')) {
if (range.includes(' ') || range === '*') {
return `${name}@"${range}"`
}
return `${name}@${range}`

View File

@@ -22,6 +22,15 @@ Peer dependencies that should be installed:
ddd@^1.0.0 "
`;
exports[`renderPeerIssues() format correctly the version ranges with spaces and "*" 1`] = `
".
└─┬ z
├── ✕ missing peer a@\\"*\\"
└── ✕ missing peer b@\\"1 || 2\\"
Peer dependencies that should be installed:
a@\\"*\\" b@\\"1 || 2\\" "
`;
exports[`renderPeerIssues() optional peer dependencies are printed only if they are in conflict with non-optional peers 1`] = `
".
└─┬ xxx

View File

@@ -160,3 +160,39 @@ test('renderPeerIssues() optional peer dependencies are printed only if they are
},
}, { width: 500 }))).toMatchSnapshot()
})
test('renderPeerIssues() format correctly the version ranges with spaces and "*"', () => {
expect(stripAnsi(renderPeerIssues({
'.': {
conflicts: [],
intersections: { a: '*', b: '1 || 2' },
bad: {},
missing: {
a: [
{
parents: [
{
name: 'z',
version: '1.0.0',
},
],
optional: false,
wantedRange: '*',
},
],
b: [
{
parents: [
{
name: 'z',
version: '1.0.0',
},
],
optional: false,
wantedRange: '1 || 2',
},
],
},
},
}, { width: 500 }))).toMatchSnapshot()
})