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