Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

#### :house: Internal

- Editor: resolve @rescript/runtime via environment variable RESCRIPT_RUNTIME. https://github.com/rescript-lang/rescript/pull/8023

# 12.0.0-rc.4

#### :boom: Breaking Change
Expand Down
40 changes: 30 additions & 10 deletions analysis/src/BuildSystem.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,39 @@ let namespacedName namespace name =

let ( /+ ) = Filename.concat

(*
Editor tooling can more accurately resolve the runtime path and will try and pass it via an environment variable.
Example path: "test-stdlib/node_modules/.pnpm/@rescript+runtime@12.0.0-rc.4/node_modules/@rescript/runtime"
*)

let getRuntimeDir rootPath =
match !Cfg.isDocGenFromCompiler with
| false -> (
let result =
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
"@rescript/runtime"
in
match result with
| Some path -> Some path
| None ->
let message = "@rescript/runtime could not be found" in
Log.log message;
None)
(* First check RESCRIPT_RUNTIME environment variable, like bsc does *)
match Sys.getenv_opt "RESCRIPT_RUNTIME" with
| Some envPath ->
if Debug.verbose () then
Printf.printf "[getRuntimeDir] Using RESCRIPT_RUNTIME=%s\n" envPath;
Some envPath
| None -> (
let result =
ModuleResolution.resolveNodeModulePath ~startPath:rootPath
"@rescript/runtime"
in
match result with
| Some path ->
if Debug.verbose () then
Printf.printf "[getRuntimeDir] Resolved via node_modules: %s\n" path;
Some path
| None ->
let message = "@rescript/runtime could not be found" in
Log.log message;
if Debug.verbose () then
Printf.printf
"[getRuntimeDir] Failed to resolve @rescript/runtime from \
rootPath=%s\n"
rootPath;
None))
| true -> Some rootPath

let getLibBs path = Files.ifExists (path /+ "lib" /+ "bs")
Expand Down
Loading