Skip to content

Commit acbbeef

Browse files
committed
♻️ inline WASM binary into generated TypeScript module
Replace runtime filesystem read of clayterm.wasm with a build step that base64-encodes the binary into wasm.ts. This removes the node:fs/promises dependency and --allow-read requirement for the WASM file.
1 parent 37594f1 commit acbbeef

6 files changed

Lines changed: 22 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/.agent-shell/
22
/clayterm.wasm
3+
/wasm.ts
34
/build/
45
/node_modules/

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@ LDFLAGS = -Wl,--no-entry \
1313
-Wl,--undefined=Clay__MeasureText \
1414
-Wl,--undefined=Clay__QueryScrollOffset
1515

16-
all: $(TARGET)
16+
all: $(TARGET) wasm.ts
1717
@echo "Built $(TARGET) ($$(wc -c < $(TARGET)) bytes)"
1818

1919
DEPS = $(wildcard src/*.c src/*.h)
2020

2121
$(TARGET): $(DEPS)
2222
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC)
2323

24+
wasm.ts: $(TARGET)
25+
deno run --allow-read --allow-write tasks/encode-wasm.ts
26+
2427
clean:
25-
rm -f $(TARGET)
28+
rm -f $(TARGET) wasm.ts
2629

2730
.PHONY: all clean

deno.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tasks/build-npm.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ await build({
4444
});
4545

4646
await Deno.copyFile("README.md", `${outDir}/README.md`);
47-
await Deno.copyFile("clayterm.wasm", `${outDir}/esm/clayterm.wasm`);

tasks/encode-wasm.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { encodeBase64 } from "jsr:@std/encoding/base64";
2+
3+
const wasm = await Deno.readFile("clayterm.wasm");
4+
const base64 = encodeBase64(wasm);
5+
6+
const source = `const base64 = "${base64}";
7+
const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
8+
export const compiled = await WebAssembly.compile(bytes);
9+
`;
10+
11+
await Deno.writeTextFile("wasm.ts", source);
12+
console.log(`wrote wasm.ts (${wasm.length} bytes encoded)`);

wasm.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)