@ruby/head-wasm-wasi 2.9.3-2.9.4 → 2.9.4-2.10.0
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.iife.js +59 -4
- package/dist/browser.script.umd.js +59 -3
- package/dist/browser.umd.js +8 -1
- package/dist/index.umd.js +8 -1
- package/dist/ruby+stdlib.wasm +0 -0
- package/dist/ruby.debug+stdlib.wasm +0 -0
- package/dist/ruby.wasm +0 -0
- package/package.json +2 -2
|
@@ -2100,9 +2100,16 @@ SOFTWARE.
|
|
|
2100
2100
|
initComponent = async (jsRuntime) => {
|
|
2101
2101
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
2102
2102
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
2103
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
2104
|
+
var _a;
|
|
2105
|
+
return Array.from(new Map([
|
|
2106
|
+
...cli.environment.getEnvironment(),
|
|
2107
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
2108
|
+
]).entries());
|
|
2109
|
+
} }) : cli.environment;
|
|
2103
2110
|
const importObject = {
|
|
2104
2111
|
"ruby:js/js-runtime": jsRuntime,
|
|
2105
|
-
"wasi:cli/environment":
|
|
2112
|
+
"wasi:cli/environment": environment,
|
|
2106
2113
|
"wasi:cli/exit": cli.exit,
|
|
2107
2114
|
"wasi:cli/stderr": cli.stderr,
|
|
2108
2115
|
"wasi:cli/stdin": cli.stdin,
|
|
@@ -2882,9 +2889,10 @@ SOFTWARE.
|
|
|
2882
2889
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
|
|
2883
2890
|
*/
|
|
2884
2891
|
const main$1 = async (pkg, options) => {
|
|
2892
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
2885
2893
|
const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
|
|
2886
2894
|
const module = await compileWebAssemblyModule(response);
|
|
2887
|
-
const { vm } = await DefaultRubyVM(module, options);
|
|
2895
|
+
const { vm } = await DefaultRubyVM(module, Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), void 0 ) }));
|
|
2888
2896
|
await mainWithRubyVM(vm);
|
|
2889
2897
|
};
|
|
2890
2898
|
const mainWithRubyVM = async (vm) => {
|
|
@@ -2940,6 +2948,53 @@ SOFTWARE.
|
|
|
2940
2948
|
}
|
|
2941
2949
|
return rawEvalStyle;
|
|
2942
2950
|
};
|
|
2951
|
+
/**
|
|
2952
|
+
* Parses the data-env attribute as a JSON object string, for example:
|
|
2953
|
+
* data-env='{"RUBY_BOX":"1","MSG":"hello world"}'
|
|
2954
|
+
*
|
|
2955
|
+
* The parsed value must be a non-null object, not an array. Each key must not
|
|
2956
|
+
* contain "=" or NUL, and each value must be a string.
|
|
2957
|
+
*
|
|
2958
|
+
* JSON is used instead of a shell-like KEY=value list so keys and values can
|
|
2959
|
+
* contain spaces and values can contain "=" without custom escaping rules.
|
|
2960
|
+
*/
|
|
2961
|
+
const parseDataEnv = (tag) => {
|
|
2962
|
+
const rawEnv = tag === null || tag === void 0 ? void 0 : tag.getAttribute("data-env");
|
|
2963
|
+
if (!rawEnv) {
|
|
2964
|
+
return {};
|
|
2965
|
+
}
|
|
2966
|
+
const trimmedEnv = rawEnv.trim();
|
|
2967
|
+
if (!trimmedEnv) {
|
|
2968
|
+
return {};
|
|
2969
|
+
}
|
|
2970
|
+
let parsedEnv;
|
|
2971
|
+
try {
|
|
2972
|
+
parsedEnv = JSON.parse(trimmedEnv);
|
|
2973
|
+
}
|
|
2974
|
+
catch (error) {
|
|
2975
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
2976
|
+
return {};
|
|
2977
|
+
}
|
|
2978
|
+
if (typeof parsedEnv !== "object" ||
|
|
2979
|
+
parsedEnv === null ||
|
|
2980
|
+
Array.isArray(parsedEnv)) {
|
|
2981
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
2982
|
+
return {};
|
|
2983
|
+
}
|
|
2984
|
+
return Object.entries(parsedEnv).reduce((env, [key, value]) => {
|
|
2985
|
+
if (key.includes("=") || key.includes("\0")) {
|
|
2986
|
+
console.warn(`data-env key must not contain "=" or NUL. ${key} is ignored.`);
|
|
2987
|
+
return env;
|
|
2988
|
+
}
|
|
2989
|
+
// POSIX environment values may contain arbitrary bytes, but data-env only accepts strings.
|
|
2990
|
+
if (typeof value !== "string") {
|
|
2991
|
+
console.warn(`data-env value for ${key} must be a string. It is ignored.`);
|
|
2992
|
+
return env;
|
|
2993
|
+
}
|
|
2994
|
+
env[key] = value;
|
|
2995
|
+
return env;
|
|
2996
|
+
}, {});
|
|
2997
|
+
};
|
|
2943
2998
|
const loadScriptAsync = async (tag) => {
|
|
2944
2999
|
const evalStyle = deriveEvalStyle(tag);
|
|
2945
3000
|
// Inline comments can be written with the src attribute of the script tag.
|
|
@@ -2970,7 +3025,7 @@ SOFTWARE.
|
|
|
2970
3025
|
};
|
|
2971
3026
|
|
|
2972
3027
|
var name = "@ruby/head-wasm-wasi";
|
|
2973
|
-
var version = "2.9.
|
|
3028
|
+
var version = "2.9.4-2.10.0";
|
|
2974
3029
|
var description = "Ruby head built on WASI";
|
|
2975
3030
|
var main = "./dist/cjs/index.js";
|
|
2976
3031
|
var module = "./dist/esm/index.js";
|
|
@@ -3020,7 +3075,7 @@ SOFTWARE.
|
|
|
3020
3075
|
];
|
|
3021
3076
|
var license = "MIT";
|
|
3022
3077
|
var dependencies = {
|
|
3023
|
-
"@ruby/wasm-wasi": "2.9.
|
|
3078
|
+
"@ruby/wasm-wasi": "2.9.4-2.10.0"
|
|
3024
3079
|
};
|
|
3025
3080
|
var _package = {
|
|
3026
3081
|
name: name,
|
|
@@ -823,9 +823,16 @@ Please replace your \`require('ruby-head-wasm-wasi/dist/browser.script.umd');\`
|
|
|
823
823
|
initComponent = async (jsRuntime) => {
|
|
824
824
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
825
825
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
826
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
827
|
+
var _a;
|
|
828
|
+
return Array.from(new Map([
|
|
829
|
+
...cli.environment.getEnvironment(),
|
|
830
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
831
|
+
]).entries());
|
|
832
|
+
} }) : cli.environment;
|
|
826
833
|
const importObject = {
|
|
827
834
|
"ruby:js/js-runtime": jsRuntime,
|
|
828
|
-
"wasi:cli/environment":
|
|
835
|
+
"wasi:cli/environment": environment,
|
|
829
836
|
"wasi:cli/exit": cli.exit,
|
|
830
837
|
"wasi:cli/stderr": cli.stderr,
|
|
831
838
|
"wasi:cli/stdin": cli.stdin,
|
|
@@ -1605,18 +1612,20 @@ Please replace your \`require('ruby-head-wasm-wasi/dist/browser.script.umd');\`
|
|
|
1605
1612
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Core Module.
|
|
1606
1613
|
*/
|
|
1607
1614
|
const main = async (pkg, options) => {
|
|
1615
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
1608
1616
|
const response = fetch(`https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`);
|
|
1609
1617
|
const module = await compileWebAssemblyModule(response);
|
|
1610
|
-
const { vm } = await DefaultRubyVM(module, options);
|
|
1618
|
+
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) }));
|
|
1611
1619
|
await mainWithRubyVM(vm);
|
|
1612
1620
|
};
|
|
1613
1621
|
/**
|
|
1614
1622
|
* The main entry point of `<script type="text/ruby">`-based scripting with WebAssembly Component.
|
|
1615
1623
|
*/
|
|
1616
1624
|
const componentMain = async (pkg, options) => {
|
|
1625
|
+
const scriptEnv = parseDataEnv(document.currentScript);
|
|
1617
1626
|
const componentUrl = `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/component`;
|
|
1618
1627
|
const fetchComponentFile = (relativePath) => fetch(`${componentUrl}/${relativePath}`);
|
|
1619
|
-
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { getCoreModule: (relativePath) => {
|
|
1628
|
+
const { vm } = await RubyVM.instantiateComponent(Object.assign(Object.assign({}, options), { env: Object.assign(Object.assign({}, scriptEnv), options.env), getCoreModule: (relativePath) => {
|
|
1620
1629
|
const response = fetchComponentFile(relativePath);
|
|
1621
1630
|
return compileWebAssemblyModule(response);
|
|
1622
1631
|
} }));
|
|
@@ -1675,6 +1684,53 @@ Please replace your \`require('ruby-head-wasm-wasi/dist/browser.script.umd');\`
|
|
|
1675
1684
|
}
|
|
1676
1685
|
return rawEvalStyle;
|
|
1677
1686
|
};
|
|
1687
|
+
/**
|
|
1688
|
+
* Parses the data-env attribute as a JSON object string, for example:
|
|
1689
|
+
* data-env='{"RUBY_BOX":"1","MSG":"hello world"}'
|
|
1690
|
+
*
|
|
1691
|
+
* The parsed value must be a non-null object, not an array. Each key must not
|
|
1692
|
+
* contain "=" or NUL, and each value must be a string.
|
|
1693
|
+
*
|
|
1694
|
+
* JSON is used instead of a shell-like KEY=value list so keys and values can
|
|
1695
|
+
* contain spaces and values can contain "=" without custom escaping rules.
|
|
1696
|
+
*/
|
|
1697
|
+
const parseDataEnv = (tag) => {
|
|
1698
|
+
const rawEnv = tag === null || tag === void 0 ? void 0 : tag.getAttribute("data-env");
|
|
1699
|
+
if (!rawEnv) {
|
|
1700
|
+
return {};
|
|
1701
|
+
}
|
|
1702
|
+
const trimmedEnv = rawEnv.trim();
|
|
1703
|
+
if (!trimmedEnv) {
|
|
1704
|
+
return {};
|
|
1705
|
+
}
|
|
1706
|
+
let parsedEnv;
|
|
1707
|
+
try {
|
|
1708
|
+
parsedEnv = JSON.parse(trimmedEnv);
|
|
1709
|
+
}
|
|
1710
|
+
catch (error) {
|
|
1711
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
1712
|
+
return {};
|
|
1713
|
+
}
|
|
1714
|
+
if (typeof parsedEnv !== "object" ||
|
|
1715
|
+
parsedEnv === null ||
|
|
1716
|
+
Array.isArray(parsedEnv)) {
|
|
1717
|
+
console.warn(`data-env must be a JSON object string. ${rawEnv} is ignored.`);
|
|
1718
|
+
return {};
|
|
1719
|
+
}
|
|
1720
|
+
return Object.entries(parsedEnv).reduce((env, [key, value]) => {
|
|
1721
|
+
if (key.includes("=") || key.includes("\0")) {
|
|
1722
|
+
console.warn(`data-env key must not contain "=" or NUL. ${key} is ignored.`);
|
|
1723
|
+
return env;
|
|
1724
|
+
}
|
|
1725
|
+
// POSIX environment values may contain arbitrary bytes, but data-env only accepts strings.
|
|
1726
|
+
if (typeof value !== "string") {
|
|
1727
|
+
console.warn(`data-env value for ${key} must be a string. It is ignored.`);
|
|
1728
|
+
return env;
|
|
1729
|
+
}
|
|
1730
|
+
env[key] = value;
|
|
1731
|
+
return env;
|
|
1732
|
+
}, {});
|
|
1733
|
+
};
|
|
1678
1734
|
const loadScriptAsync = async (tag) => {
|
|
1679
1735
|
const evalStyle = deriveEvalStyle(tag);
|
|
1680
1736
|
// 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,
|
package/dist/index.umd.js
CHANGED
|
@@ -771,9 +771,16 @@ Please replace your \`require('ruby-head-wasm-wasi/dist/index.umd');\` with \`re
|
|
|
771
771
|
initComponent = async (jsRuntime) => {
|
|
772
772
|
const { instantiate, getCoreModule, wasip2 } = options;
|
|
773
773
|
const { cli, clocks, filesystem, io, random, sockets, http } = wasip2;
|
|
774
|
+
const environment = options.env ? Object.assign(Object.assign({}, cli.environment), { getEnvironment: () => {
|
|
775
|
+
var _a;
|
|
776
|
+
return Array.from(new Map([
|
|
777
|
+
...cli.environment.getEnvironment(),
|
|
778
|
+
...Object.entries((_a = options.env) !== null && _a !== void 0 ? _a : {}),
|
|
779
|
+
]).entries());
|
|
780
|
+
} }) : cli.environment;
|
|
774
781
|
const importObject = {
|
|
775
782
|
"ruby:js/js-runtime": jsRuntime,
|
|
776
|
-
"wasi:cli/environment":
|
|
783
|
+
"wasi:cli/environment": environment,
|
|
777
784
|
"wasi:cli/exit": cli.exit,
|
|
778
785
|
"wasi:cli/stderr": cli.stderr,
|
|
779
786
|
"wasi:cli/stdin": cli.stdin,
|
package/dist/ruby+stdlib.wasm
CHANGED
|
Binary file
|
|
Binary file
|
package/dist/ruby.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruby/head-wasm-wasi",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.4-2.10.0",
|
|
4
4
|
"description": "Ruby head built on WASI",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@ruby/wasm-wasi": "2.9.
|
|
53
|
+
"@ruby/wasm-wasi": "2.9.4-2.10.0"
|
|
54
54
|
}
|
|
55
55
|
}
|