Skip to content

fix(link): scope npm link <path> --workspace to the workspace, not the root#9592

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/link-workspace-targets-root-manifest
Jun 22, 2026
Merged

fix(link): scope npm link <path> --workspace to the workspace, not the root#9592
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/link-workspace-targets-root-manifest

Conversation

@manzoorwanijk

@manzoorwanijk manzoorwanijk commented Jun 22, 2026

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.

npm link <path> --workspace=<ws> did not scope the operation to the target workspace.
The linked dependency was attached to the root project instead, and with --save (or --save-dev/--save-optional/etc.) the file: spec was written to the root package.json rather than <ws>/package.json.
npm install <path> --workspace=<ws> --save behaved correctly, so only npm link was affected.

The cause is in Link.linkInstall() in lib/commands/link.js, which built the local Arborist without the workspaces option and passed workspaces only to reify().
Arborist decides which node receives the add request from this.options.workspaces, which is captured at construction time, not from the reify-time option.
buildIdealTree merges reify options into a local variable and #parseSettings never copies options.workspaces into this.options, so the reify-time value never reached #applyUserRequests.
With this.options.workspaces left empty, the add and the save were applied to the root node.

The fix passes workspaces: this.workspaceNames to the local Arborist constructor, matching how lib/commands/install.js already does it.
Physical placement is unchanged: under the default hoisted strategy the symlink still hoists to the root node_modules, identical to npm install --workspace.

References

Fixes #9590
Related #9589

@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 22, 2026 05:07
@manzoorwanijk manzoorwanijk requested review from a team as code owners June 22, 2026 05:07
@owlstronaut owlstronaut merged commit 1a9ce8e into npm:latest Jun 22, 2026
28 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Backport to release/v11 created: #9595

owlstronaut pushed a commit that referenced this pull request Jun 22, 2026
…the root (#9595)

Backport of #9592 to `release/v11`.

Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
@manzoorwanijk manzoorwanijk deleted the fix/link-workspace-targets-root-manifest branch June 22, 2026 16:42
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] npm link <path> --workspace=<ws> ignores the workspace: dep is attached to the root (and --save writes the root manifest)

2 participants