@ruby/wasm-wasi 2.9.4-2026-07-20-a → 2.9.4-2026-07-22-a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.script.umd.js +59 -3
- package/dist/browser.umd.js +8 -1
- package/dist/cjs/browser.script.d.ts +1 -0
- package/dist/cjs/browser.script.js +51 -2
- package/dist/cjs/vm.d.ts +4 -0
- package/dist/cjs/vm.js +8 -1
- package/dist/esm/browser.script.d.ts +1 -0
- package/dist/esm/browser.script.js +51 -2
- package/dist/esm/vm.d.ts +4 -0
- package/dist/esm/vm.js +8 -1
- package/dist/index.umd.js +8 -1
- package/package.json +1 -1
|
@@ -820,9 +820,16 @@
|
|
|
820
820
|
initComponent = async (jsRuntime) => {
|
|
821
821
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
822
822
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
823
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
824
|
+
var _a;
|
|
825
|
+
return Array.from(new Map([
|
|
826
|
+
...cli.environment.getEnvironment(),
|
|
827
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
828
|
+
]).entries());
|
|
829
|
+
} }) : cli.environment;
|
|
823
830
|
const importObject = {
|
|
824
831
|
"ruby:js/js-runtime": jsRuntime,
|
|
825
|
-
"wasi:cli/environment":
|
|
832
|
+
"wasi:cli/environment": environment,
|
|
826
833
|
"wasi:cli/exit": cli.exit,
|
|
827
834
|
"wasi:cli/stderr": cli.stderr,
|
|
828
835
|
"wasi:cli/stdin": cli.stdin,
|
|
@@ -1602,18 +1609,20 @@
|
|
|
1602
1609
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
|
|
1603
1610
|
*/
|
|
1604
1611
|
const main = async (pkg, options) => {
|
|
1612
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
1605
1613
|
const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
|
|
1606
1614
|
const module = await compileWebAssemblyModule(response);
|
|
1607
|
-
const { vm } = await DefaultRubyVM(module, options);
|
|
1615
|
+
const { vm } = await DefaultRubyVM(module, Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options === null || options === void 0 ? void 0 : options.env) }));
|
|
1608
1616
|
await mainWithRubyVM(vm);
|
|
1609
1617
|
};
|
|
1610
1618
|
/**
|
|
1611
1619
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Component.
|
|
1612
1620
|
*/
|
|
1613
1621
|
const componentMain = async (pkg, options) => {
|
|
1622
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
1614
1623
|
const componentUrl = `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/component`;
|
|
1615
1624
|
const fetchComponentFile = (relativePath) => fetch(`${componentUrl}/${relativePath}`);
|
|
1616
|
-
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { getCoreModule: (relativePath) => {
|
|
1625
|
+
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options.env), getCoreModule: (relativePath) => {
|
|
1617
1626
|
const response = fetchComponentFile(relativePath);
|
|
1618
1627
|
return compileWebAssemblyModule(response);
|
|
1619
1628
|
} }));
|
|
@@ -1672,6 +1681,53 @@
|
|
|
1672
1681
|
}
|
|
1673
1682
|
return rawEvalStyle;
|
|
1674
1683
|
};
|
|
1684
|
+
/**
|
|
1685
|
+
* Parses the data-env attribute as a JSON object string, for example:
|
|
1686
|
+
* data-env='{"RUBY_BOX":"1","MSG":"hello world"}'
|
|
1687
|
+
*
|
|
1688
|
+
* The parsed value must be a non-null object, not an array. Each key must not
|
|
1689
|
+
* contain "=" or NUL, and each value must be a string.
|
|
1690
|
+
*
|
|
1691
|
+
* JSON is used instead of a shell-like KEY=value list so keys and values can
|
|
1692
|
+
* contain spaces and values can contain "=" without custom escaping rules.
|
|
1693
|
+
*/
|
|
1694
|
+
const parseDataEnv = (tag) => {
|
|
1695
|
+
const rawEnv = tag === null || tag === void 0 ? void 0 : tag.getAttribute("data-env");
|
|
1696
|
+
if (!rawEnv) {
|
|
1697
|
+
return {};
|
|
1698
|
+
}
|
|
1699
|
+
const trimmedEnv = rawEnv.trim();
|
|
1700
|
+
if (!trimmedEnv) {
|
|
1701
|
+
return {};
|
|
1702
|
+
}
|
|
1703
|
+
let parsedEnv;
|
|
1704
|
+
try {
|
|
1705
|
+
parsedEnv = JSON.parse(trimmedEnv);
|
|
1706
|
+
}
|
|
1707
|
+
catch (error) {
|
|
1708
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
1709
|
+
return {};
|
|
1710
|
+
}
|
|
1711
|
+
if (typeof parsedEnv !== "object" ||
|
|
1712
|
+
parsedEnv === null ||
|
|
1713
|
+
Array.isArray(parsedEnv)) {
|
|
1714
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
1715
|
+
return {};
|
|
1716
|
+
}
|
|
1717
|
+
return Object.entries(parsedEnv).reduce((env, [key, value]) => {
|
|
1718
|
+
if (key.includes("=") || key.includes("\0")) {
|
|
1719
|
+
console.warn(`data-env key must not contain "=" or NUL. ${key} is ignored.`);
|
|
1720
|
+
return env;
|
|
1721
|
+
}
|
|
1722
|
+
// POSIX environment values may contain arbitrary bytes, but data-env only accepts strings.
|
|
1723
|
+
if (typeof value !== "string") {
|
|
1724
|
+
console.warn(`data-env value for ${key} must be a string. It is ignored.`);
|
|
1725
|
+
return env;
|
|
1726
|
+
}
|
|
1727
|
+
env[key] = value;
|
|
1728
|
+
return env;
|
|
1729
|
+
}, {});
|
|
1730
|
+
};
|
|
1675
1731
|
const loadScriptAsync = async (tag) => {
|
|
1676
1732
|
const evalStyle = deriveEvalStyle(tag);
|
|
1677
1733
|
// Inline comments can be written with the src attribute of the script tag.
|
package/dist/browser.umd.js
CHANGED
|
@@ -778,9 +778,16 @@
|
|
|
778
778
|
initComponent = async (jsRuntime) => {
|
|
779
779
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
780
780
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
781
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
782
|
+
var _a;
|
|
783
|
+
return Array.from(new Map([
|
|
784
|
+
...cli.environment.getEnvironment(),
|
|
785
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
786
|
+
]).entries());
|
|
787
|
+
} }) : cli.environment;
|
|
781
788
|
const importObject = {
|
|
782
789
|
"ruby:js/js-runtime": jsRuntime,
|
|
783
|
-
"wasi:cli/environment":
|
|
790
|
+
"wasi:cli/environment": environment,
|
|
784
791
|
"wasi:cli/exit": cli.exit,
|
|
785
792
|
"wasi:cli/stderr": cli.stderr,
|
|
786
793
|
"wasi:cli/stdin": cli.stdin,
|
|
@@ -8,9 +8,10 @@ const vm_js_1 = require("./vm.js");
|
|
|
8
8
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
|
|
9
9
|
*/
|
|
10
10
|
const main = async (pkg, options) => {
|
|
11
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
11
12
|
const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
|
|
12
13
|
const module = await compileWebAssemblyModule(response);
|
|
13
|
-
const { vm } = await (0, browser_js_1.DefaultRubyVM)(module, options);
|
|
14
|
+
const { vm } = await (0, browser_js_1.DefaultRubyVM)(module, Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options === null || options === void 0 ? void 0 : options.env) }));
|
|
14
15
|
await mainWithRubyVM(vm);
|
|
15
16
|
};
|
|
16
17
|
exports.main = main;
|
|
@@ -18,9 +19,10 @@ exports.main = main;
|
|
|
18
19
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Component.
|
|
19
20
|
*/
|
|
20
21
|
const componentMain = async (pkg, options) => {
|
|
22
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
21
23
|
const componentUrl = `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/component`;
|
|
22
24
|
const fetchComponentFile = (relativePath) => fetch(`${componentUrl}/${relativePath}`);
|
|
23
|
-
const { vm } = await vm_js_1.RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { getCoreModule: (relativePath) => {
|
|
25
|
+
const { vm } = await vm_js_1.RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options.env), getCoreModule: (relativePath) => {
|
|
24
26
|
const response = fetchComponentFile(relativePath);
|
|
25
27
|
return compileWebAssemblyModule(response);
|
|
26
28
|
} }));
|
|
@@ -80,6 +82,53 @@ const deriveEvalStyle = (tag) => {
|
|
|
80
82
|
}
|
|
81
83
|
return rawEvalStyle;
|
|
82
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* Parses the data-env attribute as a JSON object string, for example:
|
|
87
|
+
* data-env='{"RUBY_BOX":"1","MSG":"hello world"}'
|
|
88
|
+
*
|
|
89
|
+
* The parsed value must be a non-null object, not an array. Each key must not
|
|
90
|
+
* contain "=" or NUL, and each value must be a string.
|
|
91
|
+
*
|
|
92
|
+
* JSON is used instead of a shell-like KEY=value list so keys and values can
|
|
93
|
+
* contain spaces and values can contain "=" without custom escaping rules.
|
|
94
|
+
*/
|
|
95
|
+
const parseDataEnv = (tag) => {
|
|
96
|
+
const rawEnv = tag === null || tag === void 0 ? void 0 : tag.getAttribute("data-env");
|
|
97
|
+
if (!rawEnv) {
|
|
98
|
+
return {};
|
|
99
|
+
}
|
|
100
|
+
const trimmedEnv = rawEnv.trim();
|
|
101
|
+
if (!trimmedEnv) {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
let parsedEnv;
|
|
105
|
+
try {
|
|
106
|
+
parsedEnv = JSON.parse(trimmedEnv);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
if (typeof parsedEnv !== "object" ||
|
|
113
|
+
parsedEnv === null ||
|
|
114
|
+
Array.isArray(parsedEnv)) {
|
|
115
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
116
|
+
return {};
|
|
117
|
+
}
|
|
118
|
+
return Object.entries(parsedEnv).reduce((env, [key, value]) => {
|
|
119
|
+
if (key.includes("=") || key.includes("\0")) {
|
|
120
|
+
console.warn(`data-env key must not contain "=" or NUL. ${key} is ignored.`);
|
|
121
|
+
return env;
|
|
122
|
+
}
|
|
123
|
+
// POSIX environment values may contain arbitrary bytes, but data-env only accepts strings.
|
|
124
|
+
if (typeof value !== "string") {
|
|
125
|
+
console.warn(`data-env value for ${key} must be a string. It is ignored.`);
|
|
126
|
+
return env;
|
|
127
|
+
}
|
|
128
|
+
env[key] = value;
|
|
129
|
+
return env;
|
|
130
|
+
}, {});
|
|
131
|
+
};
|
|
83
132
|
const loadScriptAsync = async (tag) => {
|
|
84
133
|
const evalStyle = deriveEvalStyle(tag);
|
|
85
134
|
// Inline comments can be written with the src attribute of the script tag.
|
package/dist/cjs/vm.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export type RubyInitComponentOptions = {
|
|
|
37
37
|
* WASI Preview 2 implementation, typically imported from `import * as wasip2 from "@bytecodealliance/preview2-shim"`
|
|
38
38
|
*/
|
|
39
39
|
wasip2: any;
|
|
40
|
+
/**
|
|
41
|
+
* Environment variables to pass to the Ruby VM.
|
|
42
|
+
*/
|
|
43
|
+
env?: Record<string, string> | undefined;
|
|
40
44
|
/**
|
|
41
45
|
* The arguments to pass to the Ruby VM. Note that the first argument must be the Ruby program name.
|
|
42
46
|
*
|
package/dist/cjs/vm.js
CHANGED
|
@@ -83,9 +83,16 @@ class RubyVM {
|
|
|
83
83
|
initComponent = async (jsRuntime) => {
|
|
84
84
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
85
85
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
86
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
87
|
+
var _a;
|
|
88
|
+
return Array.from(new Map([
|
|
89
|
+
...cli.environment.getEnvironment(),
|
|
90
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
91
|
+
]).entries());
|
|
92
|
+
} }) : cli.environment;
|
|
86
93
|
const importObject = {
|
|
87
94
|
"ruby:js/js-runtime": jsRuntime,
|
|
88
|
-
"wasi:cli/environment":
|
|
95
|
+
"wasi:cli/environment": environment,
|
|
89
96
|
"wasi:cli/exit": cli.exit,
|
|
90
97
|
"wasi:cli/stderr": cli.stderr,
|
|
91
98
|
"wasi:cli/stdin": cli.stdin,
|
|
@@ -5,18 +5,20 @@ import { RubyVM } from "./vm.js";
|
|
|
5
5
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
|
|
6
6
|
*/
|
|
7
7
|
export const main = async (pkg, options) => {
|
|
8
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
8
9
|
const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
|
|
9
10
|
const module = await compileWebAssemblyModule(response);
|
|
10
|
-
const { vm } = await DefaultRubyVM(module, options);
|
|
11
|
+
const { vm } = await DefaultRubyVM(module, Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options === null || options === void 0 ? void 0 : options.env) }));
|
|
11
12
|
await mainWithRubyVM(vm);
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Component.
|
|
15
16
|
*/
|
|
16
17
|
export const componentMain = async (pkg, options) => {
|
|
18
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
17
19
|
const componentUrl = `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/component`;
|
|
18
20
|
const fetchComponentFile = (relativePath) => fetch(`${componentUrl}/${relativePath}`);
|
|
19
|
-
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { getCoreModule: (relativePath) => {
|
|
21
|
+
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options.env), getCoreModule: (relativePath) => {
|
|
20
22
|
const response = fetchComponentFile(relativePath);
|
|
21
23
|
return compileWebAssemblyModule(response);
|
|
22
24
|
} }));
|
|
@@ -75,6 +77,53 @@ const deriveEvalStyle = (tag) => {
|
|
|
75
77
|
}
|
|
76
78
|
return rawEvalStyle;
|
|
77
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Parses the data-env attribute as a JSON object string, for example:
|
|
82
|
+
* data-env='{"RUBY_BOX":"1","MSG":"hello world"}'
|
|
83
|
+
*
|
|
84
|
+
* The parsed value must be a non-null object, not an array. Each key must not
|
|
85
|
+
* contain "=" or NUL, and each value must be a string.
|
|
86
|
+
*
|
|
87
|
+
* JSON is used instead of a shell-like KEY=value list so keys and values can
|
|
88
|
+
* contain spaces and values can contain "=" without custom escaping rules.
|
|
89
|
+
*/
|
|
90
|
+
const parseDataEnv = (tag) => {
|
|
91
|
+
const rawEnv = tag === null || tag === void 0 ? void 0 : tag.getAttribute("data-env");
|
|
92
|
+
if (!rawEnv) {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
const trimmedEnv = rawEnv.trim();
|
|
96
|
+
if (!trimmedEnv) {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
let parsedEnv;
|
|
100
|
+
try {
|
|
101
|
+
parsedEnv = JSON.parse(trimmedEnv);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
if (typeof parsedEnv !== "object" ||
|
|
108
|
+
parsedEnv === null ||
|
|
109
|
+
Array.isArray(parsedEnv)) {
|
|
110
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
return Object.entries(parsedEnv).reduce((env, [key, value]) => {
|
|
114
|
+
if (key.includes("=") || key.includes("\0")) {
|
|
115
|
+
console.warn(`data-env key must not contain "=" or NUL. ${key} is ignored.`);
|
|
116
|
+
return env;
|
|
117
|
+
}
|
|
118
|
+
// POSIX environment values may contain arbitrary bytes, but data-env only accepts strings.
|
|
119
|
+
if (typeof value !== "string") {
|
|
120
|
+
console.warn(`data-env value for ${key} must be a string. It is ignored.`);
|
|
121
|
+
return env;
|
|
122
|
+
}
|
|
123
|
+
env[key] = value;
|
|
124
|
+
return env;
|
|
125
|
+
}, {});
|
|
126
|
+
};
|
|
78
127
|
const loadScriptAsync = async (tag) => {
|
|
79
128
|
const evalStyle = deriveEvalStyle(tag);
|
|
80
129
|
// Inline comments can be written with the src attribute of the script tag.
|
package/dist/esm/vm.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export type RubyInitComponentOptions = {
|
|
|
37
37
|
* WASI Preview 2 implementation, typically imported from `import * as wasip2 from "@bytecodealliance/preview2-shim"`
|
|
38
38
|
*/
|
|
39
39
|
wasip2: any;
|
|
40
|
+
/**
|
|
41
|
+
* Environment variables to pass to the Ruby VM.
|
|
42
|
+
*/
|
|
43
|
+
env?: Record<string, string> | undefined;
|
|
40
44
|
/**
|
|
41
45
|
* The arguments to pass to the Ruby VM. Note that the first argument must be the Ruby program name.
|
|
42
46
|
*
|
package/dist/esm/vm.js
CHANGED
|
@@ -79,9 +79,16 @@ export class RubyVM {
|
|
|
79
79
|
initComponent = async (jsRuntime) => {
|
|
80
80
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
81
81
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
82
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
83
|
+
var _a;
|
|
84
|
+
return Array.from(new Map([
|
|
85
|
+
...cli.environment.getEnvironment(),
|
|
86
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
87
|
+
]).entries());
|
|
88
|
+
} }) : cli.environment;
|
|
82
89
|
const importObject = {
|
|
83
90
|
"ruby:js/js-runtime": jsRuntime,
|
|
84
|
-
"wasi:cli/environment":
|
|
91
|
+
"wasi:cli/environment": environment,
|
|
85
92
|
"wasi:cli/exit": cli.exit,
|
|
86
93
|
"wasi:cli/stderr": cli.stderr,
|
|
87
94
|
"wasi:cli/stdin": cli.stdin,
|
package/dist/index.umd.js
CHANGED
|
@@ -768,9 +768,16 @@
|
|
|
768
768
|
initComponent = async (jsRuntime) => {
|
|
769
769
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
770
770
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
771
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
772
|
+
var _a;
|
|
773
|
+
return Array.from(new Map([
|
|
774
|
+
...cli.environment.getEnvironment(),
|
|
775
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
776
|
+
]).entries());
|
|
777
|
+
} }) : cli.environment;
|
|
771
778
|
const importObject = {
|
|
772
779
|
"ruby:js/js-runtime": jsRuntime,
|
|
773
|
-
"wasi:cli/environment":
|
|
780
|
+
"wasi:cli/environment": environment,
|
|
774
781
|
"wasi:cli/exit": cli.exit,
|
|
775
782
|
"wasi:cli/stderr": cli.stderr,
|
|
776
783
|
"wasi:cli/stdin": cli.stdin,
|