mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: prevent table width error in pnpm outdated --long (#10050)
close #10040
This commit is contained in:
6
.changeset/silver-pants-sip.md
Normal file
6
.changeset/silver-pants-sip.md
Normal 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).
|
||||
2
__fixtures__/has-only-deprecated-deps/.gitignore
vendored
Normal file
2
__fixtures__/has-only-deprecated-deps/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
!**/node_modules/**/*
|
||||
!/node_modules/
|
||||
20
__fixtures__/has-only-deprecated-deps/node_modules/.pnpm/lock.yaml
generated
vendored
Normal file
20
__fixtures__/has-only-deprecated-deps/node_modules/.pnpm/lock.yaml
generated
vendored
Normal 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': {}
|
||||
7
__fixtures__/has-only-deprecated-deps/package.json
Normal file
7
__fixtures__/has-only-deprecated-deps/package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "has-only-deprecated-deps",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"@pnpm.e2e/deprecated": "1.0.0"
|
||||
}
|
||||
}
|
||||
20
__fixtures__/has-only-deprecated-deps/pnpm-lock.yaml
generated
Normal file
20
__fixtures__/has-only-deprecated-deps/pnpm-lock.yaml
generated
Normal 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': {}
|
||||
@@ -0,0 +1 @@
|
||||
sharedWorkspaceLockfile: false
|
||||
@@ -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'
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 │
|
||||
└──────────────────────┴─────────┴────────────┴──────────────────────────────────────────┘
|
||||
`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user