Skip to content

Fix pnpm workspace installs missing dependencies of workspace dependencies - #23754

Open
smaugho wants to merge 5 commits into
pantsbuild:mainfrom
smaugho:fix/pnpm-workspace-install
Open

smaugho wants to merge 5 commits into
pantsbuild:mainfrom
smaugho:fix/pnpm-workspace-install

Conversation

@smaugho

@smaugho smaugho commented Nov 4, 2026

Copy link
Copy Markdown

Fixes #23752.

Problem

In a pnpm workspace, installing the node package for a target only installed that package's own dependencies. When the package depends on another workspace package, that package's dependencies were left uninstalled, so code importing through it failed at runtime (e.g. Cannot find package '@invented/leaf').

Change

When Pants installs a pnpm workspace member, it now selects the member together with its dependencies, using pnpm's <package>... filter, instead of the member alone.

  • Only the pnpm install path changes. Ordinary commands, npm and yarn, root environments and single-package projects keep their current selectors.
  • Release note added in docs/notes/2.34.x.md.

Tests

  • New regression test: a workspace reader -> contract -> leaf. It installs through the real rules and runs Node. On current main without the fix it fails (Cannot find package '@invented/leaf'); with the fix Node prints 42.
  • Scope cases cover installation versus ordinary commands across pnpm, npm and yarn, and member, root and single environments.
  • Verified on main 05181fa with the native engine built locally: 25/25 tests in install_node_package_test.py and nodejs_project_environment_test.py, lint, MyPy, build-support/githooks/pre-push and pants --changed-since=HEAD fmt all pass.

AI disclosure

This PR was written primarily by Claude Code; I reviewed and tested it.

@smaugho
smaugho force-pushed the fix/pnpm-workspace-install branch 2 times, most recently from cf8a6ff to b2e4dbe Compare November 6, 2026 21:06
@benjyw
benjyw requested a review from tobni November 11, 2026 01:29
@benjyw

benjyw commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution. We've just branched for 2.34.x, so merging this pull request now will come out in 2.35.x, please move the release notes updates to docs/notes/2.35.x.md if that's appropriate.

@smaugho
smaugho force-pushed the fix/pnpm-workspace-install branch from b2e4dbe to 8297e33 Compare November 11, 2026 11:29
@smaugho

smaugho commented Nov 11, 2026

Copy link
Copy Markdown
Author

Moved the release note to 2.35.x. docs/notes/2.35.x.md didn't exist on main yet, so I created it from the release-notes template; happy to rebase onto the CI-generated file instead if you prefer (once it is available).

@benjyw

benjyw commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Ah whoops! The 2.35.x release notes are now on main, if you could add your note to that. Thanks!

I'm not really qualified to review, as I know precious little about the node ecosystem, but I'll try unless @tobni can jump in.

@benjyw benjyw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me, modulo one nit (and the notes merge)

package_name = target[NodePackageNameField].value
if (
self.include_workspace_dependencies
and self.env.project.package_manager.name == "pnpm"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like we encapsulate package manager-specific logic in PackageManager, so maybe this logic should live there too? Something like workspace_dependencies_suffix?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

javascript: pnpm workspace install does not install a dependency workspace's own dependencies (--filter <pkg> instead of <pkg>...)

2 participants