mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
packages/widgets-rs/web: PsychoScript's web/ (web branch e16ce7e), the TypeScript host that runs widgets in Web Workers on widget-web's WebAssembly, as package widget-web. The module is widget_web_bg.wasm (was psychoscript_web_bg.wasm): scripts/build-wasm.sh builds crate widget-web in the workspace one level up, with the opencode checkout's root remapped to /opencode, and the worker, the host's default module URL, build.ts and the package's exports follow. dist/ is no longer committed (it holds the ~10 MB module): bash scripts/build-wasm.sh && bun run build makes it. The scripts read the fixtures and preludes in place from packages/widget, and fixtures.ts takes it by default. The bundle is otherwise byte for byte the web branch's.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
#!/usr/bin/env bun
|
|
// Builds dist/: index.js (the page side), worker.js (the worker, with the wasm-bindgen glue), the .wasm module from
|
|
// wasm/ (scripts/build-wasm.sh), and the .d.ts files.
|
|
|
|
import { $ } from "bun"
|
|
import { cp, rm } from "node:fs/promises"
|
|
import path from "node:path"
|
|
|
|
const root = path.resolve(import.meta.dir, "..")
|
|
const dist = path.join(root, "dist")
|
|
await rm(dist, { recursive: true, force: true })
|
|
const built = await Bun.build({
|
|
entrypoints: [path.join(root, "src/index.ts"), path.join(root, "src/worker.ts")],
|
|
outdir: dist,
|
|
format: "esm",
|
|
target: "browser",
|
|
minify: true,
|
|
sourcemap: "linked",
|
|
naming: "[name].[ext]",
|
|
})
|
|
if (!built.success) {
|
|
for (const log of built.logs) console.error(log)
|
|
process.exit(1)
|
|
}
|
|
await cp(path.join(root, "wasm/widget_web_bg.wasm"), path.join(dist, "widget_web_bg.wasm"))
|
|
await $`bun x tsc -p ${path.join(root, "tsconfig.build.json")}`.cwd(root)
|
|
for (const f of await Array.fromAsync(new Bun.Glob("*").scan(dist)))
|
|
console.log(f.padEnd(36), (Bun.file(path.join(dist, f)).size / 1024).toFixed(1).padStart(8), "KB")
|