@@ -38,7 +38,7 @@ module LoadScript = {
38
38
module CdnMeta = {
39
39
// Make sure versions exist on https://cdn.rescript-lang.org
40
40
// [0] = latest
41
- let versions = ["v8.4.2" , "v8.3.0-dev.2" ]
41
+ let versions = ["v9.0.0" , " v8.4.2" , "v8.3.0-dev.2" ]
42
42
43
43
let getCompilerUrl = (version : string ): string =>
44
44
j ` https://cdn.rescript-lang.org/$version/compiler.js`
@@ -55,6 +55,31 @@ module FinalResult = {
55
55
| Nothing
56
56
}
57
57
58
+ // This will a given list of libraries to a specific target version of the compiler.
59
+ // E.g. starting from v9, @rescript/react instead of reason-react is used.
60
+ let migrateLibraries = (~version : string , libraries : array <string >): array <string > => {
61
+ switch Js .String2 .split (version , "." )-> Belt .List .fromArray {
62
+ | list {major , ... _rest } =>
63
+ let version =
64
+ Js .String2 .replace (major , "v" , "" )-> Belt .Int .fromString -> Belt .Option .getWithDefault (0 )
65
+
66
+ Belt .Array .map (libraries , library => {
67
+ if version >= 9 {
68
+ switch library {
69
+ | "reason-react" => "@rescript/react"
70
+ | _ => library
71
+ }
72
+ } else {
73
+ switch library {
74
+ | "@rescript/react" => "reason-react"
75
+ | _ => library
76
+ }
77
+ }
78
+ })
79
+ | _ => libraries
80
+ }
81
+ }
82
+
58
83
/*
59
84
This function loads the compiler, plus a defined set of libraries that are available
60
85
on our bs-platform-js-releases channel.
@@ -300,13 +325,14 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
300
325
React .useEffect1 (() => {
301
326
switch state {
302
327
| Init =>
303
- let libraries = ["reason-react" ]
304
-
305
328
switch CdnMeta .versions {
306
329
| [] => dispatchError (SetupError (j ` No compiler versions found` ))
307
330
| versions =>
308
331
let latest = versions [0 ]
309
332
333
+ // Latest version is already running on @rescript/react
334
+ let libraries = ["@rescript/react" ]
335
+
310
336
attachCompilerAndLibraries (~version = latest , ~libraries , ())
311
337
-> Promise .map (result =>
312
338
switch result {
@@ -347,12 +373,16 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
347
373
-> ignore
348
374
}
349
375
| SwitchingCompiler (ready , version , libraries ) =>
350
- attachCompilerAndLibraries (~version , ~libraries , ())-> Promise .map (result =>
376
+ let migratedLibraries = libraries -> migrateLibraries (~version )
377
+
378
+ attachCompilerAndLibraries (~version , ~libraries = migratedLibraries , ())
379
+ -> Promise .map (result =>
351
380
switch result {
352
381
| Ok () =>
353
382
// Make sure to remove the previous script from the DOM as well
354
383
LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (ready .selected .id ))
355
384
385
+ // We are removing the previous libraries, therefore we use ready.selected here
356
386
Belt .Array .forEach (ready .selected .libraries , lib =>
357
387
LoadScript .removeScript (~src = CdnMeta .getLibraryCmijUrl (ready .selected .id , lib ))
358
388
)
@@ -368,7 +398,7 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
368
398
ocamlVersion : instance -> Compiler .ocamlVersion ,
369
399
reasonVersion : instance -> Compiler .reasonVersion ,
370
400
config : config ,
371
- libraries : libraries ,
401
+ libraries : migratedLibraries ,
372
402
instance : instance ,
373
403
}
374
404
@@ -384,7 +414,8 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
384
414
385
415
dispatchError (CompilerLoadingError (msg ))
386
416
}
387
- )-> ignore
417
+ )
418
+ -> ignore
388
419
| Compiling (ready , (lang , code )) =>
389
420
let apiVersion = ready .selected .apiVersion
390
421
let instance = ready .selected .instance
0 commit comments