Commit a2154cd
authored
fix: linked strategy fixes for scoped packages, aliases, and peer deps (#8996)
We're looking at using `install-strategy=linked` in the [Gutenberg
monorepo](https://github.com/WordPress/gutenberg) (~200 workspace
packages), which powers the WordPress Block Editor. While [testing it in
a PR](WordPress/gutenberg#75213), we ran into
several issues with the linked strategy that this PR fixes.
## Summary
1. Scoped workspace packages were losing their `@scope/` prefix in
`node_modules` because the symlink name came from the folder basename
instead of the package name.
2. Aliased packages (e.g. `"prettier": "npm:custom-prettier@3.0.3"`) in
workspace projects were getting symlinked under the real package name
instead of the alias, so `require('prettier')` would fail.
3. With `legacy-peer-deps = true`, peer dependencies weren't being
placed alongside packages in the store, so `require()` calls for peer
deps failed from within the store.
4. With `strict-peer-deps = true`, the linked strategy could crash with
`Cannot read properties of undefined` when store entries or parent nodes
were missing for excluded peer deps.
## Root cause
`assignCommonProperties` was using a single `result.name` for both
consumer-facing symlinks and store-internal paths. For workspaces,
`node.name` comes from the folder basename (missing the scope). For
aliases, `node.packageName` gives the real name but we need the alias
for the consumer symlink.
Separately, `legacy-peer-deps` tells the arborist to skip creating peer
dep edges entirely, so the isolated reifier never saw them and never
placed them in the store. And `strict-peer-deps` can cause nodes to be
excluded from the tree while still being referenced by edges, leading to
undefined lookups.
## Changes
- Split proxy identity into `result.name` (consumer-facing: alias or
scoped workspace name) and `result.packageName` (store-internal: real
package name from `package.json`). Store paths (`getKey`, `treeHash`,
`generateChild`, `processEdges`, `processDeps`) use `packageName`;
consumer symlinks keep using `name`.
- When `legacyPeerDeps` is enabled, resolve missing peer dep edges from
the tree via `node.resolve()` so they still get symlinked in the store.
- Guard against undefined `from` and `target` nodes in
`processEdges`/`processDeps` to prevent crashes with `strict-peer-deps`.
- Guard `idealTree.children.get(ws)` in `reify.js` since the isolated
tree uses an array for `children`, not a Map.
- Test fixture updates: `recursive: true` for `mkdirSync`, scoped
workspace glob support.
- New tests for scoped workspace packages, aliased packages in
workspaces, and peer deps with `legacyPeerDeps`.
## References
Fixes #61221 parent c029cb2 commit a2154cd
4 files changed
Lines changed: 206 additions & 11 deletions
File tree
- workspaces/arborist
- lib/arborist
- test
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
148 | 163 | | |
149 | 164 | | |
150 | 165 | | |
| |||
155 | 170 | | |
156 | 171 | | |
157 | 172 | | |
158 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
159 | 176 | | |
160 | 177 | | |
161 | 178 | | |
| |||
228 | 245 | | |
229 | 246 | | |
230 | 247 | | |
231 | | - | |
| 248 | + | |
232 | 249 | | |
233 | 250 | | |
234 | 251 | | |
| |||
246 | 263 | | |
247 | 264 | | |
248 | 265 | | |
249 | | - | |
| 266 | + | |
250 | 267 | | |
251 | 268 | | |
252 | 269 | | |
| |||
301 | 318 | | |
302 | 319 | | |
303 | 320 | | |
304 | | - | |
| 321 | + | |
305 | 322 | | |
306 | 323 | | |
307 | 324 | | |
| |||
335 | 352 | | |
336 | 353 | | |
337 | 354 | | |
338 | | - | |
| 355 | + | |
339 | 356 | | |
340 | 357 | | |
341 | 358 | | |
| |||
361 | 378 | | |
362 | 379 | | |
363 | 380 | | |
364 | | - | |
| 381 | + | |
365 | 382 | | |
366 | 383 | | |
367 | 384 | | |
368 | 385 | | |
369 | 386 | | |
370 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
371 | 392 | | |
372 | 393 | | |
373 | 394 | | |
| |||
379 | 400 | | |
380 | 401 | | |
381 | 402 | | |
382 | | - | |
| 403 | + | |
383 | 404 | | |
384 | 405 | | |
385 | 406 | | |
386 | 407 | | |
387 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
388 | 413 | | |
389 | 414 | | |
390 | 415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | | - | |
| 425 | + | |
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
167 | 171 | | |
168 | 172 | | |
169 | | - | |
| 173 | + | |
170 | 174 | | |
171 | 175 | | |
172 | 176 | | |
| |||
192 | 196 | | |
193 | 197 | | |
194 | 198 | | |
195 | | - | |
| 199 | + | |
196 | 200 | | |
197 | 201 | | |
198 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
312 | 371 | | |
313 | 372 | | |
314 | 373 | | |
| |||
1300 | 1359 | | |
1301 | 1360 | | |
1302 | 1361 | | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
1303 | 1469 | | |
1304 | 1470 | | |
1305 | 1471 | | |
| |||
0 commit comments