Skip to content

fix(exec): resolve workspace-local bin under the linked install strategy#9639

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-exec-workspace-bin
Jun 24, 2026
Merged

fix(exec): resolve workspace-local bin under the linked install strategy#9639
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/linked-exec-workspace-bin

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Contributor

In continuation of our exploration of using install-strategy=linked in the Gutenberg monorepo, which powers the WordPress Block Editor.

Under install-strategy=linked, npm exec -w <ws> -- <bin> ignored a workspace-local bin (provided by a sibling workspace dependency) and fell through to the registry, producing a spurious E404. The hoisted strategy ran the local bin correctly.

Why

For a workspace exec, the command computed the local bin directory as resolve(this.npm.localDir, name, 'node_modules', '.bin'), i.e. <root>/node_modules/<name>/node_modules/.bin. That path only resolves when the workspace is symlinked into the root node_modules as <name>, which is how the hoisted strategy lays workspaces out. The linked strategy does not hoist workspaces into the root node_modules; the workspace's real bin lives at <workspace>/node_modules/.bin. libnpmexec walks up from the given bin directory looking for node_modules/.bin/<bin>, so starting from the nonexistent hoisted path never reached the workspace's actual bin and the lookup fell back to the registry.

How

Base the local bin directory on the workspace's own path (runPath) instead of the hoisted localDir/<name> location. This is correct under both strategies: linked finds the bin in the workspace's node_modules/.bin, and hoisted still finds the root-hoisted bin because the walk-up continues from the workspace directory to the root node_modules/.bin.

References

Fixes #9616

@manzoorwanijk manzoorwanijk force-pushed the fix/linked-exec-workspace-bin branch from 12ebf3a to 8f6667e Compare June 24, 2026 17:29
@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 24, 2026 17:31
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 24, 2026 17:31
@manzoorwanijk manzoorwanijk force-pushed the fix/linked-exec-workspace-bin branch 2 times, most recently from c4ab8a3 to 1a0596e Compare June 24, 2026 18:29
@manzoorwanijk

manzoorwanijk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

The coverage is broken in latest as well.

EDIT: Resolved by #9646

@manzoorwanijk manzoorwanijk force-pushed the fix/linked-exec-workspace-bin branch from 1a0596e to 86c6fd5 Compare June 24, 2026 18:54
@manzoorwanijk manzoorwanijk marked this pull request as draft June 24, 2026 19:21
@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 24, 2026 19:21
@owlstronaut owlstronaut merged commit d6fbb55 into npm:latest Jun 24, 2026
27 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9648

@manzoorwanijk manzoorwanijk deleted the fix/linked-exec-workspace-bin branch June 24, 2026 19:48
owlstronaut pushed a commit that referenced this pull request Jun 24, 2026
…egy (#9648)

Backport of #9639 to `release/v11`.

Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] install-strategy=linked: npm exec -w <ws> ignores a workspace-local bin and falls back to the registry

2 participants