Skip to content

Commit ef40d25

Browse files
authored
Merge pull request #11 from ryansolid/claude/project-thread-axchtp
@reactivescript/runtime: CP-4a's package, built from the reference
2 parents d3e29b0 + 9cf2974 commit ef40d25

10 files changed

Lines changed: 870 additions & 16 deletions

File tree

‎.github/workflows/runtime.yml‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# The runtime's npm package, @reactivescript/runtime (runtime/): built from ref/compile/rt-web.ts and rt-server.ts,
2+
# tested against the Solid release it names, with a program the crate compiles.
3+
#
4+
# A release is a version bump merged to main, once the repository variable RELEASES is `on`: a version npm does not
5+
# have is published by trusted publishing (OIDC, no token) and tagged `runtime-v<version>`.
6+
name: runtime
7+
8+
on:
9+
push:
10+
branches: [main]
11+
paths: ["runtime/**", "ref/compile/rt-web.ts", "ref/compile/rt-server.ts", "compiler/**", ".github/workflows/runtime.yml"]
12+
pull_request:
13+
paths: ["runtime/**", "ref/compile/rt-web.ts", "ref/compile/rt-server.ts", "compiler/**", ".github/workflows/runtime.yml"]
14+
workflow_dispatch:
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v5
21+
- uses: dtolnay/rust-toolchain@stable
22+
- uses: Swatinem/rust-cache@v2
23+
with:
24+
workspaces: compiler
25+
- uses: actions/setup-node@v5
26+
with:
27+
node-version: 22
28+
- name: The compiler's Node-API build (the test compiles a program)
29+
working-directory: compiler
30+
run: |
31+
npm ci
32+
npx napi build --platform --release --features node --manifest-path ./Cargo.toml -- --lib
33+
- name: Build, test and pack
34+
working-directory: runtime
35+
run: |
36+
npm ci
37+
npm run build
38+
npm test
39+
npm pack
40+
- uses: actions/upload-artifact@v4
41+
with:
42+
name: runtime
43+
path: runtime/*.tgz
44+
45+
version:
46+
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && vars.RELEASES == 'on'
47+
needs: build
48+
runs-on: ubuntu-latest
49+
outputs:
50+
version: ${{ steps.v.outputs.version }}
51+
steps:
52+
- uses: actions/checkout@v5
53+
- id: v
54+
run: |
55+
v=$(node -p 'require("./runtime/package.json").version')
56+
if [ -z "$(npm view "@reactivescript/runtime@$v" version 2>/dev/null)" ]; then echo "version=$v" >> "$GITHUB_OUTPUT"; fi
57+
58+
publish:
59+
needs: version
60+
if: needs.version.outputs.version != ''
61+
runs-on: ubuntu-latest
62+
environment: release
63+
permissions:
64+
id-token: write # trusted publishing: npm takes the job's OIDC token, and adds provenance
65+
contents: write # the tag
66+
steps:
67+
- uses: actions/checkout@v5
68+
- uses: actions/download-artifact@v4
69+
with:
70+
name: runtime
71+
- uses: actions/setup-node@v5
72+
with:
73+
node-version: 22
74+
registry-url: https://registry.npmjs.org
75+
- run: npm install -g npm@latest # trusted publishing needs npm 11.5.1 or later
76+
- run: npm publish ./*.tgz --access public
77+
- name: Tag
78+
run: git tag "runtime-v$V" && git push origin "runtime-v$V"
79+
env:
80+
V: ${{ needs.version.outputs.version }}

‎compiler/README.md‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ What happens to a `.rx` module in Vite:
6969
server-function passes (12 SF-7a) and links the stylesheet as a CSS module
7070
(CSS-4).
7171

72+
The app mounts a program with `createApp` from `@reactivescript/runtime`
73+
(`../runtime`, CP-4a), as the examples do.
74+
7275
Not yet: hot updates of `.rx` modules are untested; server rendering in Vite
73-
needs the runtime package (CP-4a; the examples take `createApp` from
74-
`ref/compile/rt-web.ts`) and the request-scoped app server functions run in;
75-
no WebAssembly fallback for platforms without a binary.
76+
needs a request-scoped app for server functions to run in; no WebAssembly
77+
fallback for platforms without a binary.
7678

7779
### Releasing
7880

@@ -84,19 +86,22 @@ every platform on every change; on `main`, once the repository variable
8486
packages first, by trusted publishing from the `release` environment, and
8587
tags it `compiler-v<version>`.
8688

89+
`@reactivescript/runtime` (`../runtime`) is released the same way by the
90+
`runtime` workflow, tagged `runtime-v<version>`.
91+
8792
Once, by hand: npm sets up trusted publishing only on a package that
88-
exists, so each of the six packages needs a placeholder first,
93+
exists, so each of the seven packages needs a placeholder first,
8994

9095
```sh
9196
npm login
92-
for p in compiler compiler-darwin-x64 compiler-darwin-arm64 compiler-linux-x64-gnu compiler-linux-arm64-gnu compiler-win32-x64-msvc; do
97+
for p in runtime compiler compiler-darwin-x64 compiler-darwin-arm64 compiler-linux-x64-gnu compiler-linux-arm64-gnu compiler-win32-x64-msvc; do
9398
npx setup-npm-trusted-publish "@reactivescript/$p"
9499
done
95100
```
96101

97102
then, on each package's **Settings › Trusted publishing**, GitHub Actions:
98-
owner `ryansolid`, repository `reactivescript`, workflow `compiler.yml`,
99-
environment `release`.
103+
owner `ryansolid`, repository `reactivescript`, workflow `compiler.yml`
104+
(`runtime.yml` for the runtime), environment `release`.
100105

101106
`ref/` stays the specification: a change of behaviour lands there first (with
102107
its scenario), then here, and `ref/crate.ts` keeps the two equal.

‎compiler/test/vite.mjs‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// this package (`@reactivescript/compiler/vite`) in the project, then driven in Chromium; and the todo app again under
33
// the dev server. Vite, solid-js and @solidjs/web come from the solid-next checkout (ref/SOLID_NEXT), as ref/ takes
44
// Solid. Solid's plugin needs built-in `.rx` (solid-vite-plugin PR, see README): SOLID_VITE_PLUGIN names a built
5-
// checkout of it, else the one pnpm installed in solid-next. The Node-API build first: `npm run build` here.
5+
// checkout of it, else the one pnpm installed in solid-next. The Node-API build first: `npm run build` here,
6+
// and the runtime's: `npm run build` in ../runtime.
67
// Usage: SOLID_VITE_PLUGIN=../solid-vite-plugin node compiler/test/vite.mjs [filter]
7-
import { readdirSync, mkdirSync, rmSync, symlinkSync, writeFileSync, cpSync, readFileSync, existsSync } from "node:fs";
8+
import { readdirSync, mkdirSync, rmSync, symlinkSync, writeFileSync, cpSync, readFileSync, existsSync, realpathSync } from "node:fs";
89
import { createServer } from "node:http";
910
import { createRequire } from "node:module";
1011
import { fileURLToPath, pathToFileURL } from "node:url";
@@ -20,7 +21,7 @@ const deps = path.resolve(installed, "../.."); // the installed plugin's node_
2021
const vite = await import(pathToFileURL(path.join(deps, "vite/dist/node/index.js")).href);
2122
const solid = (await import(pathToFileURL(path.join(pluginDir, "dist/esm/index.mjs")).href)).default;
2223
const { chromium } = createRequire(import.meta.url)("playwright");
23-
const rtWeb = path.join(repo, "ref/compile/rt-web.ts");
24+
const runtime = path.join(repo, "runtime"); // @reactivescript/runtime, built (`npm run build` there)
2425

2526
// notes/ calls server functions: with no server behind the static build, it shows its own error boundary
2627
const apps = {
@@ -36,10 +37,18 @@ function project(name, entry) {
3637
const dir = path.join(out, name); rmSync(dir, { recursive: true, force: true }); mkdirSync(dir, { recursive: true });
3738
// the project's node_modules: the plugin's (vite, solid-js, @solidjs/web) and this package, installed
3839
const nm = path.join(dir, "node_modules"); mkdirSync(path.join(nm, "@reactivescript"), { recursive: true });
39-
for (const d of readdirSync(deps)) if (d !== "@reactivescript") symlinkSync(path.join(deps, d), path.join(nm, d));
40+
for (const d of readdirSync(deps)) {
41+
if (!d.startsWith("@")) { symlinkSync(path.join(deps, d), path.join(nm, d)); continue; }
42+
mkdirSync(path.join(nm, d), { recursive: true });
43+
for (const e of readdirSync(path.join(deps, d))) symlinkSync(path.join(deps, d, e), path.join(nm, d, e));
44+
}
45+
// the runtime's peers: solid-js and @solidjs/web are the plugin's; @solidjs/signals the one that solid-js runs on
46+
if (!existsSync(path.join(nm, "@solidjs/signals"))) symlinkSync(realpathSync(path.join(deps, "solid-js/node_modules/@solidjs/signals")), path.join(nm, "@solidjs/signals"));
4047
symlinkSync(pkg, path.join(nm, "@reactivescript/compiler"));
48+
// the runtime as installed: copied, so that it takes the project's Solid (a peer), not its own dev copy
49+
for (const f of ["package.json", "dist"]) cpSync(path.join(runtime, f), path.join(nm, "@reactivescript/runtime", f), { recursive: true });
4150
cpSync(path.join(repo, "examples"), path.join(dir, "src"), { recursive: true });
42-
writeFileSync(path.join(dir, "src/entry.js"), `import { createApp } from ${JSON.stringify(rtWeb)};\nimport main from "./${entry}";\nimport * as api from "./api.mjs";\nconst app = createApp({ root: document.getElementById("app"), api });\napp.mount(main(app));\n`);
51+
writeFileSync(path.join(dir, "src/entry.js"), `import { createApp } from "@reactivescript/runtime";\nimport main from "./${entry}";\nimport * as api from "./api.mjs";\nconst app = createApp({ root: document.getElementById("app"), api });\napp.mount(main(app));\n`);
4352
writeFileSync(path.join(dir, "index.html"), `<!doctype html><html><head><meta charset="utf-8"><title>${name}</title></head><body><div id="app"></div><script type="module" src="/src/entry.js"></script></body></html>\n`);
4453
return dir;
4554
}
@@ -90,7 +99,7 @@ for (const [name, entry] of Object.entries(apps)) {
9099
if (!filter || "shared".includes(filter)) { // two programs on one page, sharing shop/catalog.rx: no entry option, one catalog module
91100
const dir = project("shared", "shop/main.rx");
92101
writeFileSync(path.join(dir, "src/shop/count.rx"), `import { products } from "./catalog.rx"\n\nexport default component Count() {\n errored fallback(e) { <p>no catalogue</p> } {\n <p>{len(products)} products</p>\n }\n}\n`);
93-
writeFileSync(path.join(dir, "src/entry.js"), `import { createApp } from ${JSON.stringify(rtWeb)};\nimport shop from "./shop/main.rx";\nimport count from "./shop/count.rx";\nimport * as api from "./api.mjs";\nfor (const [main, el] of [[shop, "app"], [count, "app2"]]) { const app = createApp({ root: document.getElementById(el), api }); app.mount(main(app)); }\n`);
102+
writeFileSync(path.join(dir, "src/entry.js"), `import { createApp } from "@reactivescript/runtime";\nimport shop from "./shop/main.rx";\nimport count from "./shop/count.rx";\nimport * as api from "./api.mjs";\nfor (const [main, el] of [[shop, "app"], [count, "app2"]]) { const app = createApp({ root: document.getElementById(el), api }); app.mount(main(app)); }\n`);
94103
writeFileSync(path.join(dir, "index.html"), readFileSync(path.join(dir, "index.html"), "utf8").replace('<div id="app"></div>', '<div id="app"></div><div id="app2"></div>'));
95104
try {
96105
const bundle = await vite.build(config(dir, "shop/main.rx"));

‎runtime/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
dist/
3+
.test/

‎runtime/README.md‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# @reactivescript/runtime
2+
3+
ReactiveScript's runtime (spec/11 CP-4a): `createApp` and the `__rt` helpers
4+
that compiled `.rx` calls, over Solid. Each helper is a Solid primitive, a
5+
composition of them, or plain JavaScript; nothing in it adds run-time
6+
behaviour beyond Solid.
7+
8+
There is a browser build and a server build, chosen by export condition as
9+
`@solidjs/web` chooses (`browser` → the browser build; `node`, `deno`,
10+
`worker` → the server build; `./web` and `./server` name one explicitly).
11+
Both create the same owners in the same order, so a page the server streamed
12+
hydrates (spec/10).
13+
14+
```js
15+
import { createApp } from "@reactivescript/runtime";
16+
import main from "./app.rx"; // compiled by @reactivescript/compiler (Solid's Vite plugin loads it)
17+
18+
const app = createApp({ root: document.getElementById("app") });
19+
app.mount(main(app));
20+
```
21+
22+
Solid is a peer: `solid-js`, `@solidjs/web` and `@solidjs/signals` (the
23+
runtime reads owner context from `@solidjs/signals`, which `solid-js` runs on;
24+
with pnpm, add it to the app).
25+
26+
The source is the reference's runtime, `ref/compile/rt-web.ts` and
27+
`rt-server.ts`, the one every scenario runs on; `npm run build` transpiles it
28+
to `dist/` with its declarations. `npm test` checks both builds and renders
29+
a program compiled by the crate on the server build (it needs the compiler's
30+
Node-API build: `npm run build` in `../compiler`).
31+
32+
Not yet: the server build's `stream` takes no request (it provides a
33+
placeholder one); a framework's request handling is to come.
34+
35+
Releases: as `@reactivescript/compiler`'s (`../compiler/README.md`,
36+
Releasing), by the `runtime` workflow, tagged `runtime-v<version>`.

‎runtime/build.mjs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// The runtime's source is the reference's (ref/compile/rt-web.ts and rt-server.ts, spec/11 CP-4a), so the package
2+
// runs what the scenarios run: each is transpiled to dist/ as it is (Solid stays external, a peer of the app's), with
3+
// its declarations.
4+
import { execFileSync } from "node:child_process";
5+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
6+
import { createRequire } from "node:module";
7+
import { fileURLToPath } from "node:url";
8+
import path from "node:path";
9+
import { build } from "esbuild";
10+
11+
const here = path.dirname(fileURLToPath(import.meta.url));
12+
const src = path.resolve(here, "../ref/compile");
13+
const dist = path.join(here, "dist");
14+
rmSync(dist, { recursive: true, force: true }); mkdirSync(dist);
15+
for (const [from, to] of [["rt-web.ts", "web"], ["rt-server.ts", "server"]]) {
16+
await build({ entryPoints: [path.join(src, from)], outfile: path.join(dist, `${to}.js`), format: "esm", platform: "neutral", target: "es2022", bundle: true, packages: "external", logLevel: "warning" });
17+
}
18+
// declarations, unchecked: the runtime uses Solid internals its types leave out (createErrorBoundary, sharedConfig,
19+
// runInServerComponentScope); Solid's types resolve from this package's node_modules
20+
const tsc = createRequire(import.meta.url).resolve("typescript/bin/tsc");
21+
const config = path.join(here, ".tsconfig.build.json");
22+
writeFileSync(config, JSON.stringify({
23+
compilerOptions: { declaration: true, emitDeclarationOnly: true, outDir: "dist/types", rootDir: src, module: "nodenext", moduleResolution: "nodenext", target: "es2022", skipLibCheck: true, allowImportingTsExtensions: true, noCheck: true, paths: { "*": ["./node_modules/*"] } },
24+
files: [path.join(src, "rt-web.ts"), path.join(src, "rt-server.ts")],
25+
}));
26+
try { execFileSync(process.execPath, [tsc, "-p", config], { stdio: "inherit", cwd: here }); }
27+
finally { rmSync(config); }
28+
for (const [from, to] of [["rt-web", "web"], ["rt-server", "server"]]) writeFileSync(path.join(dist, `${to}.d.ts`), `export * from "./types/${from}.js";\n`);

0 commit comments

Comments
 (0)