Skip to content

Commit

Permalink
fix: outdated output table information is misplaced (#8037)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed May 4, 2024
1 parent c50afe4 commit 21de734
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .changeset/flat-poets-worry.md
Original file line number Diff line number Diff line change
@@ -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).
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@
"strip-bom",
"tempy",
"unique-string",
"wrap-ansi",
"write-json-file",
"write-pkg"
]
Expand Down
14 changes: 0 additions & 14 deletions pnpm-lock.yaml

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

4 changes: 0 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion reviewing/plugin-commands-licenses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 1 addition & 3 deletions reviewing/plugin-commands-outdated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
26 changes: 22 additions & 4 deletions reviewing/plugin-commands-outdated/src/outdated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions reviewing/plugin-commands-outdated/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21de734

Please sign in to comment.