Commit ca92323
authored
fix(arborist): clean up stale .store and hoisted dirs on strategy switch (#9647)
In continuation of our exploration of using `install-strategy=linked` in
the [Gutenberg
monorepo](WordPress/gutenberg#75814), which
powers the WordPress Block Editor.
Switching `install-strategy` in the same project directory left behind
the previous strategy's layout. Going hoisted → linked kept the stale
real top-level transitive directories alongside the new `.store/` and
symlinks; going linked → hoisted kept the entire `node_modules/.store/`
directory. A fresh install of either strategy was already clean — only
the switch was affected.
## Why
Under the linked strategy the actual tree the diff compares against is
synthesized from the ideal tree (`#buildLinkedActualForDiff`), so real
directories left over from a prior hoisted layout are never seen, and
`#cleanOrphanedTopLevelLinks` only removed symlinks. In the other
direction `load-actual` ignores dot-directories, so the hoisted diff
never sees `node_modules/.store` and never removes it.
## How
`reify.js` now removes the leftover `.store` on a non-linked reify via
`#removeStaleStoreDir`. The store lives only at the project root and is
exclusively a linked artifact, so a single removal covers the project.
It runs only for a full-project install — a workspace-filtered or
`--workspaces=false` install is skipped, because out-of-scope workspaces
may still link into the store.
`#cleanOrphanedTopLevelLinks` (run only under linked) additionally
removes stale real package directories — a directory containing a
`package.json` that is not in the ideal tree's valid top-level set — and
prunes an emptied `@scope` directory afterward. Non-package real
directories and symlinks pointing outside the project are still
preserved.
The valid-top-level collection in `#cleanOrphanedStoreEntries` no longer
skips non-link nodes, so the root's bundled dependencies — materialized
as real top-level directories under linked — are recorded as valid and
never swept as stale.
## References
Fixes #9615
Part of #96081 parent d6fbb55 commit ca92323
2 files changed
Lines changed: 147 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
147 | 155 | | |
148 | 156 | | |
149 | 157 | | |
| |||
1452 | 1460 | | |
1453 | 1461 | | |
1454 | 1462 | | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
1455 | 1475 | | |
1456 | 1476 | | |
1457 | 1477 | | |
| |||
1490 | 1510 | | |
1491 | 1511 | | |
1492 | 1512 | | |
1493 | | - | |
| 1513 | + | |
1494 | 1514 | | |
1495 | 1515 | | |
1496 | 1516 | | |
| |||
1504 | 1524 | | |
1505 | 1525 | | |
1506 | 1526 | | |
1507 | | - | |
1508 | | - | |
1509 | | - | |
1510 | 1527 | | |
1511 | | - | |
| 1528 | + | |
1512 | 1529 | | |
1513 | 1530 | | |
| 1531 | + | |
1514 | 1532 | | |
1515 | 1533 | | |
1516 | 1534 | | |
| |||
1654 | 1672 | | |
1655 | 1673 | | |
1656 | 1674 | | |
1657 | | - | |
1658 | | - | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
1659 | 1679 | | |
1660 | 1680 | | |
1661 | 1681 | | |
| |||
1676 | 1696 | | |
1677 | 1697 | | |
1678 | 1698 | | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
1679 | 1706 | | |
| 1707 | + | |
1680 | 1708 | | |
1681 | 1709 | | |
1682 | 1710 | | |
| |||
1692 | 1720 | | |
1693 | 1721 | | |
1694 | 1722 | | |
1695 | | - | |
| 1723 | + | |
1696 | 1724 | | |
| 1725 | + | |
1697 | 1726 | | |
1698 | 1727 | | |
1699 | | - | |
| 1728 | + | |
1700 | 1729 | | |
1701 | 1730 | | |
1702 | 1731 | | |
| |||
1705 | 1734 | | |
1706 | 1735 | | |
1707 | 1736 | | |
1708 | | - | |
| 1737 | + | |
1709 | 1738 | | |
1710 | 1739 | | |
1711 | 1740 | | |
1712 | 1741 | | |
1713 | | - | |
| 1742 | + | |
1714 | 1743 | | |
1715 | 1744 | | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
1716 | 1760 | | |
1717 | 1761 | | |
1718 | 1762 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4399 | 4399 | | |
4400 | 4400 | | |
4401 | 4401 | | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
| 4407 | + | |
| 4408 | + | |
| 4409 | + | |
| 4410 | + | |
| 4411 | + | |
| 4412 | + | |
| 4413 | + | |
| 4414 | + | |
| 4415 | + | |
| 4416 | + | |
| 4417 | + | |
| 4418 | + | |
| 4419 | + | |
| 4420 | + | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + | |
| 4472 | + | |
| 4473 | + | |
| 4474 | + | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
| 4478 | + | |
| 4479 | + | |
| 4480 | + | |
| 4481 | + | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + | |
| 4490 | + | |
| 4491 | + | |
| 4492 | + | |
| 4493 | + | |
4402 | 4494 | | |
4403 | 4495 | | |
4404 | 4496 | | |
| |||
0 commit comments