Skip to content

Commit 82b7173

Browse files
committed
Extend Playground with v9 functionality
1 parent f1df764 commit 82b7173

File tree

4 files changed

+114
-42
lines changed

4 files changed

+114
-42
lines changed

src/Playground.js

Lines changed: 25 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Playground.res

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,17 +1079,25 @@ module Settings = {
10791079
selected=config.module_system
10801080
onChange=onModuleSystemUpdate
10811081
/>
1082-
<div className="mt-8">
1083-
<div className=titleClass>
1084-
{React.string("Warning Flags")}
1085-
<button onMouseDown=onResetClick className={"ml-6 text-14 " ++ Text.Link.standalone}>
1086-
{React.string("[reset]")}
1087-
</button>
1088-
</div>
1089-
<div className="flex justify-end" />
1090-
<div style={ReactDOM.Style.make(~maxWidth="40rem", ())}>
1091-
<WarningFlagsWidget onUpdate=onWarningFlagsUpdate flags=warnFlagTokens />
1092-
</div>
1082+
</div>
1083+
<div className="mt-6">
1084+
<div className=titleClass> {React.string("Enabled Libraries")} </div>
1085+
<ul>
1086+
{Belt.Array.map(readyState.selected.libraries, lib => {
1087+
<li className="ml-2" key=lib> {React.string(lib)} </li>
1088+
})->React.array}
1089+
</ul>
1090+
</div>
1091+
<div className="mt-8">
1092+
<div className=titleClass>
1093+
{React.string("Warning Flags")}
1094+
<button onMouseDown=onResetClick className={"ml-6 text-14 " ++ Text.Link.standalone}>
1095+
{React.string("[reset]")}
1096+
</button>
1097+
</div>
1098+
<div className="flex justify-end" />
1099+
<div style={ReactDOM.Style.make(~maxWidth="40rem", ())}>
1100+
<WarningFlagsWidget onUpdate=onWarningFlagsUpdate flags=warnFlagTokens />
10931101
</div>
10941102
</div>
10951103
</div>

src/common/CompilerManagerHook.js

Lines changed: 33 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/CompilerManagerHook.res

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module LoadScript = {
3838
module CdnMeta = {
3939
// Make sure versions exist on https://cdn.rescript-lang.org
4040
// [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"]
4242

4343
let getCompilerUrl = (version: string): string =>
4444
j`https://cdn.rescript-lang.org/$version/compiler.js`
@@ -55,6 +55,31 @@ module FinalResult = {
5555
| Nothing
5656
}
5757

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+
5883
/*
5984
This function loads the compiler, plus a defined set of libraries that are available
6085
on our bs-platform-js-releases channel.
@@ -300,13 +325,14 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
300325
React.useEffect1(() => {
301326
switch state {
302327
| Init =>
303-
let libraries = ["reason-react"]
304-
305328
switch CdnMeta.versions {
306329
| [] => dispatchError(SetupError(j`No compiler versions found`))
307330
| versions =>
308331
let latest = versions[0]
309332

333+
// Latest version is already running on @rescript/react
334+
let libraries = ["@rescript/react"]
335+
310336
attachCompilerAndLibraries(~version=latest, ~libraries, ())
311337
->Promise.map(result =>
312338
switch result {
@@ -347,12 +373,16 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
347373
->ignore
348374
}
349375
| 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 =>
351380
switch result {
352381
| Ok() =>
353382
// Make sure to remove the previous script from the DOM as well
354383
LoadScript.removeScript(~src=CdnMeta.getCompilerUrl(ready.selected.id))
355384

385+
// We are removing the previous libraries, therefore we use ready.selected here
356386
Belt.Array.forEach(ready.selected.libraries, lib =>
357387
LoadScript.removeScript(~src=CdnMeta.getLibraryCmijUrl(ready.selected.id, lib))
358388
)
@@ -368,7 +398,7 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
368398
ocamlVersion: instance->Compiler.ocamlVersion,
369399
reasonVersion: instance->Compiler.reasonVersion,
370400
config: config,
371-
libraries: libraries,
401+
libraries: migratedLibraries,
372402
instance: instance,
373403
}
374404

@@ -384,7 +414,8 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
384414

385415
dispatchError(CompilerLoadingError(msg))
386416
}
387-
)->ignore
417+
)
418+
->ignore
388419
| Compiling(ready, (lang, code)) =>
389420
let apiVersion = ready.selected.apiVersion
390421
let instance = ready.selected.instance

0 commit comments

Comments
 (0)