Skip to content

Commit 68bfe78

Browse files
committed
Hack to fix finding runtime module in analysis/tools
1 parent 6366814 commit 68bfe78

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

analysis/src/BuildSystem.ml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ let namespacedName namespace name =
66
let ( /+ ) = Filename.concat
77

88
let getRuntimeDir rootPath =
9-
let result =
10-
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
11-
"@rescript/runtime"
12-
in
13-
match result with
14-
| Some path -> Some path
15-
| None ->
16-
let message = "@rescript/runtime could not be found" in
17-
Log.log message;
18-
None
9+
match !Cfg.isDocGenFromCompiler with
10+
| false -> (
11+
let result =
12+
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
13+
"@rescript/runtime"
14+
in
15+
match result with
16+
| Some path -> Some path
17+
| None ->
18+
let message = "@rescript/runtime could not be found" in
19+
Log.log message;
20+
None)
21+
| true -> Some rootPath
1922

20-
let getLibBs root = Files.ifExists (root /+ "lib" /+ "bs")
23+
let getLibBs path = Files.ifExists (path /+ "lib" /+ "bs")
2124

2225
let getStdlib base =
2326
match getRuntimeDir base with

analysis/src/FindFiles.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ let findProjectFiles ~public ~namespace ~path ~sourceDirectories ~libBs =
142142
in
143143
let files =
144144
dirs |> StringSet.elements
145-
|> List.map (fun name -> Files.collect ~maxDepth:1 name isSourceFile)
145+
|> List.map (fun name -> Files.collect ~maxDepth:2 name isSourceFile)
146146
|> List.concat |> StringSet.of_list
147147
in
148148
dirs

analysis/src/ModuleResolution.ml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
let ( /+ ) = Filename.concat
22

33
let rec resolveNodeModulePath ~startPath name =
4-
let scope = Filename.dirname name in
5-
let name = Filename.basename name in
6-
let name =
7-
match scope.[0] with
8-
| '@' -> scope /+ name
9-
| _ -> name
10-
in
11-
let path = startPath /+ "node_modules" /+ name in
12-
if Files.exists path then Some path
13-
else if Filename.dirname startPath = startPath then None
14-
else resolveNodeModulePath ~startPath:(Filename.dirname startPath) name
4+
if name = "@rescript/runtime" then
5+
(* Hack: we need a reliable way to resolve modules in monorepos. *)
6+
Some Config.runtime_module_path
7+
else
8+
let scope = Filename.dirname name in
9+
let name = Filename.basename name in
10+
let name =
11+
match scope.[0] with
12+
| '@' -> scope /+ name
13+
| _ -> name
14+
in
15+
let path = startPath /+ "node_modules" /+ name in
16+
if Files.exists path then Some path
17+
else if Filename.dirname startPath = startPath then None
18+
else resolveNodeModulePath ~startPath:(Filename.dirname startPath) name

compiler/ext/config.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(* This resolves the location of the standard library starting from the location of bsc.exe
22
(@rescript/{platform}/bin/bsc.exe), handling different supported package layouts. *)
3-
let standard_library =
3+
let runtime_module_path =
44
let build_path rest path =
55
String.concat Filename.dir_sep (List.rev_append rest path)
66
in
@@ -15,21 +15,25 @@ let standard_library =
1515
*)
1616
| "bin" :: _platform :: "@rescript" :: "node_modules" :: _package :: ".pnpm"
1717
:: "node_modules" :: rest ->
18-
build_path rest ["node_modules"; "@rescript"; "runtime"; "lib"; "ocaml"]
18+
build_path rest ["node_modules"; "@rescript"; "runtime"]
1919
(* 2. Packages installed via npm
2020
- bin: node_modules/@rescript/{platform}/bin
2121
- stdlib: node_modules/@rescript/runtime/lib/ocaml
2222
*)
2323
| "bin" :: _platform :: "@rescript" :: "node_modules" :: rest ->
24-
build_path rest ["node_modules"; "@rescript"; "runtime"; "lib"; "ocaml"]
24+
build_path rest ["node_modules"; "@rescript"; "runtime"]
2525
(* 3. Several other cases that can occur in local development, e.g.
2626
- bin: <repo>/packages/@rescript/{platform}/bin, <repo>/_build/install/default/bin
2727
- stdlib: <repo>/packages/@rescript/runtime/lib/ocaml
2828
*)
2929
| _ :: _ :: _ :: _ :: rest ->
30-
build_path rest ["packages"; "@rescript"; "runtime"; "lib"; "ocaml"]
30+
build_path rest ["packages"; "@rescript"; "runtime"]
3131
| _ -> ""
3232

33+
let standard_library =
34+
let ( // ) = Filename.concat in
35+
runtime_module_path // "lib" // "ocaml"
36+
3337
let cmi_magic_number = "Caml1999I022"
3438

3539
and ast_impl_magic_number = "Caml1999M022"

compiler/ext/config.mli

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
(* System configuration *)
1717

18+
(* The directory containing the runtime module (@rescript/runtime) *)
19+
val runtime_module_path : string
20+
21+
(* The directory containing the runtime artifacts (@rescript/runtime/lib/ocaml) *)
1822
val standard_library : string
19-
(* The directory containing the standard libraries *)
2023

21-
val load_path : string list ref
2224
(* Directories in the search path for .cmi and .cmo files *)
25+
val load_path : string list ref
2326

2427
val cmi_magic_number : string
2528

0 commit comments

Comments
 (0)