fix: prevent table width error in pnpm outdated --long (#10050)

close #10040
This commit is contained in:
Ryo Matsukawa
2025-10-13 02:38:32 +09:00
committed by GitHub
parent 587424f24f
commit 270c447017
9 changed files with 94 additions and 11 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-outdated": patch
pnpm: patch
---
Prevent a table width error in `pnpm outdated --long` [#10040](https://github.com/pnpm/pnpm/issues/10040).

View File

@@ -0,0 +1,2 @@
!**/node_modules/**/*
!/node_modules/

View File

@@ -0,0 +1,20 @@
lockfileVersion: '9.0'
importers:
'.':
dependencies:
'@pnpm.e2e/deprecated':
specifier: 1.0.0
version: 1.0.0
packages:
'@pnpm.e2e/deprecated@1.0.0':
resolution: {integrity: sha512-oidipeQzM+eKHKOmDnruTG7wP+jySQAxskX54lMYTeaq1rBjC+G1u+l3TolCKShyyOz73mO2N9laBqyFB06t6A==}
deprecated: This package is deprecated. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
snapshots:
'@pnpm.e2e/deprecated@1.0.0': {}

View File

@@ -0,0 +1,7 @@
{
"name": "has-only-deprecated-deps",
"version": "1.0.0",
"dependencies": {
"@pnpm.e2e/deprecated": "1.0.0"
}
}

View File

@@ -0,0 +1,20 @@
lockfileVersion: '9.0'
importers:
'.':
dependencies:
'@pnpm.e2e/deprecated':
specifier: 1.0.0
version: 1.0.0
packages:
'@pnpm.e2e/deprecated@1.0.0':
resolution: {integrity: sha512-oidipeQzM+eKHKOmDnruTG7wP+jySQAxskX54lMYTeaq1rBjC+G1u+l3TolCKShyyOz73mO2N9laBqyFB06t6A==}
deprecated: This package is deprecated. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
snapshots:
'@pnpm.e2e/deprecated@1.0.0': {}

View File

@@ -0,0 +1 @@
sharedWorkspaceLockfile: false

View File

@@ -5,6 +5,7 @@ packages:
- '!has-no-lockfile'
- '!has-not-outdated-deps'
- '!has-npm-shrinkwrap-json'
- '!has-only-deprecated-deps'
- '!has-outdated-deps'
- '!has-package-lock-json'
- '!has-package-lock-v3-json'

View File

@@ -260,25 +260,24 @@ function renderOutdatedTable (outdatedPackages: readonly OutdatedPackage[], opts
...sortOutdatedPackages(outdatedPackages, { sortBy: opts.sortBy })
.map((outdatedPkg) => columnFns.map((fn) => fn(outdatedPkg))),
]
let detailsColumnMaxWidth = 40
const tableOptions = {
...TABLE_OPTIONS,
}
if (opts.long) {
detailsColumnMaxWidth = outdatedPackages.filter(pkg => pkg.latestManifest && !pkg.latestManifest.deprecated).reduce((maxWidth, pkg) => {
const 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,
}, 40)
tableOptions.columns = {
// Detail column:
3: {
width: detailsColumnMaxWidth,
wrapWord: true,
},
},
})
}
}
return table(data, tableOptions)
}
function renderOutdatedList (outdatedPackages: readonly OutdatedPackage[], opts: { long?: boolean, sortBy?: 'name' }): string {

View File

@@ -19,6 +19,7 @@ const hasNoLockfileFixture = f.find('has-no-lockfile')
const withPnpmUpdateIgnore = f.find('with-pnpm-update-ignore')
const hasOutdatedDepsUsingCatalogProtocol = f.find('has-outdated-deps-using-catalog-protocol')
const hasOutdatedDepsUsingNpmAlias = f.find('has-outdated-deps-using-npm-alias')
const hasOnlyDeprecatedDepsFixture = f.find('has-only-deprecated-deps')
const REGISTRY_URL = `http://localhost:${REGISTRY_MOCK_PORT}`
@@ -459,3 +460,29 @@ test('pnpm outdated: support --sortField option', async () => {
└──────────────────────┴──────────────────────┴────────────┘
`)
})
test('pnpm outdated --long with only deprecated packages', async () => {
tempDir()
fs.mkdirSync(path.resolve('node_modules/.pnpm'), { recursive: true })
fs.copyFileSync(path.join(hasOnlyDeprecatedDepsFixture, 'node_modules/.pnpm/lock.yaml'), path.resolve('node_modules/.pnpm/lock.yaml'))
fs.copyFileSync(path.join(hasOnlyDeprecatedDepsFixture, 'package.json'), path.resolve('package.json'))
const { output, exitCode } = await outdated.handler({
...OUTDATED_OPTIONS,
dir: process.cwd(),
long: true,
})
expect(exitCode).toBe(1)
expect(stripAnsi(output)).toBe(`\
┌──────────────────────┬─────────┬────────────┬──────────────────────────────────────────┐
│ Package │ Current │ Latest │ Details │
├──────────────────────┼─────────┼────────────┼──────────────────────────────────────────┤
│ @pnpm.e2e/deprecated │ 1.0.0 │ Deprecated │ This package is deprecated. Lorem ipsum │
│ │ │ │ dolor sit amet, consectetur adipiscing │
│ │ │ │ elit. │
│ │ │ │ https://foo.bar/qar │
└──────────────────────┴─────────┴────────────┴──────────────────────────────────────────┘
`)
})