|
1 | | -import { readdir, stat as statAsync } from "fs/promises"; |
| 1 | +import { readdir, stat as statAsync, readFile } from "fs/promises"; |
2 | 2 | import { join, resolve } from "path"; |
| 3 | +import { compilerInfoPartialPath } from "./constants"; |
3 | 4 |
|
4 | 5 | // Efficient parallel folder traversal to find node_modules directories |
5 | 6 | async function findNodeModulesDirs( |
@@ -91,7 +92,19 @@ async function findRescriptRuntimeInAlternativeLayout( |
91 | 92 | return results; |
92 | 93 | } |
93 | 94 |
|
94 | | -async function findRuntimePath(project: string) { |
| 95 | +async function findRuntimePath(project: string): Promise<string[]> { |
| 96 | + // Try a compiler-info.json file first |
| 97 | + const compilerInfo = resolve(project, compilerInfoPartialPath); |
| 98 | + try { |
| 99 | + const contents = await readFile(compilerInfo, "utf8"); |
| 100 | + const compileInfo: { runtime_path?: string } = JSON.parse(contents); |
| 101 | + if (compileInfo && compileInfo.runtime_path) { |
| 102 | + return [compileInfo.runtime_path]; |
| 103 | + } |
| 104 | + } catch { |
| 105 | + // Ignore errors, fallback to node_modules search |
| 106 | + } |
| 107 | + |
95 | 108 | // Find all node_modules directories using efficient traversal |
96 | 109 | const node_modules = await findNodeModulesDirs(project); |
97 | 110 |
|
@@ -136,7 +149,7 @@ async function findRuntimePath(project: string) { |
136 | 149 | return rescriptRuntimeDirs.map((runtime) => resolve(runtime)); |
137 | 150 | } |
138 | 151 |
|
139 | | -function findRuntimeCached() { |
| 152 | +function findRuntimeCached(): (project: string) => Promise<string[]> { |
140 | 153 | const cache = new Map<string, string[]>(); |
141 | 154 | return async (project: string) => { |
142 | 155 | if (cache.has(project)) { |
|
0 commit comments