@@ -145,6 +145,12 @@ let getLibrariesForVersion = (~version: Semver.t): array<string> => {
145145 libraries
146146}
147147
148+ let getOpenModules = (~apiVersion : Version .t , ~libraries : array <string >): option <array <string >> =>
149+ switch apiVersion {
150+ | V1 | V2 | V3 | UnknownVersion (_ ) => None
151+ | V4 => libraries -> Belt .Array .some (el => el === "@rescript/core" ) ? Some (["RescriptCore" ]) : None
152+ }
153+
148154/*
149155 This function loads the compiler, plus a defined set of libraries that are available
150156 on our bs-platform-js-releases channel.
@@ -396,6 +402,7 @@ let useCompilerManager = (
396402 | Ok () =>
397403 let instance = Compiler .make ()
398404 let apiVersion = apiVersion -> Version .fromString
405+ let open_modules = getOpenModules (~apiVersion , ~libraries )
399406
400407 // Note: The compiler bundle currently defaults to
401408 // commonjs when initiating the compiler, but our playground
@@ -405,6 +412,7 @@ let useCompilerManager = (
405412 let config = {
406413 ... instance -> Compiler .getConfig ,
407414 module_system : "es6" ,
415+ ?open_modules ,
408416 }
409417 instance -> Compiler .setConfig (config )
410418
@@ -453,11 +461,7 @@ let useCompilerManager = (
453461
454462 let instance = Compiler .make ()
455463 let apiVersion = apiVersion -> Version .fromString
456-
457- let open_modules =
458- libraries -> Belt .Array .some (el => el === "@rescript/core" )
459- ? Some (["RescriptCore" ])
460- : None
464+ let open_modules = getOpenModules (~apiVersion , ~libraries )
461465
462466 let config = {... instance -> Compiler .getConfig , ?open_modules }
463467 instance -> Compiler .setConfig (config )
0 commit comments