diff --git a/packages/pnpm/src/cmd/outdated.ts b/packages/pnpm/src/cmd/outdated.ts index 144cfa6629..f494177cbd 100644 --- a/packages/pnpm/src/cmd/outdated.ts +++ b/packages/pnpm/src/cmd/outdated.ts @@ -97,6 +97,10 @@ export default async function ( ], TABLE_OPTIONS) } +export function getCellWidth (data: string[][], columnNumber: number, maxWidth: number) { + return Math.min(maxWidth, data.reduce((maxWidth, row) => Math.max(maxWidth, row[columnNumber].length), 0)) +} + export function toOutdatedWithVersionDiff (outdated: T & OutdatedPackage): T & OutdatedWithVersionDiff { if (outdated.latestManifest) { return { diff --git a/packages/pnpm/src/cmd/recursive/outdated.ts b/packages/pnpm/src/cmd/recursive/outdated.ts index af69240771..ddd680e17f 100644 --- a/packages/pnpm/src/cmd/recursive/outdated.ts +++ b/packages/pnpm/src/cmd/recursive/outdated.ts @@ -4,6 +4,7 @@ import { DependenciesField, PackageJson, Registries } from '@pnpm/types' import R = require('ramda') import { table } from 'table' import { + getCellWidth, outdatedDependenciesOfWorkspacePackages, renderCurrent, renderDetails, @@ -87,36 +88,37 @@ export default async ( } const columnNames = ['Package', 'Current', 'Latest', 'Dependents', 'Details'] + const data = [ + columnNames, + ...R.sortWith( + [ + sortBySemverChange, + (o1, o2) => o1.packageName.localeCompare(o2.packageName), + (o1, o2) => DEP_PRIORITY[o1.belongsTo] - DEP_PRIORITY[o2.belongsTo], + ], + ( + Object.values(outdatedByNameAndType).map(toOutdatedWithVersionDiff) + ), + ) + .map((outdatedPkg) => [ + renderPackageName(outdatedPkg), + renderCurrent(outdatedPkg), + renderLatest(outdatedPkg), + outdatedPkg.dependentPkgs + .map(({ manifest, location }) => manifest.name || location) + .sort() + .join(', '), + renderDetails(outdatedPkg), + ]), + ] process.stdout.write( - table([ - columnNames, - ...R.sortWith( - [ - sortBySemverChange, - (o1, o2) => o1.packageName.localeCompare(o2.packageName), - (o1, o2) => DEP_PRIORITY[o1.belongsTo] - DEP_PRIORITY[o2.belongsTo], - ], - ( - Object.values(outdatedByNameAndType).map(toOutdatedWithVersionDiff) - ), - ) - .map((outdatedPkg) => [ - renderPackageName(outdatedPkg), - renderCurrent(outdatedPkg), - renderLatest(outdatedPkg), - outdatedPkg.dependentPkgs - .map(({ manifest, location }) => manifest.name || location) - .sort() - .join(', '), - renderDetails(outdatedPkg), - ]), - ], { + table(data, { ...TABLE_OPTIONS, columns: { ...TABLE_OPTIONS.columns, // Dependents column: 3: { - width: 40, + width: getCellWidth(data, 3, 30), wrapWord: true, }, }, diff --git a/packages/pnpm/test/recursive/outdated.ts b/packages/pnpm/test/recursive/outdated.ts index 5b765934d6..9a0e4a2731 100644 --- a/packages/pnpm/test/recursive/outdated.ts +++ b/packages/pnpm/test/recursive/outdated.ts @@ -51,15 +51,15 @@ test('pnpm recursive outdated', async (t: tape.Test) => { t.equal(result.status, 0) t.equal(normalizeNewline(result.stdout.toString()), stripIndent` - ══════════════════╤═════════╤════════╤══════════════════════════════════════════╤═════════════════════════════════════════════╗ - Package │ Current │ Latest │ Dependents │ Details ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-negative │ 1.0.0 │ 2.1.0 │ project-2 │ https://github.com/kevva/is-negative#readme ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-negative (dev) │ 1.0.0 │ 2.1.0 │ project-3 │ https://github.com/kevva/is-negative#readme ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ - ══════════════════╧═════════╧════════╧══════════════════════════════════════════╧═════════════════════════════════════════════╝ + ══════════════════╤═════════╤════════╤══════════════════════╤═════════════════════════════════════════════╗ + Package │ Current │ Latest │ Dependents │ Details ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-negative │ 1.0.0 │ 2.1.0 │ project-2 │ https://github.com/kevva/is-negative#readme ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-negative (dev) │ 1.0.0 │ 2.1.0 │ project-3 │ https://github.com/kevva/is-negative#readme ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ + ══════════════════╧═════════╧════════╧══════════════════════╧═════════════════════════════════════════════╝ ` + '\n') } @@ -69,11 +69,11 @@ test('pnpm recursive outdated', async (t: tape.Test) => { t.equal(result.status, 0) t.equal(normalizeNewline(result.stdout.toString()), stripIndent` - ════════════╤═════════╤════════╤══════════════════════════════════════════╤═════════════════════════════════════════════╗ - Package │ Current │ Latest │ Dependents │ Details ║ - ────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ - ════════════╧═════════╧════════╧══════════════════════════════════════════╧═════════════════════════════════════════════╝ + ════════════╤═════════╤════════╤══════════════════════╤═════════════════════════════════════════════╗ + Package │ Current │ Latest │ Dependents │ Details ║ + ────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ + ════════════╧═════════╧════════╧══════════════════════╧═════════════════════════════════════════════╝ ` + '\n') } }) @@ -119,15 +119,15 @@ test('pnpm recursive outdated in workspace with shared lockfile', async (t: tape t.equal(result.status, 0) t.equal(normalizeNewline(result.stdout.toString()), stripIndent` - ══════════════════╤═════════╤════════╤══════════════════════════════════════════╤═════════════════════════════════════════════╗ - Package │ Current │ Latest │ Dependents │ Details ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-negative │ 1.0.0 │ 2.1.0 │ project-2 │ https://github.com/kevva/is-negative#readme ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-negative (dev) │ 1.0.0 │ 2.1.0 │ project-3 │ https://github.com/kevva/is-negative#readme ║ - ──────────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ - ══════════════════╧═════════╧════════╧══════════════════════════════════════════╧═════════════════════════════════════════════╝ + ══════════════════╤═════════╤════════╤══════════════════════╤═════════════════════════════════════════════╗ + Package │ Current │ Latest │ Dependents │ Details ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-negative │ 1.0.0 │ 2.1.0 │ project-2 │ https://github.com/kevva/is-negative#readme ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-negative (dev) │ 1.0.0 │ 2.1.0 │ project-3 │ https://github.com/kevva/is-negative#readme ║ + ──────────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ + ══════════════════╧═════════╧════════╧══════════════════════╧═════════════════════════════════════════════╝ ` + '\n') } @@ -137,11 +137,11 @@ test('pnpm recursive outdated in workspace with shared lockfile', async (t: tape t.equal(result.status, 0) t.equal(normalizeNewline(result.stdout.toString()), stripIndent` - ════════════╤═════════╤════════╤══════════════════════════════════════════╤═════════════════════════════════════════════╗ - Package │ Current │ Latest │ Dependents │ Details ║ - ────────────┼─────────┼────────┼──────────────────────────────────────────┼─────────────────────────────────────────────╢ - is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ - ════════════╧═════════╧════════╧══════════════════════════════════════════╧═════════════════════════════════════════════╝ + ════════════╤═════════╤════════╤══════════════════════╤═════════════════════════════════════════════╗ + Package │ Current │ Latest │ Dependents │ Details ║ + ────────────┼─────────┼────────┼──────────────────────┼─────────────────────────────────────────────╢ + is-positive │ 1.0.0 │ 3.1.0 │ project-1, project-3 │ https://github.com/kevva/is-positive#readme ║ + ════════════╧═════════╧════════╧══════════════════════╧═════════════════════════════════════════════╝ ` + '\n') } })