Commit f1745ac
committed
fix(arborist): honor allow-remote=root for root-direct remote tarballs (npm#9510)
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` with `allow-remote=root`, a fresh
install fails with `EALLOWREMOTE` on a genuine remote (non-registry)
tarball that is a direct dependency of the project root or a workspace.
The standard (hoisted) reifier installs the same dependency fine under
`allow-remote=root`; only the linked strategy rejects it.
```
npm error code EALLOWREMOTE
npm error Fetching non-root packages of type "remote" have been disabled
npm error Refusing to fetch "@react-native-community/slider@https://raw.githubusercontent.com/wordpress-mobile/react-native-slider/v3.0.2-wp-5/react-native-community-slider-3.0.2-wp-5.tgz"
```
## Why
The `allow-remote=root` gate is enforced at reify time by computing
`_isRoot` and passing it to `pacote.extract` in `reify.js`. A node
counts as "root" if it satisfies at least one valid dependency edge from
the project root or a workspace, which is derived from `node.edgesIn`.
In the linked strategy, store nodes are `IsolatedNode` instances with no
`edgesIn` to recompute root-ness from, so `_isRoot` was always `false`,
every remote tarball was treated as non-root, and pacote refused even a
legitimate root/workspace direct dependency.
This is the sibling of the registry-tarball fix (npm#9495). That change
carried `isRegistryDependency` onto store nodes so the registry-tarball
exemption still applied; this change carries the analogous root-ness
signal so the `allow-remote=root` gate resolves correctly for genuine
remote tarballs, which are not registry-mediated and so do not qualify
for the registry exemption.
This only widens `allow-remote=root`. `allow-remote=none` still rejects
all remote specs (pacote refuses regardless of `_isRoot`), and a
genuinely transitive remote dependency still fails the resolution-layer
`#checkAllow` gate during ideal-tree construction. Hoisted is unaffected
because its nodes retain real `edgesIn`.
## How
Carry a root-ness flag from the source tree node onto the store node,
rather than weakening the guard:
1. `IsolatedNode` gains an `isRootDependency` field (default `false`),
settable from constructor options.
2. `#externalProxy` computes `isRootDependency` from the real tree
node's `edgesIn` using the same predicate the reifier applies (a valid
edge from the project root or a workspace).
3. `#generateChild` passes it through to the store `IsolatedNode`.
4. The `_isRoot` computation in `reify.js` falls back to
`node.isRootDependency`. Hoisted nodes do not have the property, so they
fall through to the existing edge-based check unchanged.
## References
Fixes npm#9509
Follows-up npm#94951 parent bcf01c6 commit f1745ac
4 files changed
Lines changed: 41 additions & 1 deletion
File tree
- workspaces/arborist
- lib
- arborist
- test/arborist
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
157 | 158 | | |
158 | 159 | | |
159 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
160 | 165 | | |
161 | 166 | | |
162 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
707 | 707 | | |
708 | 708 | | |
709 | 709 | | |
710 | | - | |
| 710 | + | |
| 711 | + | |
711 | 712 | | |
712 | 713 | | |
713 | 714 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
57 | 61 | | |
58 | 62 | | |
59 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3904 | 3904 | | |
3905 | 3905 | | |
3906 | 3906 | | |
| 3907 | + | |
| 3908 | + | |
| 3909 | + | |
| 3910 | + | |
| 3911 | + | |
| 3912 | + | |
| 3913 | + | |
| 3914 | + | |
| 3915 | + | |
| 3916 | + | |
| 3917 | + | |
| 3918 | + | |
| 3919 | + | |
| 3920 | + | |
| 3921 | + | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
| 3934 | + | |
| 3935 | + | |
| 3936 | + | |
3907 | 3937 | | |
3908 | 3938 | | |
3909 | 3939 | | |
| |||
0 commit comments