@@ -35,17 +35,13 @@ module LoadScript = {
3535}
3636
3737module CdnMeta = {
38- let baseUrl =
39- Node .Process .Env .nodeEnv === "development"
40- ? "https://cdn.rescript-lang.org"
41- : "" + "/playground-bundles"
38+ let getCompilerUrl = (baseUrl , version ): string =>
39+ ` ${baseUrl}/${Semver.toString(version)}/compiler.js`
4240
43- let getCompilerUrl = (version ): string => ` ${baseUrl}/${Semver.toString(version)}/compiler.js`
44-
45- let getLibraryCmijUrl = (version , libraryName : string ): string =>
41+ let getLibraryCmijUrl = (baseUrl , version , libraryName : string ): string =>
4642 ` ${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js`
4743
48- let getStdlibRuntimeUrl = (version , filename ) =>
44+ let getStdlibRuntimeUrl = (baseUrl , version , filename ) =>
4945 ` ${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}`
5046}
5147
@@ -104,11 +100,11 @@ let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option
104100 We coupled the compiler / library loading to prevent ppl to try loading compiler / cmij files
105101 separately and cause all kinds of race conditions.
106102 */
107- let attachCompilerAndLibraries = async (~version , ~libraries : array <string >, ()): result <
103+ let attachCompilerAndLibraries = async (~baseUrl , ~ version , ~libraries : array <string >, ()): result <
108104 unit ,
109105 array <string >,
110106> => {
111- let compilerUrl = CdnMeta .getCompilerUrl (version )
107+ let compilerUrl = CdnMeta .getCompilerUrl (baseUrl , version )
112108
113109 // Useful for debugging our local build
114110 /* let compilerUrl = "/static/linked-bs-bundle.js"; */
@@ -117,7 +113,7 @@ let attachCompilerAndLibraries = async (~version, ~libraries: array<string>, ())
117113 | Error (_ ) => Error ([` Could not load compiler from url ${compilerUrl}` ])
118114 | Ok (_ ) =>
119115 let promises = Array .map (libraries , async lib => {
120- let cmijUrl = CdnMeta .getLibraryCmijUrl (version , lib )
116+ let cmijUrl = CdnMeta .getLibraryCmijUrl (baseUrl , version , lib )
121117 switch await LoadScript .loadScriptPromise (cmijUrl ) {
122118 | Error (_ ) => Error (` Could not load cmij from url ${cmijUrl}` )
123119 | r => r
@@ -222,6 +218,7 @@ let defaultModuleSystem = "esmodule"
222218// component to give feedback to the user that an action happened (useful in
223219// cases where the output didn't visually change)
224220let useCompilerManager = (
221+ ~bundleBaseUrl : string ,
225222 ~initialVersion : option <Semver .t >= ?,
226223 ~initialModuleSystem = defaultModuleSystem ,
227224 ~initialLang : Lang .t = Res ,
@@ -405,7 +402,12 @@ let useCompilerManager = (
405402 // Latest version is already running on @rescript/react
406403 let libraries = getLibrariesForVersion (~version )
407404
408- switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
405+ switch await attachCompilerAndLibraries (
406+ ~baseUrl = bundleBaseUrl ,
407+ ~version ,
408+ ~libraries ,
409+ (),
410+ ) {
409411 | Ok () =>
410412 let instance = Compiler .make ()
411413 let apiVersion = apiVersion -> Version .fromString
@@ -460,14 +462,16 @@ let useCompilerManager = (
460462 | SwitchingCompiler (ready , version ) =>
461463 let libraries = getLibrariesForVersion (~version )
462464
463- switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
465+ switch await attachCompilerAndLibraries (~baseUrl = bundleBaseUrl , ~ version , ~libraries , ()) {
464466 | Ok () =>
465467 // Make sure to remove the previous script from the DOM as well
466- LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (ready .selected .id ))
468+ LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (bundleBaseUrl , ready .selected .id ))
467469
468470 // We are removing the previous libraries, therefore we use ready.selected here
469471 Array .forEach (ready .selected .libraries , lib =>
470- LoadScript .removeScript (~src = CdnMeta .getLibraryCmijUrl (ready .selected .id , lib ))
472+ LoadScript .removeScript (
473+ ~src = CdnMeta .getLibraryCmijUrl (bundleBaseUrl , ready .selected .id , lib ),
474+ )
471475 )
472476
473477 let instance = Compiler .make ()
@@ -576,7 +580,7 @@ let useCompilerManager = (
576580 }
577581 | version => version
578582 }
579- CdnMeta .getStdlibRuntimeUrl (compilerVersion , filename )
583+ CdnMeta .getStdlibRuntimeUrl (bundleBaseUrl , compilerVersion , filename )
580584 })
581585
582586 entryPointExists
0 commit comments