11import { readdir , stat as statAsync , readFile } from "fs/promises" ;
22import { join , resolve } from "path" ;
33import { compilerInfoPartialPath } from "./constants" ;
4+ import { NormalizedPath , normalizePath } from "./utils" ;
45
56// Efficient parallel folder traversal to find node_modules directories
67async function findNodeModulesDirs (
@@ -92,14 +93,18 @@ async function findRescriptRuntimeInAlternativeLayout(
9293 return results ;
9394}
9495
95- async function findRuntimePath ( project : string ) : Promise < string [ ] > {
96+ async function findRuntimePath (
97+ project : NormalizedPath ,
98+ ) : Promise < NormalizedPath [ ] > {
9699 // Try a compiler-info.json file first
97100 const compilerInfo = resolve ( project , compilerInfoPartialPath ) ;
98101 try {
99102 const contents = await readFile ( compilerInfo , "utf8" ) ;
100103 const compileInfo : { runtime_path ?: string } = JSON . parse ( contents ) ;
101104 if ( compileInfo && compileInfo . runtime_path ) {
102- return [ compileInfo . runtime_path ] ;
105+ // We somewhat assume the user to pass down a normalized path, but we cannot be sure of this.
106+ const normalizedRuntimePath = normalizePath ( compileInfo . runtime_path ) ;
107+ return normalizedRuntimePath ? [ normalizedRuntimePath ] : [ ] ;
103108 }
104109 } catch {
105110 // Ignore errors, fallback to node_modules search
@@ -146,7 +151,10 @@ async function findRuntimePath(project: string): Promise<string[]> {
146151 } ) ,
147152 ) . then ( ( results ) => results . flatMap ( ( x ) => x ) ) ;
148153
149- return rescriptRuntimeDirs . map ( ( runtime ) => resolve ( runtime ) ) ;
154+ return rescriptRuntimeDirs . map (
155+ // `resolve` ensures we can assume string is now NormalizedPath
156+ ( runtime ) => resolve ( runtime ) as NormalizedPath ,
157+ ) ;
150158}
151159
152160/**
@@ -156,7 +164,7 @@ async function findRuntimePath(project: string): Promise<string[]> {
156164 * (see getRuntimePathFromWorkspaceRoot in utils.ts).
157165 */
158166export async function findRescriptRuntimesInProject (
159- project : string ,
160- ) : Promise < string [ ] > {
167+ project : NormalizedPath ,
168+ ) : Promise < NormalizedPath [ ] > {
161169 return await findRuntimePath ( project ) ;
162170}
0 commit comments