Commit 6e2375b
committed
fix(embed): install @huggingface/transformers into codegraph's host node_modules
`embed`'s lazy install calls `execFileSync('npm', ['install', ...])` with
no `cwd`. Default cwd = `process.cwd()`, which is whatever directory the
user invoked codegraph from — typically NOT the directory where codegraph
itself is installed.
The resulting install lands in the user's project node_modules, but the
subsequent `await import('@huggingface/transformers')` resolves from
codegraph's own location, where the dep is missing. The user sees:
[ENGINE_UNAVAILABLE]: @huggingface/transformers was installed
but failed to load. Please check your environment.
…while their project's node_modules silently gains an unwanted dep.
Pin `cwd` to the host directory that contains @optave/codegraph (resolved
via `_require.resolve('@optave/codegraph/package.json')` then four
`path.dirname` hops). The install now lands in the same node_modules that
contains codegraph, so the dynamic import resolves correctly without
polluting the user's working directory.
Falls back to `cwd: undefined` (= process.cwd()) when @optave/codegraph
can't be resolved — typically a source-of-truth dev checkout — so the
existing test suite (which mocks the import to fail) continues to pass.
Closes #11751 parent 4d8df7b commit 6e2375b
1 file changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
6 | 36 | | |
7 | 37 | | |
8 | 38 | | |
| |||
104 | 134 | | |
105 | 135 | | |
106 | 136 | | |
| 137 | + | |
107 | 138 | | |
108 | 139 | | |
109 | 140 | | |
110 | 141 | | |
111 | 142 | | |
112 | 143 | | |
| 144 | + | |
113 | 145 | | |
114 | 146 | | |
115 | 147 | | |
| |||
131 | 163 | | |
132 | 164 | | |
133 | 165 | | |
| 166 | + | |
134 | 167 | | |
135 | 168 | | |
136 | 169 | | |
| |||
0 commit comments