mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-07 07:27:06 -04:00
feat(outdated): limit the maxWidth of the dependents column
This commit is contained in:
@@ -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<T> (outdated: T & OutdatedPackage): T & OutdatedWithVersionDiff {
|
||||
if (outdated.latestManifest) {
|
||||
return {
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user