Skip to content

Commit 572632d

Browse files
authored
Merge pull request rescript-lang#143 from reason-association/prepare-playground-842
Prepare Playground for 8.4 bundle
2 parents 68efeab + d3b0d09 commit 572632d

File tree

2 files changed

+104
-139
lines changed

2 files changed

+104
-139
lines changed

common/CompilerManagerHook.js

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

common/CompilerManagerHook.res

Lines changed: 41 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ module LoadScript = {
3636
}
3737

3838
module CdnMeta = {
39-
// Splits and sanitizes the content of the VERSIONS file
40-
let parseVersions = (versions: string) =>
41-
Js.String2.split(versions, "\n")->Js.Array2.filter(v => v !== "")
39+
// Make sure versions exist on https://cdn.rescript-lang.org
40+
// [0] = latest
41+
let versions = ["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`
@@ -291,67 +291,48 @@ let useCompilerManager = (~initialLang: Lang.t=Res, ~onAction: option<action =>
291291
| Init =>
292292
let libraries = ["reason-react"]
293293

294-
let completed = res => {
295-
open SimpleRequest
296-
switch res {
297-
| Ok({text}) =>
298-
switch CdnMeta.parseVersions(text) {
299-
| [] => dispatchError(SetupError(j`No compiler versions found`))
300-
| versions =>
301-
// Fetching the initial compiler is different, since we
302-
// don't have any running version downloaded yet
294+
switch CdnMeta.versions {
295+
| [] => dispatchError(SetupError(j`No compiler versions found`))
296+
| versions =>
297+
let latest = versions[0]
303298

304-
let latest = versions[0]
305-
306-
attachCompilerAndLibraries(~version=latest, ~libraries, ())->Promise.get(result =>
307-
switch result {
308-
| Ok() =>
309-
let instance = Compiler.make()
310-
let apiVersion = apiVersion->Version.fromString
311-
let config = instance->Compiler.getConfig
312-
313-
let selected = {
314-
id: latest,
315-
apiVersion: apiVersion,
316-
compilerVersion: instance->Compiler.version,
317-
ocamlVersion: instance->Compiler.ocamlVersion,
318-
reasonVersion: instance->Compiler.reasonVersion,
319-
config: config,
320-
libraries: libraries,
321-
instance: instance,
322-
}
299+
attachCompilerAndLibraries(~version=latest, ~libraries, ())->Promise.get(result =>
300+
switch result {
301+
| Ok() =>
302+
let instance = Compiler.make()
303+
let apiVersion = apiVersion->Version.fromString
304+
let config = instance->Compiler.getConfig
305+
306+
let selected = {
307+
id: latest,
308+
apiVersion: apiVersion,
309+
compilerVersion: instance->Compiler.version,
310+
ocamlVersion: instance->Compiler.ocamlVersion,
311+
reasonVersion: instance->Compiler.reasonVersion,
312+
config: config,
313+
libraries: libraries,
314+
instance: instance,
315+
}
323316

324-
let targetLang =
325-
Version.availableLanguages(apiVersion)
326-
->Js.Array2.find(l => l === initialLang)
327-
->Belt.Option.getWithDefault(Version.defaultTargetLang(apiVersion))
328-
329-
setState(_ => Ready({
330-
selected: selected,
331-
targetLang: targetLang,
332-
versions: versions,
333-
errors: [],
334-
result: FinalResult.Nothing,
335-
}))
336-
| Error(errs) =>
337-
let msg = Js.Array2.joinWith(errs, "; ")
338-
339-
dispatchError(CompilerLoadingError(msg))
340-
}
341-
)
317+
let targetLang =
318+
Version.availableLanguages(apiVersion)
319+
->Js.Array2.find(l => l === initialLang)
320+
->Belt.Option.getWithDefault(Version.defaultTargetLang(apiVersion))
321+
322+
setState(_ => Ready({
323+
selected: selected,
324+
targetLang: targetLang,
325+
versions: versions,
326+
errors: [],
327+
result: FinalResult.Nothing,
328+
}))
329+
| Error(errs) =>
330+
let msg = Js.Array2.joinWith(errs, "; ")
331+
332+
dispatchError(CompilerLoadingError(msg))
342333
}
343-
| Error({text, status}) =>
344-
dispatchError(SetupError(j`Error occurred: $text (status-code: $status)`))
345-
}
346-
()
334+
)
347335
}
348-
349-
open SimpleRequest
350-
make(
351-
~contentType=Plain,
352-
~completed,
353-
"https://cdn.rescript-lang.org/VERSIONS",
354-
)->send
355336
| SwitchingCompiler(ready, version, libraries) =>
356337
attachCompilerAndLibraries(~version, ~libraries, ())->Promise.get(result =>
357338
switch result {

0 commit comments

Comments
 (0)