Skip to content

Commit 07363d5

Browse files
Developer playground (#8435)
* Developer playground * Deploy developer playground on rescript-lang.github.io * Reuse existing compiler build step * Changelog * Format * review * Simplify dev playground api * CompilerApi in .res * One less helper * More cleanup * Let Unwrap and nullable cleanup * Format button * Format * Siplify jsoo part * Review * Simplify jsoo once more * Remove doc * Bindings * Look ma, no raw * Manual cleanup * Resi * Codex cant let? * Shadow fix * Simplify UrlState api * Common signal for config * Extract SourceHighlight module * Load cmijs only after api global is captured
1 parent 0a29fc8 commit 07363d5

24 files changed

Lines changed: 3750 additions & 8 deletions

.github/workflows/ci.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,18 @@ jobs:
382382
if: matrix.build_playground
383383
run: yarn workspace playground test
384384

385+
- name: Stage dev playground compiler bundle
386+
if: ${{ matrix.build_playground && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
387+
run: yarn workspace dev-playground stage-master-bundle
388+
389+
- name: "Upload artifacts: dev playground compiler bundle"
390+
if: ${{ matrix.build_playground && github.event_name == 'push' && github.ref == 'refs/heads/master' }}
391+
uses: actions/upload-artifact@v7
392+
with:
393+
name: dev-playground-master-bundle
394+
path: packages/dev-playground/public/playground-bundles/master
395+
if-no-files-found: error
396+
385397
- name: Setup Rclone
386398
if: ${{ matrix.build_playground && startsWith(github.ref, 'refs/tags/v') }}
387399
uses: cometkim/rclone-actions/setup-rclone@main
@@ -430,6 +442,62 @@ jobs:
430442
name: api
431443
path: scripts/res/apiDocs/
432444

445+
dev-playground:
446+
needs:
447+
- build-compiler
448+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
449+
runs-on: ubuntu-24.04
450+
permissions:
451+
contents: read
452+
pages: write
453+
id-token: write
454+
environment:
455+
name: github-pages
456+
url: ${{ steps.deployment.outputs.page_url }}dev-playground/
457+
env:
458+
VITE_DEFAULT_COMPILER_VERSION: master
459+
VITE_COMPILER_VERSIONS: '[{"id":"master","label":"master"}]'
460+
GITHUB_PAGES_PATH: dev-playground
461+
PLAYGROUND_BUNDLE_ID: master
462+
steps:
463+
- name: Checkout
464+
uses: actions/checkout@v6
465+
466+
- name: Use Node.js
467+
uses: actions/setup-node@v6
468+
with:
469+
cache: yarn
470+
node-version-file: .nvmrc
471+
472+
- name: Install npm packages
473+
run: yarn install
474+
475+
- name: Download dev playground compiler bundle
476+
uses: actions/download-artifact@v8
477+
with:
478+
name: dev-playground-master-bundle
479+
path: packages/dev-playground/public/playground-bundles/master
480+
481+
- name: Configure GitHub Pages
482+
id: pages
483+
uses: actions/configure-pages@v6
484+
485+
- name: Build dev playground Pages site
486+
env:
487+
VITE_BASE: ${{ steps.pages.outputs.base_path }}/dev-playground/
488+
run: |
489+
yarn workspace dev-playground build
490+
yarn workspace dev-playground prepare-pages-site
491+
492+
- name: Upload GitHub Pages artifact
493+
uses: actions/upload-pages-artifact@v5
494+
with:
495+
path: packages/dev-playground/pages-site
496+
497+
- name: Deploy to GitHub Pages
498+
id: deployment
499+
uses: actions/deploy-pages@v5
500+
433501
pkg-pr-new:
434502
needs:
435503
- build-compiler

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ playground/*.cmj
7272
playground/*.cmi
7373
playground/.netrc
7474
playground/compiler.*js
75+
packages/dev-playground/dist/
76+
packages/dev-playground/pages-site/
77+
packages/dev-playground/lib/
78+
packages/dev-playground/src/*.res.mjs
79+
packages/dev-playground/public/playground-bundles/*
80+
!packages/dev-playground/public/playground-bundles/.gitignore
7581

7682
rewatch/target/
7783
rewatch/rewatch

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#### :house: Internal
4848

4949
- Remove `Primitive_option.toUndefined`; use `valFromOption` for optional ffi args. https://github.com/rescript-lang/rescript/pull/8380
50+
- Add a developer playground for testing the current compiler bundle locally and deploy the latest `master` build to GitHub Pages. https://github.com/rescript-lang/rescript/pull/8435
5051
- Expand `super_errors` fixture coverage for warnings and errors. https://github.com/rescript-lang/rescript/pull/8429
5152
- Run `super_errors` fixtures in parallel (~2.4× faster locally). https://github.com/rescript-lang/rescript/pull/8430
5253
- Expand `super_errors` fixture coverage for the remaining reachable single-file error variants. https://github.com/rescript-lang/rescript/pull/8432

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ $(PLAYGROUND_CMI_BUILD_STAMP): $(RUNTIME_BUILD_STAMP)
204204
playground-test: playground
205205
yarn workspace playground test
206206

207+
dev-playground-stage: playground
208+
yarn workspace dev-playground stage-local-bundle
209+
210+
dev-playground: dev-playground-stage
211+
yarn workspace dev-playground dev
212+
213+
dev-playground-build: dev-playground-stage
214+
yarn workspace dev-playground build
215+
207216
# Builds the playground, runs some e2e tests and releases the playground to the
208217
# Cloudflare R2 (requires Rclone `rescript:` remote)
209218
playground-release: playground-test

compiler/jsoo/jsoo_playground_main.ml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@
5151
* modules in the playground.
5252
* v5: Removed .ml support.
5353
* v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig.
54+
* v7: Added debug dump output APIs for developer playground tooling.
5455
* *)
55-
let api_version = "6"
56+
let api_version = "7"
5657

5758
module Js = Js_of_ocaml.Js
5859

@@ -298,6 +299,8 @@ let rescript_parse ~filename src =
298299
structure
299300

300301
module Printer = struct
302+
let to_string printer value = Format.asprintf "%a@." printer value
303+
301304
let print_expr typ =
302305
Printtyp.reset_names ();
303306
Printtyp.reset_and_mark_loops typ;
@@ -472,7 +475,8 @@ module Compile = struct
472475
List.iter Iter.iter_structure_item structure.str_items;
473476
Js.array (!acc |> Array.of_list)
474477

475-
let implementation ~(config : BundleConfig.t) ~lang str =
478+
let implementation ?(include_debug_outputs = false) ~(config : BundleConfig.t)
479+
~lang str =
476480
let {
477481
BundleConfig.module_system;
478482
warn_flags;
@@ -525,8 +529,8 @@ module Compile = struct
525529
in
526530
let v = Buffer.contents buffer in
527531
let type_hints = collect_type_hints typed_tree in
528-
Js.Unsafe.(
529-
obj
532+
let attrs =
533+
Js.Unsafe.
530534
[|
531535
("js_code", inject @@ Js.string v);
532536
( "warnings",
@@ -536,7 +540,28 @@ module Compile = struct
536540
|> Js.array |> inject) );
537541
("type_hints", inject @@ type_hints);
538542
("type", inject @@ Js.string "success");
539-
|])
543+
|]
544+
in
545+
if include_debug_outputs then
546+
let export_ident_sets = Set_ident.of_list exports in
547+
let parsetree = Printer.to_string Printast.implementation ast in
548+
let typedtree =
549+
Printer.to_string Printtyped.implementation_with_coercion typed_tree
550+
in
551+
let lambda = Printer.to_string Printlambda.lambda lam in
552+
let lam, _ = Lam_convert.convert export_ident_sets lam in
553+
let lam = Lam_print.lambda_to_string lam in
554+
let debug_attrs =
555+
Js.Unsafe.
556+
[|
557+
("parsetree", inject @@ Js.string parsetree);
558+
("typedtree", inject @@ Js.string typedtree);
559+
("lambda", inject @@ Js.string lambda);
560+
("lam", inject @@ Js.string lam);
561+
|]
562+
in
563+
Js.Unsafe.obj (Array.append attrs debug_attrs)
564+
else Js.Unsafe.obj attrs
540565
with e -> (
541566
match e with
542567
| Arg.Bad msg -> ErrorRet.make_warning_flag_error ~warn_flags msg
@@ -582,6 +607,11 @@ module Export = struct
582607
inject
583608
@@ Js.wrap_meth_callback (fun _ code ->
584609
Compile.implementation ~config ~lang (Js.to_string code)) );
610+
( "compileWithDebug",
611+
inject
612+
@@ Js.wrap_meth_callback (fun _ code ->
613+
Compile.implementation ~include_debug_outputs:true ~config
614+
~lang (Js.to_string code)) );
585615
("version", inject @@ Js.string Bs_version.version);
586616
|]
587617
in

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"typescript": "6.0.3"
9898
},
9999
"workspaces": [
100+
"packages/dev-playground",
100101
"packages/playground",
101102
"packages/@rescript/*",
102103
"tests/dependencies/**",

packages/dev-playground/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>ReScript Developer Playground</title>
7+
<link rel="stylesheet" href="/src/styles.css" />
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/Main.res.mjs"></script>
12+
</body>
13+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"private": true,
3+
"name": "dev-playground",
4+
"version": "0.1.0",
5+
"type": "module",
6+
"scripts": {
7+
"stage-local-bundle": "node scripts/stage-local-bundle.mjs",
8+
"stage-master-bundle": "node scripts/stage-local-bundle.mjs master --clear-other-bundles",
9+
"prepare-pages-site": "node scripts/prepare-pages-site.mjs",
10+
"res:build": "rescript",
11+
"res:watch": "rescript -w",
12+
"dev": "vite --host 127.0.0.1",
13+
"build": "rescript && vite build",
14+
"preview": "vite preview --host 127.0.0.1"
15+
},
16+
"dependencies": {
17+
"@rescript/runtime": "12.3.0",
18+
"rescript": "12.3.0",
19+
"vite": "^7.3.2",
20+
"xote": "6.1.1"
21+
}
22+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "dev-playground",
3+
"sources": [
4+
{
5+
"dir": "src",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": {
10+
"module": "esmodule",
11+
"in-source": true
12+
},
13+
"suffix": ".res.mjs",
14+
"dependencies": ["xote"],
15+
"jsx": {
16+
"version": 4,
17+
"module": "XoteJSX"
18+
},
19+
"experimental-features": {
20+
"LetUnwrap": true
21+
},
22+
"compiler-flags": ["-open Xote", "-open Bindings"],
23+
"warnings": {
24+
"error": "+8"
25+
}
26+
}

0 commit comments

Comments
 (0)