Skip to content

Commit

Permalink
init workerd shim
Browse files Browse the repository at this point in the history
  • Loading branch information
lherman-cs committed Jan 22, 2025
1 parent 5edb687 commit ed173a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ build:
$(MAKE) build-target WASM_PATH=$(WASM_PATH) TARGET=experimental-nodejs-module
$(MAKE) build-target WASM_PATH=$(WASM_PATH) TARGET=deno

# shim workerd
cp $(ROOT_DIR)/shim-workerd.js $(ROOT_DIR)/pkg-experimental-nodejs-module/

build-target:
wasm-bindgen --target $(TARGET) --out-dir $(ROOT_DIR)/pkg-$(TARGET) --typescript $(WASM_PATH)
# jsr requires explicit d.ts reference, https://github.com/jsr-io/jsr/issues/370#issuecomment-2044467118
Expand Down
3 changes: 2 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"exports": {
".": "./pkg-experimental-nodejs-module/pulsebeam_core.js",
"./node": "./pkg-experimental-nodejs-module/pulsebeam_core.js",
"./deno": "./pkg-deno/pulsebeam_core.js"
"./deno": "./pkg-deno/pulsebeam_core.js",
"./workerd": "./pkg-experimental-nodejs-module/shim-workerd.js"
},
"files": [
"pkg-experimental-nodejs-module",
Expand Down
19 changes: 19 additions & 0 deletions js/shim-workerd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Cloudflare doesn't support URL, import.meta.url, and fs.readFileSync
// https://github.com/cloudflare/workers-sdk/issues/7265#issuecomment-2480871605

let imports = {};
import * as import0 from "./pulsebeam_core_bg.js";
import wasmModule from "./pulsebeam_core_bg.wasm";
imports["./pulsebeam_core_bg.js"] = import0;

const wasmInstance = await WebAssembly.instantiate(wasmModule, imports);
const wasm = wasmInstance.exports;
export const __wasm = wasm;

imports["./pulsebeam_core_bg.js"].__wbg_set_wasm(
wasm,
wasmModule,
);
wasm.__wbindgen_start();

export * from "./pulsebeam_core_bg.js";

0 comments on commit ed173a0

Please sign in to comment.