Skip to content

Commit

Permalink
Add env option to DefaultRubyVM to configure env vars passed to Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Nov 13, 2023
1 parent bc46b12 commit b4590e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/npm-packages/ruby-wasm-wasi/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ const consolePrinter = () => {

export const DefaultRubyVM = async (
rubyModule: WebAssembly.Module,
options: { consolePrint: boolean } = { consolePrint: true },
options: {
consolePrint?: boolean;
env?: Record<string, string> | undefined;
},
): Promise<{
vm: RubyVM;
wasi: WASI;
instance: WebAssembly.Instance;
}> => {
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);
Expand Down
7 changes: 5 additions & 2 deletions packages/npm-packages/ruby-wasm-wasi/src/node.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> | undefined },
) => {
const wasi = new WASI({ env: options.env });
const vm = new RubyVM();
const imports = {
wasi_snapshot_preview1: wasi.wasiImport,
Expand Down

0 comments on commit b4590e4

Please sign in to comment.