Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435// Boots the runtime with the page's options, runs an ESM guest that imports a .mts file// (so the kernel fetches typestrip.wasm) and then the Express fixture in an iframe.import { boot } from "@nibling/kernel";
const out = document.getElementById("out");const errEl = document.getElementById("err");const dec = new TextDecoder();
export async function run(options) { try { const runtime = await boot(options); const res = await fetch("/dist/fixtures/express.snap"); if (!res.ok) throw new Error(`fixture missing (${res.status}): run npm run fixtures`); runtime.mountSnapshot(await res.arrayBuffer()); runtime.writeTree({ "/app/hello.mjs": 'import { greet } from "./greet.mts";\nconsole.log(greet("relocated"));\n', "/app/greet.mts": 'export function greet(name: string): string {\n return `hello ${name}`;\n}\n', });
const hello = runtime.exec("/app/hello.mjs"); const stdout = hello.stdout.pipeTo(new WritableStream({ write: (c) => { out.textContent += dec.decode(c); } })); const stderr = hello.stderr.pipeTo(new WritableStream({ write: (c) => { errEl.textContent += dec.decode(c); } })); await Promise.all([stdout, stderr, hello.exited]);
const server = runtime.exec("/app/server.cjs", { env: { NODE_ENV: "production" } }); server.stderr.pipeTo(new WritableStream({ write: (c) => { errEl.textContent += dec.decode(c); } })); const frame = document.createElement("iframe"); frame.id = "app"; frame.src = await runtime.waitForPort(3000); document.body.append(frame); } catch (e) { errEl.textContent = "BOOT FAILED: " + (e?.message ?? String(e)); }}