fix: outdated output table information is misplaced (#8037)

This commit is contained in:
btea
2024-05-04 17:44:02 +08:00
committed by GitHub
parent c50afe4ddc
commit 21de734b5a
8 changed files with 31 additions and 30 deletions

View File

@@ -0,0 +1,7 @@
---
"@pnpm/plugin-commands-licenses": patch
"@pnpm/plugin-commands-outdated": patch
"pnpm": patch
---
Details in the `pnpm outdated` output are wrapped correctly [#8037](https://github.com/pnpm/pnpm/pull/8037).

View File

@@ -147,7 +147,6 @@
"strip-bom",
"tempy",
"unique-string",
"wrap-ansi",
"write-json-file",
"write-pkg"
]

14
pnpm-lock.yaml generated
View File

@@ -5601,9 +5601,6 @@ importers:
'@types/semver':
specifier: 7.5.3
version: 7.5.3
'@types/wrap-ansi':
specifier: 8.0.2
version: 8.0.2
'@types/zkochan__table':
specifier: npm:@types/table@6.0.0
version: '@types/table@6.0.0'
@@ -5731,9 +5728,6 @@ importers:
strip-ansi:
specifier: ^6.0.1
version: 6.0.1
wrap-ansi:
specifier: ^7.0.0
version: 7.0.0
devDependencies:
'@pnpm/constants':
specifier: workspace:*
@@ -5759,9 +5753,6 @@ importers:
'@types/ramda':
specifier: 0.29.12
version: 0.29.12
'@types/wrap-ansi':
specifier: 8.0.2
version: 8.0.2
'@types/zkochan__table':
specifier: npm:@types/table@6.0.0
version: '@types/table@6.0.0'
@@ -8004,9 +7995,6 @@ packages:
'@types/which@2.0.2':
resolution: {integrity: sha512-113D3mDkZDjo+EeUEHCFy0qniNc1ZpecGiAU7WSo7YDoSzolZIQKpYFHrPpjkB2nuyahcKfrmLXeQlh7gqJYdw==}
'@types/wrap-ansi@8.0.2':
resolution: {integrity: sha512-mdaFibQzYYqJF8Sc9By84eBLtDQD9Hnko0yXuezHBU5f5KdtQk+j5hPRQc1j4ayzdqGddKON6PjeuzxD5U1hPg==}
'@types/write-file-atomic@4.0.3':
resolution: {integrity: sha512-qdo+vZRchyJIHNeuI1nrpsLw+hnkgqP/8mlaN6Wle/NKhydHmUN9l4p3ZE8yP90AJNJW4uB8HQhedb4f1vNayQ==}
@@ -14765,8 +14753,6 @@ snapshots:
'@types/which@2.0.2': {}
'@types/wrap-ansi@8.0.2': {}
'@types/write-file-atomic@4.0.3':
dependencies:
'@types/node': 18.19.31

View File

@@ -115,10 +115,6 @@
"packageNames": ["strip-ansi"],
"allowedVersions": "^6.0.0"
},
{
"packageNames": ["wrap-ansi"],
"allowedVersions": "^7.0.0"
},
{
"packageNames": ["escape-string-regexp"],
"allowedVersions": "^4.0.0"

View File

@@ -40,7 +40,6 @@
"@pnpm/test-fixtures": "workspace:*",
"@types/ramda": "0.29.12",
"@types/semver": "7.5.3",
"@types/wrap-ansi": "8.0.2",
"@types/zkochan__table": "npm:@types/table@6.0.0",
"strip-ansi": "^6.0.1"
},

View File

@@ -38,7 +38,6 @@
"@pnpm/registry-mock": "3.30.0",
"@pnpm/test-fixtures": "workspace:*",
"@types/ramda": "0.29.12",
"@types/wrap-ansi": "8.0.2",
"@types/zkochan__table": "npm:@types/table@6.0.0"
},
"dependencies": {
@@ -60,8 +59,7 @@
"chalk": "^4.1.2",
"ramda": "npm:@pnpm/ramda@0.28.1",
"render-help": "^1.0.3",
"strip-ansi": "^6.0.1",
"wrap-ansi": "^7.0.0"
"strip-ansi": "^6.0.1"
},
"funding": "https://opencollective.com/pnpm",
"exports": {

View File

@@ -21,7 +21,6 @@ import pick from 'ramda/src/pick'
import sortWith from 'ramda/src/sortWith'
import renderHelp from 'render-help'
import stripAnsi from 'strip-ansi'
import wrapAnsi from 'wrap-ansi'
import {
DEFAULT_COMPARATORS,
type OutdatedWithVersionDiff,
@@ -239,11 +238,30 @@ function renderOutdatedTable (outdatedPackages: readonly OutdatedPackage[], opts
for (let i = 0; i < columnNames.length; i++)
columnNames[i] = chalk.blueBright(columnNames[i])
return table([
const data = [
columnNames,
...sortOutdatedPackages(outdatedPackages)
.map((outdatedPkg) => columnFns.map((fn) => fn(outdatedPkg))),
], TABLE_OPTIONS)
]
let detailsColumnMaxWidth = 40
if (opts.long) {
detailsColumnMaxWidth = outdatedPackages.filter(pkg => pkg.latestManifest && !pkg.latestManifest.deprecated).reduce((maxWidth, pkg) => {
const cellWidth = pkg.latestManifest?.homepage?.length ?? 0
return Math.max(maxWidth, cellWidth)
}, 0)
}
return table(data, {
...TABLE_OPTIONS,
columns: {
...TABLE_OPTIONS.columns,
// Detail column:
3: {
width: detailsColumnMaxWidth,
wrapWord: true,
},
},
})
}
function renderOutdatedList (outdatedPackages: readonly OutdatedPackage[], opts: { long?: boolean }): string {
@@ -354,7 +372,7 @@ export function renderDetails ({ latestManifest }: OutdatedPackage): string {
if (latestManifest == null) return ''
const outputs = []
if (latestManifest.deprecated) {
outputs.push(wrapAnsi(chalk.redBright(latestManifest.deprecated), 40))
outputs.push(chalk.redBright(latestManifest.deprecated))
}
if (latestManifest.homepage) {
outputs.push(chalk.underline(latestManifest.homepage))

View File

@@ -175,9 +175,7 @@ is-positive (dev)
expect(exitCode).toBe(1)
expect(stripAnsi(output)).toBe(`@pnpm.e2e/deprecated
1.0.0 => Deprecated
This package is deprecated. Lorem ipsum
dolor sit amet, consectetur adipiscing
elit.
This package is deprecated. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
https://foo.bar/qar
is-negative