diff --git a/.changeset/silver-pants-sip.md b/.changeset/silver-pants-sip.md new file mode 100644 index 0000000000..030b745172 --- /dev/null +++ b/.changeset/silver-pants-sip.md @@ -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). \ No newline at end of file diff --git a/__fixtures__/has-only-deprecated-deps/.gitignore b/__fixtures__/has-only-deprecated-deps/.gitignore new file mode 100644 index 0000000000..5867a0493e --- /dev/null +++ b/__fixtures__/has-only-deprecated-deps/.gitignore @@ -0,0 +1,2 @@ +!**/node_modules/**/* +!/node_modules/ diff --git a/__fixtures__/has-only-deprecated-deps/node_modules/.pnpm/lock.yaml b/__fixtures__/has-only-deprecated-deps/node_modules/.pnpm/lock.yaml new file mode 100644 index 0000000000..d2d8efe825 --- /dev/null +++ b/__fixtures__/has-only-deprecated-deps/node_modules/.pnpm/lock.yaml @@ -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': {} diff --git a/__fixtures__/has-only-deprecated-deps/package.json b/__fixtures__/has-only-deprecated-deps/package.json new file mode 100644 index 0000000000..5aa1cb2af5 --- /dev/null +++ b/__fixtures__/has-only-deprecated-deps/package.json @@ -0,0 +1,7 @@ +{ + "name": "has-only-deprecated-deps", + "version": "1.0.0", + "dependencies": { + "@pnpm.e2e/deprecated": "1.0.0" + } +} diff --git a/__fixtures__/has-only-deprecated-deps/pnpm-lock.yaml b/__fixtures__/has-only-deprecated-deps/pnpm-lock.yaml new file mode 100644 index 0000000000..d2d8efe825 --- /dev/null +++ b/__fixtures__/has-only-deprecated-deps/pnpm-lock.yaml @@ -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': {} diff --git a/__fixtures__/has-only-deprecated-deps/pnpm-workspace.yaml b/__fixtures__/has-only-deprecated-deps/pnpm-workspace.yaml new file mode 100644 index 0000000000..22be0eefca --- /dev/null +++ b/__fixtures__/has-only-deprecated-deps/pnpm-workspace.yaml @@ -0,0 +1 @@ +sharedWorkspaceLockfile: false diff --git a/__fixtures__/pnpm-workspace.yaml b/__fixtures__/pnpm-workspace.yaml index c03282c739..f816f49ab5 100644 --- a/__fixtures__/pnpm-workspace.yaml +++ b/__fixtures__/pnpm-workspace.yaml @@ -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' diff --git a/reviewing/plugin-commands-outdated/src/outdated.ts b/reviewing/plugin-commands-outdated/src/outdated.ts index 0ab8bffacd..000668eab7 100644 --- a/reviewing/plugin-commands-outdated/src/outdated.ts +++ b/reviewing/plugin-commands-outdated/src/outdated.ts @@ -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 { diff --git a/reviewing/plugin-commands-outdated/test/index.ts b/reviewing/plugin-commands-outdated/test/index.ts index d6b930e3b1..6b77791367 100644 --- a/reviewing/plugin-commands-outdated/test/index.ts +++ b/reviewing/plugin-commands-outdated/test/index.ts @@ -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 │ +└──────────────────────┴─────────┴────────────┴──────────────────────────────────────────┘ +`) +})