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

[Feature request] Inlining wasm binary #21

Open
riywo opened this issue Apr 12, 2023 · 2 comments
Open

[Feature request] Inlining wasm binary #21

riywo opened this issue Apr 12, 2023 · 2 comments

Comments

@riywo
Copy link

riywo commented Apr 12, 2023

For some Node.js runtime environment such as AWS Lambda, it would be nice to have a pure JS implementation without extra file access like a wasm file because some bundling process doesn't recognize such extra files automatically.

Could you provide another package like re2-wasm-inline by inlining the wasm binary as a Buffer so that the extra wasm file isn't required?

Or, if your licensing term allows, I can also create such a package and publish it to npmjs on behalf.

Let me know your opinion!

See smithy-lang/smithy-typescript#733

This could also solve #15

@riywo
Copy link
Author

riywo commented Apr 12, 2023

Let me craft a PoC package.

@riywo
Copy link
Author

riywo commented Apr 15, 2023

This simple script worked:

const fs = require("fs");

fs.rmSync("build", { force: true, recursive: true });
fs.cpSync("node_modules/re2-wasm/build", "build", { recursive: true });

const wasm = fs.readFileSync("build/wasm/re2.wasm").toString("base64");
const js = fs.readFileSync("build/wasm/re2.js", { encoding: "utf8" });

fs.writeFileSync(
  "build/wasm/re2.js",
  `
var Module = {
  wasmBinary: Buffer.from("${wasm}", "base64"),
}
${js}
`
);

fs.rmSync("build/wasm/re2.wasm");

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

No branches or pull requests

1 participant