Files
faunosteo/scripts/wasm-stamp.mjs
T
bchanot 343d6f4c1f feat(workspace): R2.4 core runtime — lazy load, poison on trap, offline re-instantiation, per-generation sheet handles
packages/core-wasm: browser-safe CoreRuntime (synchronous calls once ready;
a WebAssembly.RuntimeError poisons the instance, the call answers internal,
a fresh instance comes from the kept compiled module and a glue record
imported in advance; at most 3 recoveries per page; retry after a load
failure), SheetSession (handle rebuilt per instance generation, never
called on a dropped one; invalid_sheet without poisoning), Node source.
crates/wasm: SheetHandle (sheet held in the module memory). Two builds:
pkg/ shipped without trap exports (checked), pkg-proofs/ for the trap
tests; BUILD_STAMP (hash of the Rust sources) refused when missing or
stale by the vitest global setup instead of skipping. Failure envelope
carries a numeric found version; compact JS-number output.
2026-10-14 00:12:04 +02:00

42 lines
1.4 KiB
JavaScript

// Build stamp of the browser module: sha256 over the sources that compile into it (the core
// library, the wasm facade, the workspace manifests and lock, the cargo config). Written into
// pkg/ and pkg-proofs/ by scripts/wasm-build.sh; packages/core-wasm/tests/global-setup.ts
// recomputes it and refuses to run the suites on a missing or stale module.
// Usage: node scripts/wasm-stamp.mjs → prints the stamp.
import { createHash } from 'node:crypto'
import { readdirSync, readFileSync, statSync } from 'node:fs'
import { join, relative, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
const INPUTS = [
'Cargo.toml',
'Cargo.lock',
'.cargo/config.toml',
'crates/core/Cargo.toml',
'crates/core/src',
'crates/wasm/Cargo.toml',
'crates/wasm/src',
]
function files(path) {
const absolute = join(ROOT, path)
if (!statSync(absolute).isDirectory()) return [path]
return readdirSync(absolute).flatMap((name) => files(join(path, name)))
}
export function wasmStamp() {
const hash = createHash('sha256')
const all = INPUTS.flatMap(files).map((f) => relative(ROOT, join(ROOT, f)))
for (const file of all.sort()) {
hash.update(`${file}\0`)
hash.update(readFileSync(join(ROOT, file)))
hash.update('\0')
}
return hash.digest('hex')
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
process.stdout.write(`${wasmStamp()}\n`)
}