Repository navigation
Commit d6fbb55
authored
fix(exec): resolve workspace-local bin under the linked install strategy (npm#9639)
In continuation of our exploration of using `install-strategy=linked` in
the [Gutenberg
monorepo](WordPress/gutenberg#75814), 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 npm#96161 parent 7e29a19 commit d6fbb55
2 files changed
Lines changed: 38 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
223 | 258 | | |
224 | 259 | | |
225 | 260 | | |
| |||
0 commit comments