Skip to content

Commit 47aafa1

Browse files
authored
[codex] Split playground into workspace packages (#1278)
* chore: add yarn workspaces * fix: honor workspace resolutions at root * chore: move docs app into workspace * chore: update workspace root tooling * fix: generate docs scripts before index updates * fix: make root build work from clean checkout * fix: resolve docs workspace paths * fix: update repository links for docs workspace * fix: update deployment workflows for docs workspace * fix: update formatter ignores for docs workspace * fix: run docs formatter from repo root * fix: correct users source link * fix: load docs env from workspace root * fix: handle nested public hrefs in docs checks * fix: add root rescript monorepo config * refactor: split playground into workspace packages Move shared editor/compiler helpers into @rescript-lang/shared and the playground implementation into @rescript-lang/playground. Wire the docs app to consume both workspace packages and keep playground browser storage access safe during prerendering.
1 parent a11341c commit 47aafa1

51 files changed

Lines changed: 245 additions & 66 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy-fork-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
workingDirectory: apps/docs
8282
command: pages deploy out --project-name=rescript-lang-org
8383
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
84-
wranglerVersion: 4.61.1
84+
wranglerVersion: 4.85.0
8585
continue-on-error: true
8686
env:
8787
FORCE_COLOR: 0

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
workingDirectory: apps/docs
6565
command: pages deploy out --project-name=rescript-lang-org --branch=${{ env.SAFE_BRANCH }}
6666
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
67-
wranglerVersion: 4.63.0
67+
wranglerVersion: 4.85.0
6868
env:
6969
FORCE_COLOR: 0
7070
- name: Comment PR with deployment link

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ apps/docs/temp-jsx-preserve
2525
.merlin
2626
lib/
2727
apps/docs/lib/
28+
packages/*/lib/
2829

2930
.vercel
3031

3132
apps/docs/src/**/*.mjs
3233
apps/docs/src/**/*.jsx
34+
packages/*/src/**/*.mjs
35+
packages/*/src/**/*.jsx
3336
apps/docs/scripts/gendocs.mjs
3437
apps/docs/scripts/generate_*.mjs
3538
apps/docs/scripts/gendocs.jsx

apps/docs/__tests__/BlogArticle_.test.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ let mockFrontmatterWithArticleImg: BlogFrontmatter.t = {
141141
co_authors: [],
142142
date: DateStr.fromString("2025-06-01"),
143143
previewImg: Nullable.null,
144-
articleImg: Nullable.Value("https://rescript-lang.org/brand/rescript-brandmark.svg"),
144+
articleImg: Nullable.Value("/brand/rescript-brandmark.svg"),
145145
title: "Blog Post With Article Image",
146146
badge: Nullable.Value(Release),
147147
description: Nullable.Value("A post with an article image."),
@@ -166,6 +166,7 @@ test("desktop blog article with article image shows image", async () => {
166166
await element(title)->toBeVisible
167167

168168
let wrapper = await screen->getByTestId("blog-article-wrapper")
169+
await waitForImages("[data-testid='blog-article-wrapper']")
169170
await element(wrapper)->toMatchScreenshot("desktop-blog-article-with-image")
170171
})
171172

apps/docs/__tests__/LandingPage_.test.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ let snapshotSection = async (~width, ~height, ~sectionTestId, ~screenshotName) =
4848

4949
let snapshotTarget = await snapshotScreen->getByTestId(sandboxTestId)
5050
await element(snapshotTarget)->toBeVisible
51+
await waitForImages(`[data-testid="${sandboxTestId}"]`)
5152
await element(snapshotTarget)->toMatchScreenshot(screenshotName)
5253
await snapshotScreen->unmount
5354
}

apps/docs/__tests__/MarkdownComponents_.test.res

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ test("renders Image with caption", async () => {
204204
<div dataTestId="image-wrapper">
205205
<Markdown.Image
206206
className="rounded-lg border border-gray-90/5 text-gray-60"
207-
src="https://rescript-lang.org/lp/community-3.avif"
207+
src="/lp/community-3.avif"
208208
caption="A sample image caption"
209209
/>
210210
</div>,
@@ -214,6 +214,7 @@ test("renders Image with caption", async () => {
214214
await element(caption)->toBeVisible
215215

216216
let wrapper = await screen->getByTestId("image-wrapper")
217+
await waitForImages("[data-testid='image-wrapper']")
217218
await element(wrapper)->toMatchScreenshot("markdown-image")
218219
})
219220

apps/docs/package.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,21 @@
3333
"vitest:update": "vitest --run --browser.headless --update"
3434
},
3535
"dependencies": {
36-
"@babel/generator": "^7.29.1",
37-
"@babel/parser": "^7.29.2",
38-
"@babel/traverse": "^7.29.0",
3936
"@cloudflare/pages-plugin-vercel-og": "^0.1.2",
40-
"@codemirror/commands": "^6.10.3",
41-
"@codemirror/lang-javascript": "^6.2.5",
42-
"@codemirror/language": "^6.12.3",
43-
"@codemirror/lint": "^6.9.5",
44-
"@codemirror/search": "^6.6.0",
45-
"@codemirror/state": "^6.6.0",
46-
"@codemirror/view": "^6.41.0",
4737
"@docsearch/react": "^4.6.2",
4838
"@headlessui/react": "^2.2.9",
49-
"@lezer/highlight": "^1.2.3",
5039
"@mdx-js/mdx": "^3.1.1",
5140
"@node-cli/static-server": "^3.1.10",
5241
"@react-router/node": "^7.14.0",
53-
"@replit/codemirror-vim": "^6.3.0",
42+
"@rescript-lang/playground": "workspace:*",
43+
"@rescript-lang/shared": "workspace:*",
5444
"@rescript/react": "^0.14.2",
5545
"@rescript/webapi": "0.1.0-experimental-29db5f4",
56-
"@tsnobip/rescript-lezer": "^0.8.0",
5746
"docson": "^2.1.0",
5847
"fuse.js": "^6.6.2",
5948
"highlight.js": "^11.11.1",
6049
"highlightjs-rescript": "^0.2.2",
6150
"isbot": "^5.1.37",
62-
"lz-string": "^1.5.0",
6351
"mdast-util-from-markdown": "^2.0.3",
6452
"mdast-util-to-string": "^4.0.0",
6553
"mdast-util-toc": "^7.1.0",

apps/docs/rescript.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"name": "@rescript-lang/docs",
33
"namespace": false,
4-
"dependencies": ["@rescript/react", "@rescript/webapi"],
4+
"dependencies": [
5+
"@rescript-lang/shared",
6+
"@rescript-lang/playground",
7+
"@rescript/react",
8+
"@rescript/webapi"
9+
],
510
"compiler-flags": ["-open WebAPI.Global"],
611
"sources": [
712
{

apps/docs/src/bindings/Vitest.res

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ external getAllByLabelText: (element, string) => promise<array<element>> = "getA
5656
@send
5757
external getByRole: (element, [#button]) => promise<element> = "getByRole"
5858

59+
external imageFromNode: WebAPI.DOMAPI.node => WebAPI.DOMAPI.htmlImageElement = "%identity"
60+
61+
let waitForImages = async (selector: string) => {
62+
let root = switch document->WebAPI.Document.querySelector(selector) {
63+
| Value(root) => root
64+
| Null => failwith(`expected to find screenshot target ${selector}`)
65+
}
66+
67+
let images = root->WebAPI.Element.querySelectorAll("img")
68+
69+
if images.length > 0 {
70+
for i in 0 to images.length - 1 {
71+
let image = images->WebAPI.NodeList.item(i)->imageFromNode
72+
await image->WebAPI.HTMLImageElement.decode
73+
}
74+
}
75+
}
76+
5977
/**
6078
* Actions
6179
*/

apps/docs/vitest.config.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@ import { playwright } from "@vitest/browser-playwright";
33
import react from "@vitejs/plugin-react";
44
import tailwindcss from "@tailwindcss/vite";
55

6+
const setupDeps = [
7+
"highlight.js/lib/core",
8+
"highlight.js/lib/languages/bash",
9+
"highlight.js/lib/languages/css",
10+
"highlight.js/lib/languages/diff",
11+
"highlight.js/lib/languages/ini",
12+
"highlight.js/lib/languages/javascript",
13+
"highlight.js/lib/languages/json",
14+
"highlight.js/lib/languages/plaintext",
15+
"highlight.js/lib/languages/typescript",
16+
"highlight.js/lib/languages/xml",
17+
"highlightjs-rescript",
18+
];
19+
620
export default defineConfig({
721
envDir: "../..",
822
plugins: [react(), tailwindcss()],
23+
optimizeDeps: {
24+
include: setupDeps,
25+
},
926
test: {
1027
include: ["__tests__/*.jsx"],
1128
setupFiles: ["./vitest.setup.mjs"],

0 commit comments

Comments
 (0)