Skip to content

fix(pnpm): ignore workspace when listing production dependencies - #606

Merged
floydspace merged 1 commit into
floydspace:masterfrom
lyn1dev:fix/pnpm-ignore-workspace
Nov 26, 2026
Merged

floydspace merged 1 commit into
floydspace:masterfrom
lyn1dev:fix/pnpm-ignore-workspace

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #590

Root cause

In pnpm 11, running pnpm ls --prod --json from a subdirectory inside a pnpm workspace without its own manifest (such as .esbuild/.build when no temporary package.json is generated) becomes workspace-recursive and outputs dependency graphs for every workspace package. In large monorepos, this output can exceed Execa's default maxBuffer limit.

Changes

  • src/packagers/pnpm.ts: Pass --ignore-workspace before ls in Pnpm.getProdDependencies() so pnpm lists only the single nearest package (matching pre-pnpm-11 behavior when .esbuild/.build/package.json is present or absent, as well as in standalone non-workspace projects).
  • src/tests/packagers/pnpm.test.ts: Added unit tests verifying Pnpm.getProdDependencies() invokes pnpm with --ignore-workspace (with and without depth) and returns the first parsed dependency entry.

Verification

  • The new unit tests in src/tests/packagers/pnpm.test.ts fail without the fix and pass with it (pnpm run test:unit src/tests/packagers/pnpm.test.ts).
  • With pnpm 11.29.0 in a multi-package workspace, pnpm --ignore-workspace ls --prod --json returns only the single target package in both .esbuild/.build with and without a package.json, as well as in a standalone project.
  • pnpm run lint (eslint . and tsc --noEmit && tsc -p tsconfig.examples.json) passes.
  • pnpm exec tsc -p ./tsconfig.build.json passes.

@floydspace floydspace left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Tested against #590.

Reproduction (pnpm 11.8.0, plugin built from master, 40-package workspace)

  • pnpm ls --prod --json from .esbuild/.build returns every workspace package (42 entries, first entry is root). With --ignore-workspace it returns only svc.
  • Through the plugin, with maxBuffer lowered to 20 KB as a proxy for the real 100 MB limit: master fails with MaxBufferError: Command failed: pnpm ls --prod --json / maxBuffer exceeded. With this PR's flag it does not. I did not test a workspace large enough to hit 100 MB.
  • Besides the oversized output, master reads JSON.parse(output)[0], which is root on affected versions, so the wrong package's dependencies can be read.

Affected pnpm versions

  • Bug present in 11.0.0 through 11.27.0, fixed in 11.27.1 (release notes: commands run in a project the workspace does not include now act on that project alone).
  • Not affected: 9.15.x, 10.x, 11.27.1+, 12.23.0. So this flag only matters for 11.0.0-11.27.0. Upgrading pnpm to 11.27.1+ also resolves #590.

Regression check (pnpm 9.15.4/9.15.9, 10.33.0/10.34.9, 11.x, 12.23.0)

  • The flag is accepted on all of them.
  • When .build has its own package.json (the only case pack.ts uses, since getProdDependencies is only called when hasExternals is true), output is identical with and without the flag.
  • If .build had no manifest, the flag would return the nearest package without its dependencies. The plugin does not reach that state.

Notes

  • The flag can be removed once pnpm 11.0.0-11.27.0 is no longer supported.
  • The new tests only assert the argument list, which is acceptable for a one-line change.
  • Separate from this PR: inside a workspace, pnpm install in .esbuild/.build attaches to the workspace ("Scope: all N workspace projects") and installs nothing, so externals are dropped from the zip. This happens with or without this PR and should be tracked as its own issue.

@floydspace
floydspace merged commit 58c953d into floydspace:master Nov 26, 2026
3 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.59.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pnpm 11: pnpm ls becomes workspace-recursive and exceeds Execa maxBuffer

2 participants