Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add an entrypoint which embeds the wasm instead of requiring it to be fetched over the network when deployed as a Netlify Edge Function #10

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

JakeChampion
Copy link
Collaborator

@JakeChampion JakeChampion commented Nov 25, 2024

Netlify Edge Functions are not able to read the file-system, which means we can't read the generated .wasm file during execution, we currently fetch the wasm file over the network but this request could fail or have an incorrect response, leading to a runtime error when attempting to instantiate the WebAssembly Module. To work-around this,when building the .wasm file we now also build a .ts file which includes the exact same bytes as the wasm file, but within a JavaScript UInt8Array, which we can then instantiate as a WebAssembly Module.

This package now has two possible entry-points, the already existing one at ./src/index.ts and a new one at ./src/index-embedded-wasm.ts - The tests have been updated to test both entry-points.

scripts/build.ts Outdated Show resolved Hide resolved
src/csp.ts Show resolved Hide resolved
… to be fetched over the network when deployed as a Netlify Edge Function

Netlify Edge Functions are not able to read the file-system, which means we can't read the generated `.wasm` file during execution, we currently fetch the wasm file over the network but this request could fail or have an incorrect response, leading to a runtime error when attempting to instantiate the WebAssembly Module. To work-around this, we when building the `.wasm` file we now also build a `.ts` file which includes the exact same bytes as the wasm file, but within a JavaScipt UInt8Array, which we can then instantiate as a WebAssembly Module.
@JakeChampion JakeChampion force-pushed the jake/inline-wasm branch 4 times, most recently from 4780aaa to c9ead30 Compare November 25, 2024 13:51
@JakeChampion JakeChampion merged commit ccb04a7 into main Nov 25, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants