From a85224999d89425e3f1cde3c792a90a49ce9642f Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Tue, 14 Dec 2021 22:27:38 +0000 Subject: [PATCH] support importing `.wasm` files / `workers-rs` support Following up from https://github.com/cloudflare/wrangler2/pull/107, this PR adds support for importing `.wasm` files. Specifically, it works directly on the output of [`workers-rs`](https://github.com/cloudflare/workers-rs). I'll test with other wasm outputs (like assemblyscript etc) later. --- .changeset/thin-terms-walk.md | 5 +++++ packages/wrangler/src/module-collection.ts | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/thin-terms-walk.md diff --git a/.changeset/thin-terms-walk.md b/.changeset/thin-terms-walk.md new file mode 100644 index 000000000000..a14df9a55581 --- /dev/null +++ b/.changeset/thin-terms-walk.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +support importing `.wasm` files / `workers-rs` support diff --git a/packages/wrangler/src/module-collection.ts b/packages/wrangler/src/module-collection.ts index 5d0efac7a124..1ebfa8e3073b 100644 --- a/packages/wrangler/src/module-collection.ts +++ b/packages/wrangler/src/module-collection.ts @@ -30,10 +30,11 @@ export default function makeModuleCollector(): { build.onResolve( // filter on "known" file types, // we can expand this list later - { filter: /.*\.(pem|txt|html)$/ }, + { filter: /.*\.(pem|txt|html|wasm)$/ }, async (args: esbuild.OnResolveArgs) => { // take the file and massage it to a // transportable/manageable format + const fileExt = path.extname(args.path); const filePath = path.join(args.resolveDir, args.path); const fileContent = await readFile(filePath); const fileHash = crypto @@ -46,7 +47,7 @@ export default function makeModuleCollector(): { modules.push({ name: fileName, content: fileContent, - type: "text", + type: fileExt === ".wasm" ? "compiled-wasm" : "text", }); return {