Skip to content

Commit b4590e4

Browse files
Add env option to DefaultRubyVM to configure env vars passed to Ruby
1 parent bc46b12 commit b4590e4

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/npm-packages/ruby-wasm-wasi/src/browser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@ const consolePrinter = () => {
6262

6363
export const DefaultRubyVM = async (
6464
rubyModule: WebAssembly.Module,
65-
options: { consolePrint: boolean } = { consolePrint: true },
65+
options: {
66+
consolePrint?: boolean;
67+
env?: Record<string, string> | undefined;
68+
},
6669
): Promise<{
6770
vm: RubyVM;
6871
wasi: WASI;
6972
instance: WebAssembly.Instance;
7073
}> => {
7174
await init();
7275

73-
const wasi = new WASI({});
76+
const wasi = new WASI({ env: options.env });
7477
const vm = new RubyVM();
7578

7679
const imports = wasi.getImports(rubyModule) as WebAssembly.Imports;
7780
vm.addToImports(imports);
78-
const printer = options.consolePrint ? consolePrinter() : undefined;
81+
const printer = (options.consolePrint ?? true) ? consolePrinter() : undefined;
7982
printer?.addToImports(imports);
8083

8184
const instance = await WebAssembly.instantiate(rubyModule, imports);

packages/npm-packages/ruby-wasm-wasi/src/node.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { WASI } from "wasi";
22
import { RubyVM } from "./index";
33

4-
export const DefaultRubyVM = async (rubyModule: WebAssembly.Module) => {
5-
const wasi = new WASI();
4+
export const DefaultRubyVM = async (
5+
rubyModule: WebAssembly.Module,
6+
options: { env?: Record<string, string> | undefined },
7+
) => {
8+
const wasi = new WASI({ env: options.env });
69
const vm = new RubyVM();
710
const imports = {
811
wasi_snapshot_preview1: wasi.wasiImport,

0 commit comments

Comments
 (0)