diff --git a/packages/npm-packages/ruby-wasm-wasi/src/browser.ts b/packages/npm-packages/ruby-wasm-wasi/src/browser.ts index 9068b093f8..14fd2dea1e 100644 --- a/packages/npm-packages/ruby-wasm-wasi/src/browser.ts +++ b/packages/npm-packages/ruby-wasm-wasi/src/browser.ts @@ -62,7 +62,10 @@ const consolePrinter = () => { export const DefaultRubyVM = async ( rubyModule: WebAssembly.Module, - options: { consolePrint: boolean } = { consolePrint: true }, + options: { + consolePrint?: boolean; + env?: Record | undefined; + } = {}, ): Promise<{ vm: RubyVM; wasi: WASI; @@ -70,12 +73,12 @@ export const DefaultRubyVM = async ( }> => { await init(); - const wasi = new WASI({}); + const wasi = new WASI({ env: options.env }); const vm = new RubyVM(); const imports = wasi.getImports(rubyModule) as WebAssembly.Imports; vm.addToImports(imports); - const printer = options.consolePrint ? consolePrinter() : undefined; + const printer = (options.consolePrint ?? true) ? consolePrinter() : undefined; printer?.addToImports(imports); const instance = await WebAssembly.instantiate(rubyModule, imports); diff --git a/packages/npm-packages/ruby-wasm-wasi/src/node.ts b/packages/npm-packages/ruby-wasm-wasi/src/node.ts index 4d27fee208..b9b4312f9d 100644 --- a/packages/npm-packages/ruby-wasm-wasi/src/node.ts +++ b/packages/npm-packages/ruby-wasm-wasi/src/node.ts @@ -1,8 +1,11 @@ import { WASI } from "wasi"; import { RubyVM } from "./index"; -export const DefaultRubyVM = async (rubyModule: WebAssembly.Module) => { - const wasi = new WASI(); +export const DefaultRubyVM = async ( + rubyModule: WebAssembly.Module, + options: { env?: Record | undefined } = {}, +) => { + const wasi = new WASI({ env: options.env }); const vm = new RubyVM(); const imports = { wasi_snapshot_preview1: wasi.wasiImport,