Skip to content

Commit 992bb05

Browse files
Format
1 parent 4572ca7 commit 992bb05

7 files changed

Lines changed: 114 additions & 87 deletions

File tree

packages/dev-playground/scripts/prepare-pages-site.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ await assertExists(
2424
"Missing dev playground build. Run `yarn workspace dev-playground build` first",
2525
);
2626

27-
await fs.rm(siteDir, {recursive: true, force: true});
28-
await fs.mkdir(targetDir, {recursive: true});
29-
await fs.cp(distDir, targetDir, {recursive: true});
27+
await fs.rm(siteDir, { recursive: true, force: true });
28+
await fs.mkdir(targetDir, { recursive: true });
29+
await fs.cp(distDir, targetDir, { recursive: true });
3030

3131
const catalog = {
3232
generatedAt: new Date().toISOString(),

packages/dev-playground/scripts/stage-local-bundle.mjs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,8 @@ const sourcePackages = path.join(playgroundDir, "packages");
1111
const args = process.argv.slice(2);
1212
const bundleId = args.find(arg => !arg.startsWith("--")) ?? "local";
1313
const clearOtherBundles = args.includes("--clear-other-bundles");
14-
const bundlesRoot = path.join(
15-
devPlaygroundDir,
16-
"public",
17-
"playground-bundles",
18-
);
19-
const targetRoot = path.join(
20-
bundlesRoot,
21-
bundleId,
22-
);
14+
const bundlesRoot = path.join(devPlaygroundDir, "public", "playground-bundles");
15+
const targetRoot = path.join(bundlesRoot, bundleId);
2316

2417
async function assertExists(filePath, message) {
2518
try {
@@ -41,14 +34,17 @@ await assertExists(
4134
if (clearOtherBundles) {
4235
for (const entry of await fs.readdir(bundlesRoot)) {
4336
if (entry !== ".gitignore") {
44-
await fs.rm(path.join(bundlesRoot, entry), {recursive: true, force: true});
37+
await fs.rm(path.join(bundlesRoot, entry), {
38+
recursive: true,
39+
force: true,
40+
});
4541
}
4642
}
4743
}
4844

49-
await fs.rm(targetRoot, {recursive: true, force: true});
50-
await fs.mkdir(targetRoot, {recursive: true});
45+
await fs.rm(targetRoot, { recursive: true, force: true });
46+
await fs.mkdir(targetRoot, { recursive: true });
5147
await fs.copyFile(sourceCompiler, path.join(targetRoot, "compiler.js"));
52-
await fs.cp(sourcePackages, targetRoot, {recursive: true});
48+
await fs.cp(sourcePackages, targetRoot, { recursive: true });
5349

5450
console.log(`Staged ${bundleId} playground bundle at ${targetRoot}`);

packages/dev-playground/src/CompilerRuntime.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ function parseCompilerVersions(defaultVersion) {
1616
Array.isArray(versions) &&
1717
versions.every(
1818
version =>
19-
typeof version?.id === "string" &&
20-
typeof version?.label === "string",
19+
typeof version?.id === "string" && typeof version?.label === "string",
2120
)
2221
) {
2322
return versions;
@@ -129,8 +128,12 @@ function errorToText(item) {
129128
}
130129

131130
function normalizeFailure(result, elapsedMs) {
132-
const errors = Array.isArray(result?.errors) ? result.errors.map(errorToText) : [];
133-
const warnings = Array.isArray(result?.warnings) ? result.warnings.map(warningToText) : [];
131+
const errors = Array.isArray(result?.errors)
132+
? result.errors.map(errorToText)
133+
: [];
134+
const warnings = Array.isArray(result?.warnings)
135+
? result.warnings.map(warningToText)
136+
: [];
134137
const message =
135138
result?.msg ??
136139
result?.shortMsg ??
@@ -165,7 +168,9 @@ function normalizeSuccess(result, elapsedMs) {
165168
lambda: result?.lambda ?? fallback,
166169
lam: result?.lam ?? fallback,
167170
errors: [],
168-
warnings: Array.isArray(result?.warnings) ? result.warnings.map(warningToText) : [],
171+
warnings: Array.isArray(result?.warnings)
172+
? result.warnings.map(warningToText)
173+
: [],
169174
message: "Compiled successfully",
170175
time: elapsedMs,
171176
};
@@ -205,7 +210,9 @@ async function ensureCompilerApi(version) {
205210

206211
const api = globalThis.rescript_compiler;
207212
if (api == null || typeof api.make !== "function") {
208-
throw new Error("rescript_compiler global was not registered by compiler.js");
213+
throw new Error(
214+
"rescript_compiler global was not registered by compiler.js",
215+
);
209216
}
210217

211218
compilerApis.set(selectedVersion, api);
@@ -245,7 +252,9 @@ export async function init(version) {
245252
warnFlags: config.warnFlags,
246253
jsxPreserveMode: config.jsxPreserveMode,
247254
experimentalFeatures: config.experimentalFeatures,
248-
libraries: loadedLibrariesByVersion.get(selectedVersion) ?? ["compiler-builtins"],
255+
libraries: loadedLibrariesByVersion.get(selectedVersion) ?? [
256+
"compiler-builtins",
257+
],
249258
};
250259
}
251260

@@ -257,11 +266,11 @@ export async function compile(source, config) {
257266
const start = performance.now();
258267
const result = hasFunction(instance.rescript, "compileWithDebug")
259268
? instance.rescript.compileWithDebug(source, [
260-
"parsetree",
261-
"typedtree",
262-
"lambda",
263-
"lam",
264-
])
269+
"parsetree",
270+
"typedtree",
271+
"lambda",
272+
"lam",
273+
])
265274
: instance.rescript.compile(source);
266275
const elapsedMs = performance.now() - start;
267276

packages/dev-playground/src/Main.res

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,7 @@ module TabButton = {
446446
@jsx.component
447447
let make = (~tab, ~activeTab: Signal.t<tab>, ~onSelect: tab => unit) => {
448448
<button
449-
class={() =>
450-
Signal.get(activeTab) === tab
451-
? "tab-button tab-button-active"
452-
: "tab-button"}
449+
class={() => Signal.get(activeTab) === tab ? "tab-button tab-button-active" : "tab-button"}
453450
onClick={_ => onSelect(tab)}
454451
>
455452
{Node.text(tabLabel(tab))}
@@ -493,12 +490,12 @@ module SettingsPanel = {
493490
) => {
494491
<div
495492
class={() =>
496-
Signal.get(activeTab) === Settings
497-
? "settings-panel"
498-
: "settings-panel hidden-panel"}
493+
Signal.get(activeTab) === Settings ? "settings-panel" : "settings-panel hidden-panel"}
499494
>
500495
<section class="settings-section">
501-
<label class="setting-label" for_="compiler-version"> {Node.text("Compiler Version")} </label>
496+
<label class="setting-label" for_="compiler-version">
497+
{Node.text("Compiler Version")}
498+
</label>
502499
<select
503500
id="compiler-version"
504501
value={ReactiveProp.reactive(compilerVersion)}
@@ -508,9 +505,11 @@ module SettingsPanel = {
508505
switchCompiler(nextVersion)
509506
}}
510507
>
511-
{Node.fragment(CompilerApi.availableCompilerVersions->Array.map(version =>
512-
<option value=version.id> {Node.text(version.label)} </option>
513-
))}
508+
{Node.fragment(
509+
CompilerApi.availableCompilerVersions->Array.map(version =>
510+
<option value=version.id> {Node.text(version.label)} </option>
511+
),
512+
)}
514513
</select>
515514
</section>
516515
<section class="settings-section">
@@ -628,11 +627,12 @@ module App = {
628627
@jsx.component
629628
let make = () => {
630629
let requestedCompilerVersion = UrlState.queryCompilerVersion(CompilerApi.defaultCompilerVersion)
631-
let initialCompilerVersion = CompilerApi.availableCompilerVersions->Array.some(version =>
632-
version.id === requestedCompilerVersion
633-
)
634-
? requestedCompilerVersion
635-
: CompilerApi.defaultCompilerVersion
630+
let initialCompilerVersion =
631+
CompilerApi.availableCompilerVersions->Array.some(version =>
632+
version.id === requestedCompilerVersion
633+
)
634+
? requestedCompilerVersion
635+
: CompilerApi.defaultCompilerVersion
636636
let initialModuleSystem = UrlState.queryModuleSystem("esmodule")
637637
let initialWarnFlags = UrlState.queryWarnFlags(CompilerApi.defaultWarnFlags)
638638
let initialJsxPreserveMode = UrlState.queryJsxPreserveMode(false)
@@ -662,7 +662,10 @@ module App = {
662662

663663
let syncEditorState = event => {
664664
let currentSource = Browser.eventValue(event)
665-
let cursorPosition = cursorPositionForOffset(currentSource, Browser.eventSelectionStart(event))
665+
let cursorPosition = cursorPositionForOffset(
666+
currentSource,
667+
Browser.eventSelectionStart(event),
668+
)
666669
Signal.set(editorScrollTop, Browser.eventScrollTop(event))
667670
Signal.set(editorScrollLeft, Browser.eventScrollLeft(event))
668671
Signal.set(activeLine, cursorPosition.line)
@@ -776,7 +779,10 @@ module App = {
776779
Signal.set(compilerVersion, info.bundleId)
777780
Signal.set(moduleSystem, useInitialSettings ? initialModuleSystem : info.moduleSystem)
778781
Signal.set(warnFlags, useInitialSettings ? initialWarnFlags : info.warnFlags)
779-
Signal.set(jsxPreserveMode, useInitialSettings ? initialJsxPreserveMode : info.jsxPreserveMode)
782+
Signal.set(
783+
jsxPreserveMode,
784+
useInitialSettings ? initialJsxPreserveMode : info.jsxPreserveMode,
785+
)
780786
Signal.set(
781787
experimentalFeatures,
782788
useInitialSettings ? initialExperimentalFeatures : info.experimentalFeatures,
@@ -889,29 +895,30 @@ module App = {
889895
scheduleUrlSync()
890896
scheduleCompile()
891897
| None => ()
892-
}
893-
}
898+
}}
894899
/>
895900
</div>
896901
</div>
897902
<div class="result-column">
898903
<div class="tabs">
899-
{Node.fragment(tabs->Array.map(tab =>
900-
<TabButton tab activeTab onSelect={tab => Signal.set(activeTab, tab)} />
901-
))}
904+
{Node.fragment(
905+
tabs->Array.map(tab =>
906+
<TabButton tab activeTab onSelect={tab => Signal.set(activeTab, tab)} />
907+
),
908+
)}
902909
</div>
903910
<div
904911
class={() =>
905-
Signal.get(activeTab) === Settings
906-
? "output-panel hidden-panel"
907-
: "output-panel"}
912+
Signal.get(activeTab) === Settings ? "output-panel hidden-panel" : "output-panel"}
908913
>
909914
<div class="result-meta">
910915
{Node.signalText(() => resultSummary(Signal.get(compileResult)))}
911916
</div>
912917
<div class="output-shell">
913918
<pre class="output">
914-
{Node.signalText(() => selectedOutput(Signal.get(compileResult), Signal.get(activeTab)))}
919+
{Node.signalText(() =>
920+
selectedOutput(Signal.get(compileResult), Signal.get(activeTab))
921+
)}
915922
</pre>
916923
</div>
917924
<Problems compileResult />

packages/dev-playground/src/UrlState.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const maxDecodedSourceLength = 200 * 1024;
55
let replaceSequence = 0;
66

77
function supportsCompression() {
8-
return typeof CompressionStream !== "undefined" && typeof DecompressionStream !== "undefined";
8+
return (
9+
typeof CompressionStream !== "undefined" &&
10+
typeof DecompressionStream !== "undefined"
11+
);
912
}
1013

1114
function normalizeModuleSystem(value, fallback) {
@@ -25,7 +28,10 @@ function bytesToBase64Url(bytes) {
2528
const chunk = bytes.subarray(index, index + chunkSize);
2629
binary += String.fromCharCode(...chunk);
2730
}
28-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
31+
return btoa(binary)
32+
.replace(/\+/g, "-")
33+
.replace(/\//g, "_")
34+
.replace(/=+$/g, "");
2935
}
3036

3137
function base64UrlToBytes(value) {
@@ -40,12 +46,16 @@ function base64UrlToBytes(value) {
4046
}
4147

4248
async function gzip(bytes) {
43-
const stream = new Blob([bytes]).stream().pipeThrough(new CompressionStream("gzip"));
49+
const stream = new Blob([bytes])
50+
.stream()
51+
.pipeThrough(new CompressionStream("gzip"));
4452
return new Uint8Array(await new Response(stream).arrayBuffer());
4553
}
4654

4755
async function gunzip(bytes) {
48-
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"));
56+
const stream = new Blob([bytes])
57+
.stream()
58+
.pipeThrough(new DecompressionStream("gzip"));
4959
return new Uint8Array(await new Response(stream).arrayBuffer());
5060
}
5161

@@ -140,7 +150,11 @@ async function copyText(value) {
140150

141151
export async function initialSource(defaultSource) {
142152
const encoded = currentParams().get("code");
143-
if (encoded == null || encoded === "" || encoded.length > maxEncodedCodeLength) {
153+
if (
154+
encoded == null ||
155+
encoded === "" ||
156+
encoded.length > maxEncodedCodeLength
157+
) {
144158
return defaultSource;
145159
}
146160

@@ -157,7 +171,10 @@ export function queryCompilerVersion(defaultVersion) {
157171
}
158172

159173
export function queryModuleSystem(defaultModuleSystem) {
160-
return normalizeModuleSystem(currentParams().get("module"), defaultModuleSystem);
174+
return normalizeModuleSystem(
175+
currentParams().get("module"),
176+
defaultModuleSystem,
177+
);
161178
}
162179

163180
export function queryWarnFlags(defaultWarnFlags) {

packages/dev-playground/src/UrlState.res

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,11 @@
33
@module("./UrlState.js") external queryModuleSystem: string => string = "queryModuleSystem"
44
@module("./UrlState.js") external queryWarnFlags: string => string = "queryWarnFlags"
55
@module("./UrlState.js") external queryJsxPreserveMode: bool => bool = "queryJsxPreserveMode"
6-
@module("./UrlState.js") external queryExperimentalFeatures: unit => array<string> = "queryExperimentalFeatures"
76
@module("./UrlState.js")
8-
external replaceUrlState: (
9-
string,
10-
string,
11-
string,
12-
string,
13-
bool,
14-
array<string>,
15-
) => promise<unit> = "replaceUrlState"
7+
external queryExperimentalFeatures: unit => array<string> = "queryExperimentalFeatures"
168
@module("./UrlState.js")
17-
external copyUrlState: (
18-
string,
19-
string,
20-
string,
21-
string,
22-
bool,
23-
array<string>,
24-
) => promise<string> = "copyUrlState"
9+
external replaceUrlState: (string, string, string, string, bool, array<string>) => promise<unit> =
10+
"replaceUrlState"
11+
@module("./UrlState.js")
12+
external copyUrlState: (string, string, string, string, bool, array<string>) => promise<string> =
13+
"copyUrlState"

0 commit comments

Comments
 (0)