Commit 880ecb7
authored
fix(arborist): skip postinstall on store links in linked strategy (npm#9013)
Continuing the `install-strategy=linked` fixes from npm#8996. While testing
on the [Gutenberg
monorepo](WordPress/gutenberg#75814), `esbuild`
installs fail because its postinstall script runs twice in parallel
against the same store directory.
## Summary
With `install-strategy=linked`, postinstall scripts run twice for every
store package — once for the store entry and once for its symlink. For
packages like `esbuild` whose postinstall modifies files in-place
(`fs.linkSync` to replace the JS wrapper with a native binary), this
race condition corrupts the install.
## Root cause
In `rebuild.js`, `#runScripts` destructures `isStoreLink` from
`node.target` (the store entry) to decide whether to skip a node. But
`isStoreLink` is a property of the link node itself (`node`), not its
target. Store entries don't have `isStoreLink`, so it's always
`undefined` and the guard never triggers. Both the store entry and the
store link run scripts against the same directory in parallel.
## Changes
- Fixed the skip condition in `rebuild.js` `#runScripts` to use
`node.isLink && node.target?.isInStore` instead of reading `isStoreLink`
from `node.target`. This correctly skips store links (symlinks pointing
to store entries) while still allowing workspace links and store entries
themselves to run scripts.
- Added a regression test that verifies postinstall scripts run exactly
once for store packages.
## References
Fixes npm#90121 parent 658b323 commit 880ecb7
2 files changed
Lines changed: 33 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
299 | 298 | | |
300 | 299 | | |
301 | 300 | | |
302 | | - | |
303 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1571 | 1571 | | |
1572 | 1572 | | |
1573 | 1573 | | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
1574 | 1604 | | |
1575 | 1605 | | |
1576 | 1606 | | |
| |||
0 commit comments