extism / js-sdk

Run Extism WebAssembly plug-ins / functions from JavaScript (supports major browsers, Node.js, Deno, Bun, and Cloudflare Workers)
https://extism.github.io/js-sdk/
BSD 3-Clause "New" or "Revised" License
89 stars 12 forks source link

Deno 2 WASI support #95

Open G4Vi opened 1 month ago

G4Vi commented 1 month ago

Deno removed wasi from their standard library, we should use the wasi polyfill instead on Deno 2.

From https://discord.com/channels/1011124058408112148/1156304630028959824/1295444183930110013:

main.ts

import createPlugin from "npm:@extism/extism";

const plugin = await createPlugin(
  "plugin.wasm",
  { useWasi: true, runInWorker: true },
);

let out = await plugin.call("greet", "a1");
console.log(out?.text());

lib.rs (compiled to wasm32-wasi w/ release)

use extism_pdk::*;

#[plugin_fn]
pub fn greet(name: String) -> FnResult<String> {
    Ok(format!("Hello, {}!", name))
}

result:

Uncaught (in worker "") Relative import path "wasi" not prefixed with / or ./ or ../ and not in import map from "data:text/javascript;base64,dm...lots of base64...

hint: If you want to use a built-in Node module, add a "node:" prefix (ex. "node:wasi").

at data:text/javascript;base64,dm...
bhelx commented 1 month ago

Since wasi is deprecated in node as well, we might want to consider using the polyfill there too.