Skip to content

Commit 670186f

Browse files
Revert "make playground bundle endpoint customizable (#1099)"
This reverts commit b7e5ae1.
1 parent b7e5ae1 commit 670186f

File tree

7 files changed

+32
-78
lines changed

7 files changed

+32
-78
lines changed

src/Playground.res

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ module App = {
14191419
let initialReContent = `Js.log("Hello Reason 3.6!");`
14201420

14211421
@react.component
1422-
let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1422+
let make = (~versions: array<string>) => {
14231423
let router = Next.Router.useRouter()
14241424

14251425
let versions =
@@ -1436,18 +1436,14 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14361436
cmp(b) - cmp(a)
14371437
})
14381438

1439-
let initialVersion = switch versions {
1440-
| [v] => Some(v) // only single version available. maybe local dev.
1441-
| versions => {
1442-
let lastStableVersion = versions->Array.find(version => version.preRelease->Option.isNone)
1443-
switch Dict.get(router.query, "version") {
1444-
| Some(version) => version->Semver.parse
1445-
| None =>
1446-
switch Url.getVersionFromStorage(Playground) {
1447-
| Some(v) => v->Semver.parse
1448-
| None => lastStableVersion
1449-
}
1450-
}
1439+
let lastStableVersion = versions->Array.find(version => version.preRelease->Option.isNone)
1440+
1441+
let initialVersion = switch Dict.get(router.query, "version") {
1442+
| Some(version) => version->Semver.parse
1443+
| None =>
1444+
switch Url.getVersionFromStorage(Playground) {
1445+
| Some(v) => v->Semver.parse
1446+
| None => lastStableVersion
14511447
}
14521448
}
14531449

@@ -1474,7 +1470,6 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14741470
let (actionCount, setActionCount) = React.useState(_ => 0)
14751471
let onAction = _ => setActionCount(prev => prev > 1000000 ? 0 : prev + 1)
14761472
let (compilerState, compilerDispatch) = useCompilerManager(
1477-
~bundleBaseUrl,
14781473
~initialVersion?,
14791474
~initialModuleSystem?,
14801475
~initialLang,

src/Playground.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@react.component
2-
let make: (~bundleBaseUrl: string, ~versions: array<string>) => React.element
2+
let make: (~versions: array<string>) => React.element

src/Try.res

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
type props = {
2-
bundleBaseUrl: string,
3-
versions: array<string>,
4-
}
1+
type props = {versions: array<string>}
52

63
let default = props => {
74
let (isOverlayOpen, setOverlayOpen) = React.useState(() => false)
@@ -22,13 +19,7 @@ let default = props => {
2219
},
2320
)
2421

25-
let playground = React.createElement(
26-
lazyPlayground,
27-
{
28-
bundleBaseUrl: props.bundleBaseUrl,
29-
versions: props.versions,
30-
},
31-
)
22+
let playground = React.createElement(lazyPlayground, {versions: props.versions})
3223

3324
<>
3425
<Meta
@@ -49,36 +40,14 @@ let default = props => {
4940
}
5041

5142
let getStaticProps: Next.GetStaticProps.t<props, _> = async _ => {
52-
let (bundleBaseUrl, versionsBaseUrl) = switch (
53-
Node.Process.Env.playgroundBundleEndpoint,
54-
Node.Process.Env.nodeEnv,
55-
) {
56-
| (Some(baseUrl), _) => (baseUrl, baseUrl)
57-
| (None, "development") => {
58-
// Use remote bundles in dev
59-
let baseUrl = "https://cdn.rescript-lang.org"
60-
(baseUrl, baseUrl)
61-
}
62-
| (None, _) => (
63-
// Use same-origin requests for the bundle
64-
"",
65-
// There is no version endpoint in the build phase
66-
"https://cdn.rescript-lang.org",
67-
)
68-
}
6943
let versions = {
70-
let response = await fetch(versionsBaseUrl + "/playground-bundles/versions.json")
44+
let response = await fetch("https://cdn.rescript-lang.org/playground-bundles/versions.json")
7145
let json = await WebAPI.Response.json(response)
7246
json
7347
->JSON.Decode.array
7448
->Option.getOrThrow
7549
->Array.map(json => json->JSON.Decode.string->Option.getOrThrow)
7650
}
7751

78-
{
79-
"props": {
80-
bundleBaseUrl,
81-
versions,
82-
},
83-
}
52+
{"props": {versions: versions}}
8453
}

src/Try.resi

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
type props = {
2-
bundleBaseUrl: string,
3-
versions: array<string>,
4-
}
1+
type props = {versions: array<string>}
52
let default: props => React.element
63
let getStaticProps: Next.GetStaticProps.t<props, 'a>

src/bindings/Node.res

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ module Process = {
1818
@scope("process") external exit: int => unit = "exit"
1919
module Env = {
2020
@scope(("process", "env")) external nodeEnv: string = "NODE_ENV"
21-
@scope(("process", "env"))
22-
external playgroundBundleEndpoint: option<string> = "PLAYGROUND_BUNDLE_ENDPOINT"
2321
}
2422
}
2523

src/common/CompilerManagerHook.res

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ module LoadScript = {
3535
}
3636

3737
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"
4042

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 =>
4246
`${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js`
4347

44-
let getStdlibRuntimeUrl = (baseUrl, version, filename) =>
48+
let getStdlibRuntimeUrl = (version, filename) =>
4549
`${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}`
4650
}
4751

@@ -100,11 +104,11 @@ let getOpenModules = (~apiVersion: Version.t, ~libraries: array<string>): option
100104
We coupled the compiler / library loading to prevent ppl to try loading compiler / cmij files
101105
separately and cause all kinds of race conditions.
102106
*/
103-
let attachCompilerAndLibraries = async (~baseUrl, ~version, ~libraries: array<string>, ()): result<
107+
let attachCompilerAndLibraries = async (~version, ~libraries: array<string>, ()): result<
104108
unit,
105109
array<string>,
106110
> => {
107-
let compilerUrl = CdnMeta.getCompilerUrl(baseUrl, version)
111+
let compilerUrl = CdnMeta.getCompilerUrl(version)
108112

109113
// Useful for debugging our local build
110114
/* let compilerUrl = "/static/linked-bs-bundle.js"; */
@@ -113,7 +117,7 @@ let attachCompilerAndLibraries = async (~baseUrl, ~version, ~libraries: array<st
113117
| Error(_) => Error([`Could not load compiler from url ${compilerUrl}`])
114118
| Ok(_) =>
115119
let promises = Array.map(libraries, async lib => {
116-
let cmijUrl = CdnMeta.getLibraryCmijUrl(baseUrl, version, lib)
120+
let cmijUrl = CdnMeta.getLibraryCmijUrl(version, lib)
117121
switch await LoadScript.loadScriptPromise(cmijUrl) {
118122
| Error(_) => Error(`Could not load cmij from url ${cmijUrl}`)
119123
| r => r
@@ -218,7 +222,6 @@ let defaultModuleSystem = "esmodule"
218222
// component to give feedback to the user that an action happened (useful in
219223
// cases where the output didn't visually change)
220224
let useCompilerManager = (
221-
~bundleBaseUrl: string,
222225
~initialVersion: option<Semver.t>=?,
223226
~initialModuleSystem=defaultModuleSystem,
224227
~initialLang: Lang.t=Res,
@@ -402,12 +405,7 @@ let useCompilerManager = (
402405
// Latest version is already running on @rescript/react
403406
let libraries = getLibrariesForVersion(~version)
404407

405-
switch await attachCompilerAndLibraries(
406-
~baseUrl=bundleBaseUrl,
407-
~version,
408-
~libraries,
409-
(),
410-
) {
408+
switch await attachCompilerAndLibraries(~version, ~libraries, ()) {
411409
| Ok() =>
412410
let instance = Compiler.make()
413411
let apiVersion = apiVersion->Version.fromString
@@ -462,16 +460,14 @@ let useCompilerManager = (
462460
| SwitchingCompiler(ready, version) =>
463461
let libraries = getLibrariesForVersion(~version)
464462

465-
switch await attachCompilerAndLibraries(~baseUrl=bundleBaseUrl, ~version, ~libraries, ()) {
463+
switch await attachCompilerAndLibraries(~version, ~libraries, ()) {
466464
| Ok() =>
467465
// 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))
469467

470468
// We are removing the previous libraries, therefore we use ready.selected here
471469
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))
475471
)
476472

477473
let instance = Compiler.make()
@@ -580,7 +576,7 @@ let useCompilerManager = (
580576
}
581577
| version => version
582578
}
583-
CdnMeta.getStdlibRuntimeUrl(bundleBaseUrl, compilerVersion, filename)
579+
CdnMeta.getStdlibRuntimeUrl(compilerVersion, filename)
584580
})
585581

586582
entryPointExists

src/common/CompilerManagerHook.resi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type ready = {
3131
}
3232

3333
module CdnMeta: {
34-
let getStdlibRuntimeUrl: (string, Semver.t, string) => string
34+
let getStdlibRuntimeUrl: (Semver.t, string) => string
3535
}
3636

3737
type state =
@@ -53,7 +53,6 @@ type action =
5353
| RunCode
5454

5555
let useCompilerManager: (
56-
~bundleBaseUrl: string,
5756
~initialVersion: Semver.t=?,
5857
~initialModuleSystem: string=?,
5958
~initialLang: Lang.t=?,

0 commit comments

Comments
 (0)