// Demo page logic for the step-1 milestone (+ package.json resolution). // Runs on the page (host side). import { boot } from "@nibling/kernel"; const out = document.getElementById("out"); const errEl = document.getElementById("err"); const exitEl = document.getElementById("exit"); const dec = new TextDecoder(); try { const runtime = await boot(); const read = async (p) => await (await fetch(p)).text(); runtime.writeTree({ "/app/main.cjs": await read("/demo/app/main.cjs"), "/app/greet.js": await read("/demo/app/greet.js"), "/app/name.txt": await read("/demo/app/name.txt"), "/app/node_modules/leftpad/package.json": await read("/demo/app/node_modules/leftpad/package.json"), "/app/node_modules/leftpad/index.js": await read("/demo/app/node_modules/leftpad/index.js"), "/app/node_modules/shouty/package.json": await read("/demo/app/node_modules/shouty/package.json"), "/app/node_modules/shouty/lib/loud.js": await read("/demo/app/node_modules/shouty/lib/loud.js"), }); const proc = runtime.exec("/app/main.cjs"); proc.stdout.pipeTo(new WritableStream({ write: (c) => { out.textContent += dec.decode(c); } })); proc.stderr.pipeTo(new WritableStream({ write: (c) => { errEl.textContent += dec.decode(c); } })); exitEl.textContent = String(await proc.exited); } catch (e) { errEl.textContent = "BOOT FAILED: " + (e?.message ?? String(e)); exitEl.textContent = "?"; }