muse/esp32-eink-display
A 55×46 mm two-layer ESP32-S3 e-paper controller board with USB‑C power/programming, buck regulation, FPC display connector, UC8179-style boost/charge-pump circuitry, ESD protection, controls, and routed passive components.
- Version
- 1.3.4
- License
- unset
- Stars
- 0
scripts/patch-webgpu.mjs
// Temporary compatibility patch for the pinned runframe build. The corresponding
// upstream TypeScript change and regression tests are in renderer-fix/upstream.patch.
import {readFileSync, writeFileSync} from "node:fs";
import {createRequire} from "node:module";
import {dirname, resolve} from "node:path";
import {createHash} from "node:crypto";
import {findWorker, findShapeFunction} from "./webgpu-bundle-utils.mjs";
const require = createRequire(import.meta.url);
const patch = JSON.parse(readFileSync(new URL("../renderer-fix/bundle-patch.json", import.meta.url)));
const standalone = require.resolve("@tscircuit/runframe/standalone");
const manifest = JSON.parse(readFileSync(resolve(dirname(standalone), "../package.json")));
if (manifest.version !== patch.runframeVersion) throw new Error("Runframe version changed; review/remove the compatibility patch before rebuilding.");
for (const name of ["standalone.min.js", "standalone-preview.min.js"]) {
const path = resolve(dirname(standalone), name);
const source = readFileSync(path, "utf8");
const worker = findWorker(source);
const shape = findShapeFunction(worker.text);
const original = shape.replace(patch.branch, "");
if (createHash("sha256").update(original).digest("hex") !== patch.shapeFunctionHash)
throw new Error(`Unexpected WebGPU shape compiler in ${name}; refusing an unsafe patch.`);
if (shape.includes(patch.branch)) {console.log(`${name}: already patched`); continue;}
const updated = worker.text.replace(patch.functionPrefix, patch.functionPrefix + patch.branch);
if (findShapeFunction(updated).replace(patch.branch, "") !== original) throw new Error("Patch changed unrelated geometry");
writeFileSync(path, source.slice(0, worker.start) + JSON.stringify(updated) + source.slice(worker.end));
console.log(`${name}: rotated plated-hole support applied`);
}
// tsci bundles its own copy of the standalone viewer inside both CLI modules.
// Updating runframe alone is insufficient: patch that embedded viewer as well.
const ts = (await import("typescript")).default;
for (const path of [require.resolve("@tscircuit/cli"), require.resolve("@tscircuit/cli/lib")]) {
const source = readFileSync(path, "utf8");
const prefix = "var standalone_min_default = ";
const start = source.indexOf(prefix) + prefix.length;
if (start < prefix.length || source.indexOf(prefix, start) !== -1) throw new Error("Unexpected CLI standalone bundle location");
const scanner = ts.createScanner(ts.ScriptTarget.Latest, false, ts.LanguageVariant.Standard, source.slice(start));
if (scanner.scan() !== ts.SyntaxKind.StringLiteral) throw new Error("Expected embedded viewer string");
const viewer = scanner.getTokenValue(), end = start + scanner.getTextPos();
const worker = findWorker(viewer), shape = findShapeFunction(worker.text);
const original = shape.replace(patch.branch, "");
if (createHash("sha256").update(original).digest("hex") !== patch.shapeFunctionHash) throw new Error("Unexpected CLI WebGPU compiler; refusing patch");
if (shape.includes(patch.branch)) {console.log(`${path}: already patched`); continue;}
const updatedWorker = worker.text.replace(patch.functionPrefix, patch.functionPrefix + patch.branch);
const updatedViewer = viewer.slice(0, worker.start) + JSON.stringify(updatedWorker) + viewer.slice(worker.end);
writeFileSync(path, source.slice(0, start) + JSON.stringify(updatedViewer) + source.slice(end));
console.log(`${path}: embedded WebGPU viewer patched`);
}
