Repository navigation
Commit 1a9ce8e
authored
fix(link): scope
`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
<!-- List any relevant issues, pull requests, or external references -->
Fixes #9590
Related #9589npm link <path> --workspace to the workspace, not the root (#9592)1 parent 00b9f9f commit 1a9ce8e
2 files changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
128 | 130 | | |
129 | 131 | | |
130 | 132 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
292 | 330 | | |
293 | 331 | | |
294 | 332 | | |
| |||
0 commit comments