Commit 74311e7
committed
fix(core): omit peer dependencies when installing packages to a temp dir (#36295)
`installPackageToTmp` (behind devkit's `ensurePackage`) fetches a
package into an **empty** temp directory. npm and bun **auto-install
that package's peer dependencies** there. So a loose peer range — e.g.
`@phenomnomnominal/tsquery`'s `typescript: >3.0.0` — pulls the
**newest** major, TypeScript 7, into the temp dir. tsquery reads
`ts.SyntaxKind` at module load, which TS 7 no longer exposes as a
top-level CommonJS export, so it crashes:
```
NX Cannot convert undefined or null to object
at Object.keys (<anonymous>)
at .../@phenomnomnominal/tsquery/dist/src/syntax-kind.js:8:27
```
Peer dependencies are the **host's** responsibility, not something a
throwaway fetch should decide. `ensurePackage` already loads the package
from the temp dir with the workspace's `node_modules` on `NODE_PATH`, so
its peers resolve from the workspace — the correct provider. This omits
peers from the temp install so nothing incompatible gets pulled:
- **npm** / **bun**: `--omit=peer`
- **pnpm**: `--config.auto-install-peers=false`
- **Yarn** (classic & Berry): never auto-installs peers, so no flag
needed
Verified locally: with `--omit=peer` the temp dir no longer contains
TypeScript 7, and loading the package resolves `typescript@6.0.3` from
the workspace via `NODE_PATH`. Unit tests cover the emitted install
command for every package manager.
Hardening for the `ensurePackage` path, surfaced while investigating the
TypeScript 7 / tsquery crash. Complements bounding tsquery's
`typescript` peer range at the source.
<!-- polygraph-session-start -->
---
[View session information
↗](https://app.trypolygraph.com/orgs/6a061dcb561c062131116eca/sessions/Migrate-nrwl-repos-to-nx-23.1.0-rc.0-b8c94700)
<!-- polygraph-session-end -->
(cherry picked from commit edc9212)1 parent 23d2a55 commit 74311e7
2 files changed
Lines changed: 80 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
106 | 166 | | |
107 | 167 | | |
108 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
388 | | - | |
389 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
390 | 406 | | |
391 | 407 | | |
392 | 408 | | |
| |||
0 commit comments