#!/usr/bin/env bash # Builds the web vault package: wasm-pack (size profile, wasm-opt -Oz) plus the Web Worker wrapper. # crates/kv-wasm/build.sh -> crates/kv-wasm/pkg/ # Then run the Node smoke test: node crates/kv-wasm/js/smoke.mjs set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" cd "$here" wasm-pack build . --target web --profile wasm-release --out-dir pkg --scope kestrove --out-name kv_wasm cp js/worker.js js/client.js js/client.d.ts pkg/ # Ship the worker files and point the package's types at the client (it re-exports everything). node -e ' const fs = require("fs"); const p = JSON.parse(fs.readFileSync("pkg/package.json", "utf8")); p.files = Array.from(new Set([...(p.files || []), "worker.js", "client.js", "client.d.ts"])); p.exports = { ".": { types: "./kv_wasm.d.ts", default: "./kv_wasm.js" }, "./client.js": { types: "./client.d.ts", default: "./client.js" }, "./worker.js": "./worker.js", "./kv_wasm_bg.wasm": "./kv_wasm_bg.wasm", }; fs.writeFileSync("pkg/package.json", JSON.stringify(p, null, 2) + "\n"); ' wasm="pkg/kv_wasm_bg.wasm" printf 'kv_wasm_bg.wasm: %s bytes, gzip -9 %s, brotli %s\n' \ "$(wc -c <"$wasm" | tr -d ' ')" "$(gzip -9 -c "$wasm" | wc -c | tr -d ' ')" \ "$( (command -v brotli >/dev/null && brotli -c -q 11 "$wasm" | wc -c | tr -d ' ') || echo n/a)"