fix(link): scope npm link <path> --workspace to the workspace, not the root#9592
Merged
owlstronaut merged 1 commit intoJun 22, 2026
Conversation
owlstronaut
approved these changes
Jun 22, 2026
Contributor
|
🎉 Backport to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In continuation of our exploration of using
install-strategy=linkedin 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.) thefile:spec was written to the rootpackage.jsonrather than<ws>/package.json.npm install <path> --workspace=<ws> --savebehaved correctly, so onlynpm linkwas affected.The cause is in
Link.linkInstall()inlib/commands/link.js, which built the local Arborist without theworkspacesoption and passedworkspacesonly toreify().Arborist decides which node receives the
addrequest fromthis.options.workspaces, which is captured at construction time, not from the reify-time option.buildIdealTreemerges reify options into a local variable and#parseSettingsnever copiesoptions.workspacesintothis.options, so the reify-time value never reached#applyUserRequests.With
this.options.workspacesleft empty, theaddand the save were applied to the root node.The fix passes
workspaces: this.workspaceNamesto the local Arborist constructor, matching howlib/commands/install.jsalready does it.Physical placement is unchanged: under the default
hoistedstrategy the symlink still hoists to the rootnode_modules, identical tonpm install --workspace.References
Fixes #9590
Related #9589