@@ -35,13 +35,17 @@ module LoadScript = {
3535}
3636
3737module CdnMeta = {
38- let getCompilerUrl = (baseUrl , version ): string =>
39- ` ${baseUrl}/${Semver.toString(version)}/compiler.js`
38+ let baseUrl =
39+ Node .Process .Env .nodeEnv === "development"
40+ ? "https://cdn.rescript-lang.org"
41+ : "" + "/playground-bundles"
4042
41- let getLibraryCmijUrl = (baseUrl , version , libraryName : string ): string =>
43+ let getCompilerUrl = (version ): string => ` ${baseUrl}/${Semver.toString(version)}/compiler.js`
44+
45+ let getLibraryCmijUrl = (version , libraryName : string ): string =>
4246 ` ${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js`
4347
44- let getStdlibRuntimeUrl = (baseUrl , version , filename ) =>
48+ let getStdlibRuntimeUrl = (version , filename ) =>
4549 ` ${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}`
4650}
4751
@@ -100,11 +104,11 @@ let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option
100104 We coupled the compiler / library loading to prevent ppl to try loading compiler / cmij files
101105 separately and cause all kinds of race conditions.
102106 */
103- let attachCompilerAndLibraries = async (~baseUrl , ~ version , ~libraries : array <string >, ()): result <
107+ let attachCompilerAndLibraries = async (~version , ~libraries : array <string >, ()): result <
104108 unit ,
105109 array <string >,
106110> => {
107- let compilerUrl = CdnMeta .getCompilerUrl (baseUrl , version )
111+ let compilerUrl = CdnMeta .getCompilerUrl (version )
108112
109113 // Useful for debugging our local build
110114 /* let compilerUrl = "/static/linked-bs-bundle.js"; */
@@ -113,7 +117,7 @@ let attachCompilerAndLibraries = async (~baseUrl, ~version, ~libraries: array<st
113117 | Error (_ ) => Error ([` Could not load compiler from url ${compilerUrl}` ])
114118 | Ok (_ ) =>
115119 let promises = Array .map (libraries , async lib => {
116- let cmijUrl = CdnMeta .getLibraryCmijUrl (baseUrl , version , lib )
120+ let cmijUrl = CdnMeta .getLibraryCmijUrl (version , lib )
117121 switch await LoadScript .loadScriptPromise (cmijUrl ) {
118122 | Error (_ ) => Error (` Could not load cmij from url ${cmijUrl}` )
119123 | r => r
@@ -218,7 +222,6 @@ let defaultModuleSystem = "esmodule"
218222// component to give feedback to the user that an action happened (useful in
219223// cases where the output didn't visually change)
220224let useCompilerManager = (
221- ~bundleBaseUrl : string ,
222225 ~initialVersion : option <Semver .t >= ?,
223226 ~initialModuleSystem = defaultModuleSystem ,
224227 ~initialLang : Lang .t = Res ,
@@ -402,12 +405,7 @@ let useCompilerManager = (
402405 // Latest version is already running on @rescript/react
403406 let libraries = getLibrariesForVersion (~version )
404407
405- switch await attachCompilerAndLibraries (
406- ~baseUrl = bundleBaseUrl ,
407- ~version ,
408- ~libraries ,
409- (),
410- ) {
408+ switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
411409 | Ok () =>
412410 let instance = Compiler .make ()
413411 let apiVersion = apiVersion -> Version .fromString
@@ -462,16 +460,14 @@ let useCompilerManager = (
462460 | SwitchingCompiler (ready , version ) =>
463461 let libraries = getLibrariesForVersion (~version )
464462
465- switch await attachCompilerAndLibraries (~baseUrl = bundleBaseUrl , ~ version , ~libraries , ()) {
463+ switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
466464 | Ok () =>
467465 // Make sure to remove the previous script from the DOM as well
468- LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (bundleBaseUrl , ready .selected .id ))
466+ LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (ready .selected .id ))
469467
470468 // We are removing the previous libraries, therefore we use ready.selected here
471469 Array .forEach (ready .selected .libraries , lib =>
472- LoadScript .removeScript (
473- ~src = CdnMeta .getLibraryCmijUrl (bundleBaseUrl , ready .selected .id , lib ),
474- )
470+ LoadScript .removeScript (~src = CdnMeta .getLibraryCmijUrl (ready .selected .id , lib ))
475471 )
476472
477473 let instance = Compiler .make ()
@@ -580,7 +576,7 @@ let useCompilerManager = (
580576 }
581577 | version => version
582578 }
583- CdnMeta .getStdlibRuntimeUrl (bundleBaseUrl , compilerVersion , filename )
579+ CdnMeta .getStdlibRuntimeUrl (compilerVersion , filename )
584580 })
585581
586582 entryPointExists
0 commit comments