@@ -35,17 +35,13 @@ module LoadScript = {
35
35
}
36
36
37
37
module 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`
42
40
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 =>
46
42
` ${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js`
47
43
48
- let getStdlibRuntimeUrl = (version , filename ) =>
44
+ let getStdlibRuntimeUrl = (baseUrl , version , filename ) =>
49
45
` ${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}`
50
46
}
51
47
@@ -104,11 +100,11 @@ let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option
104
100
We coupled the compiler / library loading to prevent ppl to try loading compiler / cmij files
105
101
separately and cause all kinds of race conditions.
106
102
*/
107
- let attachCompilerAndLibraries = async (~version , ~libraries : array <string >, ()): result <
103
+ let attachCompilerAndLibraries = async (~baseUrl , ~ version , ~libraries : array <string >, ()): result <
108
104
unit ,
109
105
array <string >,
110
106
> => {
111
- let compilerUrl = CdnMeta .getCompilerUrl (version )
107
+ let compilerUrl = CdnMeta .getCompilerUrl (baseUrl , version )
112
108
113
109
// Useful for debugging our local build
114
110
/* let compilerUrl = "/static/linked-bs-bundle.js"; */
@@ -117,7 +113,7 @@ let attachCompilerAndLibraries = async (~version, ~libraries: array<string>, ())
117
113
| Error (_ ) => Error ([` Could not load compiler from url ${compilerUrl}` ])
118
114
| Ok (_ ) =>
119
115
let promises = Array .map (libraries , async lib => {
120
- let cmijUrl = CdnMeta .getLibraryCmijUrl (version , lib )
116
+ let cmijUrl = CdnMeta .getLibraryCmijUrl (baseUrl , version , lib )
121
117
switch await LoadScript .loadScriptPromise (cmijUrl ) {
122
118
| Error (_ ) => Error (` Could not load cmij from url ${cmijUrl}` )
123
119
| r => r
@@ -222,6 +218,7 @@ let defaultModuleSystem = "esmodule"
222
218
// component to give feedback to the user that an action happened (useful in
223
219
// cases where the output didn't visually change)
224
220
let useCompilerManager = (
221
+ ~bundleBaseUrl : string ,
225
222
~initialVersion : option <Semver .t >= ?,
226
223
~initialModuleSystem = defaultModuleSystem ,
227
224
~initialLang : Lang .t = Res ,
@@ -405,7 +402,12 @@ let useCompilerManager = (
405
402
// Latest version is already running on @rescript/react
406
403
let libraries = getLibrariesForVersion (~version )
407
404
408
- switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
405
+ switch await attachCompilerAndLibraries (
406
+ ~baseUrl = bundleBaseUrl ,
407
+ ~version ,
408
+ ~libraries ,
409
+ (),
410
+ ) {
409
411
| Ok () =>
410
412
let instance = Compiler .make ()
411
413
let apiVersion = apiVersion -> Version .fromString
@@ -460,14 +462,16 @@ let useCompilerManager = (
460
462
| SwitchingCompiler (ready , version ) =>
461
463
let libraries = getLibrariesForVersion (~version )
462
464
463
- switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
465
+ switch await attachCompilerAndLibraries (~baseUrl = bundleBaseUrl , ~ version , ~libraries , ()) {
464
466
| Ok () =>
465
467
// 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 ))
467
469
468
470
// We are removing the previous libraries, therefore we use ready.selected here
469
471
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
+ )
471
475
)
472
476
473
477
let instance = Compiler .make ()
@@ -576,7 +580,7 @@ let useCompilerManager = (
576
580
}
577
581
| version => version
578
582
}
579
- CdnMeta .getStdlibRuntimeUrl (compilerVersion , filename )
583
+ CdnMeta .getStdlibRuntimeUrl (bundleBaseUrl , compilerVersion , filename )
580
584
})
581
585
582
586
entryPointExists
0 commit comments