@bytecodealliance/jco 0.4.0 → 0.4.2
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/README.md +35 -26
- package/api.mjs +23 -53
- package/cli.mjs +54 -55
- package/js-component-bindgen-component.core.wasm +0 -0
- package/package.json +7 -4
- package/wasm-tools.core.wasm +0 -0
package/README.md
CHANGED
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
|
|
19
19
|
Features include:
|
|
20
20
|
|
|
21
|
+
* Creating WebAssembly Components from JavaScript sources and a WIT world
|
|
21
22
|
* "Transpiling" Wasm Component binaries into ES modules that can run in any JS environment.
|
|
22
|
-
* Optimization helpers for Components via Binaryen
|
|
23
|
+
* Optimization helpers for Components via Binaryen.
|
|
23
24
|
* Component builds of [Wasm Tools](https://github.com/bytecodealliance/wasm-tools) helpers, available for use as a library or CLI commands for use in native JS environments.
|
|
24
25
|
|
|
25
|
-
For creating components, see the [Cargo Component](https://github.com/bytecodealliance/cargo-Component) project for Rust and [Wit Bindgen](https://github.com/bytecodealliance/wit-bindgen) for various guest bindgen helpers.
|
|
26
|
+
For creating components in other languages, see the [Cargo Component](https://github.com/bytecodealliance/cargo-Component) project for Rust and [Wit Bindgen](https://github.com/bytecodealliance/wit-bindgen) for various guest bindgen helpers.
|
|
26
27
|
|
|
27
28
|
> **Note**: This is an experimental project, no guarantees are provided for stability or support and breaking changes may be made in future.
|
|
28
29
|
|
|
@@ -38,10 +39,42 @@ jco can be used as either a library or as a CLI via the `jco` CLI command.
|
|
|
38
39
|
|
|
39
40
|
See the [example workflow](EXAMPLE.md) page for a full usage example.
|
|
40
41
|
|
|
42
|
+
## CLI
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
Usage: jco <command> [options]
|
|
46
|
+
|
|
47
|
+
jco - WebAssembly JS Component Tools
|
|
48
|
+
JS Component Transpilation Bindgen & Wasm Tools for JS
|
|
49
|
+
|
|
50
|
+
Options:
|
|
51
|
+
-V, --version output the version number
|
|
52
|
+
-h, --help display help for command
|
|
53
|
+
|
|
54
|
+
Commands:
|
|
55
|
+
componentize [options] <js-source> Create a component from a JavaScript module
|
|
56
|
+
transpile [options] <component-path> Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution
|
|
57
|
+
opt [options] <component-file> optimizes a Wasm component, including running wasm-opt Binaryen optimizations
|
|
58
|
+
wit [options] <component-path> extract the WIT from a WebAssembly Component [wasm-tools component wit]
|
|
59
|
+
print [options] <input> print the WebAssembly WAT text for a binary file [wasm-tools print]
|
|
60
|
+
metadata-show [options] [module] extract the producer metadata for a Wasm binary [wasm-tools metadata show]
|
|
61
|
+
metadata-add [options] [module] add producer metadata for a Wasm binary [wasm-tools metadata add]
|
|
62
|
+
parse [options] <input> parses the Wasm text format into a binary file [wasm-tools parse]
|
|
63
|
+
new [options] <core-module> create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]
|
|
64
|
+
embed [options] [core-module] embed the component typing section into a core Wasm module [wasm-tools component embed]
|
|
65
|
+
help [command] display help for command
|
|
66
|
+
```
|
|
67
|
+
|
|
41
68
|
## API
|
|
42
69
|
|
|
43
70
|
The below is an outline of the available API functions, see [api.d.ts](api.d.ts) file for the exact options.
|
|
44
71
|
|
|
72
|
+
#### `componentize(jsSource: String, witWorld: String, opts?): Promise<{ component: Uint8Array }>`
|
|
73
|
+
|
|
74
|
+
Creates a component from a JS file and WIT world definition, via a Spidermonkey engine embedding.
|
|
75
|
+
|
|
76
|
+
See [ComponentizeJS](https://github.com/bytecodealliance/componentize-js) for more details on this process.
|
|
77
|
+
|
|
45
78
|
#### `transpile(component: Uint8Array, opts?): Promise<{ files: Record<string, Uint8Array> }>`
|
|
46
79
|
|
|
47
80
|
Transpile a Component to JS.
|
|
@@ -92,30 +125,6 @@ Parse a compoment WAT to output a Component binary.
|
|
|
92
125
|
|
|
93
126
|
Add new producer metadata to a component or core Wasm binary.
|
|
94
127
|
|
|
95
|
-
## CLI
|
|
96
|
-
|
|
97
|
-
```shell
|
|
98
|
-
Usage: jco <command> [options]
|
|
99
|
-
|
|
100
|
-
jco - WebAssembly JS Component Tools
|
|
101
|
-
JS Component Bindgen & Wasm Tools for JS
|
|
102
|
-
|
|
103
|
-
Options:
|
|
104
|
-
-V, --version output the version number
|
|
105
|
-
-h, --help display help for command
|
|
106
|
-
|
|
107
|
-
Commands:
|
|
108
|
-
transpile [options] <component-path> Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution
|
|
109
|
-
opt [options] <component-file> optimizes a Wasm component, including running wasm-opt Binaryen optimizations
|
|
110
|
-
wit [options] <component-path> extract the WIT from a WebAssembly Component [wasm-tools component wit]
|
|
111
|
-
print [options] <input> print the WebAssembly WAT text for a binary file [wasm-tools print]
|
|
112
|
-
metadata [options] [module] extract the producer metadata for a Wasm binary [wasm-tools metadata show]
|
|
113
|
-
parse [options] <input> parses the Wasm text format into a binary file [wasm-tools parse]
|
|
114
|
-
new [options] <core-module> create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]
|
|
115
|
-
embed [options] [core-module] embed the component typing section into a core Wasm module [wasm-tools component embed]
|
|
116
|
-
help [command] display help for command
|
|
117
|
-
```
|
|
118
|
-
|
|
119
128
|
## Contributing
|
|
120
129
|
|
|
121
130
|
Development is based on a standard `npm install && npm run build && npm run test` workflow.
|
package/api.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE__bytecodealliance_componentize_js_a7e85369__ from "@bytecodealliance/componentize-js";
|
|
1
2
|
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
|
|
2
3
|
/******/ var __webpack_modules__ = ({
|
|
3
4
|
|
|
@@ -6835,6 +6836,15 @@ function bisearch(ucs) {
|
|
|
6835
6836
|
}
|
|
6836
6837
|
|
|
6837
6838
|
|
|
6839
|
+
/***/ }),
|
|
6840
|
+
|
|
6841
|
+
/***/ 9291:
|
|
6842
|
+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
6843
|
+
|
|
6844
|
+
var x = y => { var x = {}; __nccwpck_require__.d(x, y); return x; }
|
|
6845
|
+
var y = x => () => x
|
|
6846
|
+
module.exports = x({ ["componentize"]: () => __WEBPACK_EXTERNAL_MODULE__bytecodealliance_componentize_js_a7e85369__.componentize });
|
|
6847
|
+
|
|
6838
6848
|
/***/ }),
|
|
6839
6849
|
|
|
6840
6850
|
/***/ 9491:
|
|
@@ -40303,7 +40313,6 @@ let exports2;
|
|
|
40303
40313
|
let realloc0;
|
|
40304
40314
|
let postReturn0;
|
|
40305
40315
|
let postReturn1;
|
|
40306
|
-
let postReturn2;
|
|
40307
40316
|
const exports = {
|
|
40308
40317
|
parse(arg0) {
|
|
40309
40318
|
const ptr0 = utf8Encode(arg0, realloc0, memory0);
|
|
@@ -40713,7 +40722,7 @@ const exports = {
|
|
|
40713
40722
|
const base9 = dataView(memory0).getInt32(ret + 4, true);
|
|
40714
40723
|
const result9 = [];
|
|
40715
40724
|
for (let i = 0; i < len9; i++) {
|
|
40716
|
-
const base = base9 + i *
|
|
40725
|
+
const base = base9 + i * 36;
|
|
40717
40726
|
let variant2;
|
|
40718
40727
|
switch (dataView(memory0).getUint8(base + 0, true)) {
|
|
40719
40728
|
case 0: {
|
|
@@ -40750,8 +40759,8 @@ const exports = {
|
|
|
40750
40759
|
throw new TypeError('invalid variant discriminant for ModuleMetaType');
|
|
40751
40760
|
}
|
|
40752
40761
|
}
|
|
40753
|
-
const len8 = dataView(memory0).getInt32(base +
|
|
40754
|
-
const base8 = dataView(memory0).getInt32(base +
|
|
40762
|
+
const len8 = dataView(memory0).getInt32(base + 32, true);
|
|
40763
|
+
const base8 = dataView(memory0).getInt32(base + 28, true);
|
|
40755
40764
|
const result8 = [];
|
|
40756
40765
|
for (let i = 0; i < len8; i++) {
|
|
40757
40766
|
const base = base8 + i * 16;
|
|
@@ -40776,6 +40785,7 @@ const exports = {
|
|
|
40776
40785
|
result9.push({
|
|
40777
40786
|
name: variant2,
|
|
40778
40787
|
metaType: variant3,
|
|
40788
|
+
range: [dataView(memory0).getInt32(base + 20, true) >>> 0, dataView(memory0).getInt32(base + 24, true) >>> 0],
|
|
40779
40789
|
producers: result8,
|
|
40780
40790
|
});
|
|
40781
40791
|
}
|
|
@@ -40872,49 +40882,6 @@ const exports = {
|
|
|
40872
40882
|
}
|
|
40873
40883
|
return variant10.val;
|
|
40874
40884
|
},
|
|
40875
|
-
extractCoreModules(arg0) {
|
|
40876
|
-
const val0 = arg0;
|
|
40877
|
-
const len0 = val0.byteLength;
|
|
40878
|
-
const ptr0 = realloc0(0, 0, 1, len0 * 1);
|
|
40879
|
-
const src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
|
|
40880
|
-
(new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
|
|
40881
|
-
const ret = exports1['exports#extract-core-modules'](ptr0, len0);
|
|
40882
|
-
let variant3;
|
|
40883
|
-
switch (dataView(memory0).getUint8(ret + 0, true)) {
|
|
40884
|
-
case 0: {
|
|
40885
|
-
const len1 = dataView(memory0).getInt32(ret + 8, true);
|
|
40886
|
-
const base1 = dataView(memory0).getInt32(ret + 4, true);
|
|
40887
|
-
const result1 = [];
|
|
40888
|
-
for (let i = 0; i < len1; i++) {
|
|
40889
|
-
const base = base1 + i * 8;
|
|
40890
|
-
result1.push([dataView(memory0).getInt32(base + 0, true) >>> 0, dataView(memory0).getInt32(base + 4, true) >>> 0]);
|
|
40891
|
-
}
|
|
40892
|
-
variant3= {
|
|
40893
|
-
tag: 'ok',
|
|
40894
|
-
val: result1
|
|
40895
|
-
};
|
|
40896
|
-
break;
|
|
40897
|
-
}
|
|
40898
|
-
case 1: {
|
|
40899
|
-
const ptr2 = dataView(memory0).getInt32(ret + 4, true);
|
|
40900
|
-
const len2 = dataView(memory0).getInt32(ret + 8, true);
|
|
40901
|
-
const result2 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr2, len2));
|
|
40902
|
-
variant3= {
|
|
40903
|
-
tag: 'err',
|
|
40904
|
-
val: result2
|
|
40905
|
-
};
|
|
40906
|
-
break;
|
|
40907
|
-
}
|
|
40908
|
-
default: {
|
|
40909
|
-
throw new TypeError('invalid variant discriminant for expected');
|
|
40910
|
-
}
|
|
40911
|
-
}
|
|
40912
|
-
postReturn2(ret);
|
|
40913
|
-
if (variant3.tag === 'err') {
|
|
40914
|
-
throw new ComponentError(variant3.val);
|
|
40915
|
-
}
|
|
40916
|
-
return variant3.val;
|
|
40917
|
-
},
|
|
40918
40885
|
|
|
40919
40886
|
};
|
|
40920
40887
|
|
|
@@ -40941,7 +40908,6 @@ const $init = (async() => {
|
|
|
40941
40908
|
realloc0 = exports1.cabi_realloc;
|
|
40942
40909
|
postReturn0 = exports1['cabi_post_exports#component-embed'];
|
|
40943
40910
|
postReturn1 = exports1['cabi_post_exports#metadata-show'];
|
|
40944
|
-
postReturn2 = exports1['cabi_post_exports#extract-core-modules'];
|
|
40945
40911
|
})();
|
|
40946
40912
|
|
|
40947
40913
|
await $init;
|
|
@@ -40964,11 +40930,13 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
40964
40930
|
/* harmony export */ "S0": () => (/* binding */ print),
|
|
40965
40931
|
/* harmony export */ "Xs": () => (/* binding */ metadataAdd),
|
|
40966
40932
|
/* harmony export */ "YO": () => (/* binding */ componentWit),
|
|
40967
|
-
/* harmony export */ "eL": () => (/* binding */ metadataShow)
|
|
40933
|
+
/* harmony export */ "eL": () => (/* binding */ metadataShow),
|
|
40934
|
+
/* harmony export */ "he": () => (/* reexport safe */ _bytecodealliance_componentize_js__WEBPACK_IMPORTED_MODULE_3__.componentize)
|
|
40968
40935
|
/* harmony export */ });
|
|
40969
40936
|
/* harmony import */ var _cmd_opt_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(5862);
|
|
40970
40937
|
/* harmony import */ var _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(2229);
|
|
40971
40938
|
/* harmony import */ var _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(8980);
|
|
40939
|
+
/* harmony import */ var _bytecodealliance_componentize_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(9291);
|
|
40972
40940
|
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd_opt_js__WEBPACK_IMPORTED_MODULE_0__, _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_1__, _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__]);
|
|
40973
40941
|
([_cmd_opt_js__WEBPACK_IMPORTED_MODULE_0__, _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_1__, _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
40974
40942
|
|
|
@@ -40976,6 +40944,7 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd
|
|
|
40976
40944
|
|
|
40977
40945
|
const { parse, print, componentNew, componentWit, componentEmbed, metadataAdd, metadataShow } = _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__/* .exports */ .I;
|
|
40978
40946
|
|
|
40947
|
+
|
|
40979
40948
|
__webpack_async_result__();
|
|
40980
40949
|
} catch(e) { __webpack_async_result__(e); } });
|
|
40981
40950
|
|
|
@@ -41004,7 +40973,7 @@ _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies_
|
|
|
41004
40973
|
|
|
41005
40974
|
|
|
41006
40975
|
|
|
41007
|
-
const {
|
|
40976
|
+
const { metadataShow, print } = _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__/* .exports */ .I;
|
|
41008
40977
|
|
|
41009
40978
|
let WASM_OPT;
|
|
41010
40979
|
try {
|
|
@@ -41060,7 +41029,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
41060
41029
|
const showSpinner = (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .getShowSpinner */ .AZ)();
|
|
41061
41030
|
let spinner;
|
|
41062
41031
|
try {
|
|
41063
|
-
const coreModules =
|
|
41032
|
+
const coreModules = metadataShow(componentBytes).slice(1, -1).map(({ range }) => range);
|
|
41064
41033
|
|
|
41065
41034
|
let completed = 0;
|
|
41066
41035
|
const spinnerText = () => chalk_template__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z`{cyan ${completed} / ${coreModules.length}} Running Binaryen on WebAssembly Component Internal Core Modules \n`;
|
|
@@ -41137,7 +41106,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
41137
41106
|
* @param {Uint8Array} source
|
|
41138
41107
|
* @returns {Promise<Uint8Array>}
|
|
41139
41108
|
*/
|
|
41140
|
-
async function wasmOpt (source, args = ['-
|
|
41109
|
+
async function wasmOpt (source, args = ['-O1', '--low-memory-unused', '--enable-bulk-memory']) {
|
|
41141
41110
|
try {
|
|
41142
41111
|
return await (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .spawnIOTmp */ .np)(WASM_OPT, source, [
|
|
41143
41112
|
...args, '-o'
|
|
@@ -41868,11 +41837,12 @@ module.exports = JSON.parse('{"dots":{"interval":80,"frames":["⠋","⠙","⠹",
|
|
|
41868
41837
|
/******/ var __webpack_exports__componentEmbed = __webpack_exports__.Ch;
|
|
41869
41838
|
/******/ var __webpack_exports__componentNew = __webpack_exports__.LM;
|
|
41870
41839
|
/******/ var __webpack_exports__componentWit = __webpack_exports__.YO;
|
|
41840
|
+
/******/ var __webpack_exports__componentize = __webpack_exports__.he;
|
|
41871
41841
|
/******/ var __webpack_exports__metadataAdd = __webpack_exports__.Xs;
|
|
41872
41842
|
/******/ var __webpack_exports__metadataShow = __webpack_exports__.eL;
|
|
41873
41843
|
/******/ var __webpack_exports__opt = __webpack_exports__.MD;
|
|
41874
41844
|
/******/ var __webpack_exports__parse = __webpack_exports__.Qc;
|
|
41875
41845
|
/******/ var __webpack_exports__print = __webpack_exports__.S0;
|
|
41876
41846
|
/******/ var __webpack_exports__transpile = __webpack_exports__.LZ;
|
|
41877
|
-
/******/ export { __webpack_exports__componentEmbed as componentEmbed, __webpack_exports__componentNew as componentNew, __webpack_exports__componentWit as componentWit, __webpack_exports__metadataAdd as metadataAdd, __webpack_exports__metadataShow as metadataShow, __webpack_exports__opt as opt, __webpack_exports__parse as parse, __webpack_exports__print as print, __webpack_exports__transpile as transpile };
|
|
41847
|
+
/******/ export { __webpack_exports__componentEmbed as componentEmbed, __webpack_exports__componentNew as componentNew, __webpack_exports__componentWit as componentWit, __webpack_exports__componentize as componentize, __webpack_exports__metadataAdd as metadataAdd, __webpack_exports__metadataShow as metadataShow, __webpack_exports__opt as opt, __webpack_exports__parse as parse, __webpack_exports__print as print, __webpack_exports__transpile as transpile };
|
|
41878
41848
|
/******/
|
package/cli.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE__bytecodealliance_componentize_js_a7e85369__ from "@bytecodealliance/componentize-js";
|
|
3
4
|
/******/ var __webpack_modules__ = ({
|
|
4
5
|
|
|
5
6
|
/***/ 2068:
|
|
@@ -43627,7 +43628,6 @@ let exports2;
|
|
|
43627
43628
|
let realloc0;
|
|
43628
43629
|
let postReturn0;
|
|
43629
43630
|
let postReturn1;
|
|
43630
|
-
let postReturn2;
|
|
43631
43631
|
const exports = {
|
|
43632
43632
|
parse(arg0) {
|
|
43633
43633
|
const ptr0 = utf8Encode(arg0, realloc0, memory0);
|
|
@@ -44037,7 +44037,7 @@ const exports = {
|
|
|
44037
44037
|
const base9 = dataView(memory0).getInt32(ret + 4, true);
|
|
44038
44038
|
const result9 = [];
|
|
44039
44039
|
for (let i = 0; i < len9; i++) {
|
|
44040
|
-
const base = base9 + i *
|
|
44040
|
+
const base = base9 + i * 36;
|
|
44041
44041
|
let variant2;
|
|
44042
44042
|
switch (dataView(memory0).getUint8(base + 0, true)) {
|
|
44043
44043
|
case 0: {
|
|
@@ -44074,8 +44074,8 @@ const exports = {
|
|
|
44074
44074
|
throw new TypeError('invalid variant discriminant for ModuleMetaType');
|
|
44075
44075
|
}
|
|
44076
44076
|
}
|
|
44077
|
-
const len8 = dataView(memory0).getInt32(base +
|
|
44078
|
-
const base8 = dataView(memory0).getInt32(base +
|
|
44077
|
+
const len8 = dataView(memory0).getInt32(base + 32, true);
|
|
44078
|
+
const base8 = dataView(memory0).getInt32(base + 28, true);
|
|
44079
44079
|
const result8 = [];
|
|
44080
44080
|
for (let i = 0; i < len8; i++) {
|
|
44081
44081
|
const base = base8 + i * 16;
|
|
@@ -44100,6 +44100,7 @@ const exports = {
|
|
|
44100
44100
|
result9.push({
|
|
44101
44101
|
name: variant2,
|
|
44102
44102
|
metaType: variant3,
|
|
44103
|
+
range: [dataView(memory0).getInt32(base + 20, true) >>> 0, dataView(memory0).getInt32(base + 24, true) >>> 0],
|
|
44103
44104
|
producers: result8,
|
|
44104
44105
|
});
|
|
44105
44106
|
}
|
|
@@ -44196,49 +44197,6 @@ const exports = {
|
|
|
44196
44197
|
}
|
|
44197
44198
|
return variant10.val;
|
|
44198
44199
|
},
|
|
44199
|
-
extractCoreModules(arg0) {
|
|
44200
|
-
const val0 = arg0;
|
|
44201
|
-
const len0 = val0.byteLength;
|
|
44202
|
-
const ptr0 = realloc0(0, 0, 1, len0 * 1);
|
|
44203
|
-
const src0 = new Uint8Array(val0.buffer || val0, val0.byteOffset, len0 * 1);
|
|
44204
|
-
(new Uint8Array(memory0.buffer, ptr0, len0 * 1)).set(src0);
|
|
44205
|
-
const ret = exports1['exports#extract-core-modules'](ptr0, len0);
|
|
44206
|
-
let variant3;
|
|
44207
|
-
switch (dataView(memory0).getUint8(ret + 0, true)) {
|
|
44208
|
-
case 0: {
|
|
44209
|
-
const len1 = dataView(memory0).getInt32(ret + 8, true);
|
|
44210
|
-
const base1 = dataView(memory0).getInt32(ret + 4, true);
|
|
44211
|
-
const result1 = [];
|
|
44212
|
-
for (let i = 0; i < len1; i++) {
|
|
44213
|
-
const base = base1 + i * 8;
|
|
44214
|
-
result1.push([dataView(memory0).getInt32(base + 0, true) >>> 0, dataView(memory0).getInt32(base + 4, true) >>> 0]);
|
|
44215
|
-
}
|
|
44216
|
-
variant3= {
|
|
44217
|
-
tag: 'ok',
|
|
44218
|
-
val: result1
|
|
44219
|
-
};
|
|
44220
|
-
break;
|
|
44221
|
-
}
|
|
44222
|
-
case 1: {
|
|
44223
|
-
const ptr2 = dataView(memory0).getInt32(ret + 4, true);
|
|
44224
|
-
const len2 = dataView(memory0).getInt32(ret + 8, true);
|
|
44225
|
-
const result2 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr2, len2));
|
|
44226
|
-
variant3= {
|
|
44227
|
-
tag: 'err',
|
|
44228
|
-
val: result2
|
|
44229
|
-
};
|
|
44230
|
-
break;
|
|
44231
|
-
}
|
|
44232
|
-
default: {
|
|
44233
|
-
throw new TypeError('invalid variant discriminant for expected');
|
|
44234
|
-
}
|
|
44235
|
-
}
|
|
44236
|
-
postReturn2(ret);
|
|
44237
|
-
if (variant3.tag === 'err') {
|
|
44238
|
-
throw new ComponentError(variant3.val);
|
|
44239
|
-
}
|
|
44240
|
-
return variant3.val;
|
|
44241
|
-
},
|
|
44242
44200
|
|
|
44243
44201
|
};
|
|
44244
44202
|
|
|
@@ -44265,7 +44223,6 @@ const $init = (async() => {
|
|
|
44265
44223
|
realloc0 = exports1.cabi_realloc;
|
|
44266
44224
|
postReturn0 = exports1['cabi_post_exports#component-embed'];
|
|
44267
44225
|
postReturn1 = exports1['cabi_post_exports#metadata-show'];
|
|
44268
|
-
postReturn2 = exports1['cabi_post_exports#extract-core-modules'];
|
|
44269
44226
|
})();
|
|
44270
44227
|
|
|
44271
44228
|
await $init;
|
|
@@ -44273,6 +44230,39 @@ await $init;
|
|
|
44273
44230
|
__webpack_async_result__();
|
|
44274
44231
|
} catch(e) { __webpack_async_result__(e); } }, 1);
|
|
44275
44232
|
|
|
44233
|
+
/***/ }),
|
|
44234
|
+
|
|
44235
|
+
/***/ 3452:
|
|
44236
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
|
|
44237
|
+
|
|
44238
|
+
|
|
44239
|
+
// EXPORTS
|
|
44240
|
+
__nccwpck_require__.d(__webpack_exports__, {
|
|
44241
|
+
"h": () => (/* binding */ componentize)
|
|
44242
|
+
});
|
|
44243
|
+
|
|
44244
|
+
// EXTERNAL MODULE: external "node:fs/promises"
|
|
44245
|
+
var promises_ = __nccwpck_require__(3977);
|
|
44246
|
+
;// CONCATENATED MODULE: external "@bytecodealliance/componentize-js"
|
|
44247
|
+
var x = y => { var x = {}; __nccwpck_require__.d(x, y); return x; }
|
|
44248
|
+
var y = x => () => x
|
|
44249
|
+
const componentize_js_namespaceObject = x({ ["componentize"]: () => __WEBPACK_EXTERNAL_MODULE__bytecodealliance_componentize_js_a7e85369__.componentize });
|
|
44250
|
+
// EXTERNAL MODULE: ./node_modules/chalk-template/index.js
|
|
44251
|
+
var chalk_template = __nccwpck_require__(267);
|
|
44252
|
+
;// CONCATENATED MODULE: ./src/cmd/componentize.js
|
|
44253
|
+
|
|
44254
|
+
|
|
44255
|
+
|
|
44256
|
+
|
|
44257
|
+
async function componentize (jsSource, opts) {
|
|
44258
|
+
const source = await (0,promises_.readFile)(jsSource, 'utf8');
|
|
44259
|
+
const wit = await (0,promises_.readFile)(opts.wit, 'utf8');
|
|
44260
|
+
const { component, imports } = await (0,componentize_js_namespaceObject.componentize)(source, wit);
|
|
44261
|
+
await (0,promises_.writeFile)(opts.out, component);
|
|
44262
|
+
console.log(chalk_template/* default */.Z`{green OK} Successfully written {bold ${opts.out}} with imports (${imports.join(', ')}).`);
|
|
44263
|
+
}
|
|
44264
|
+
|
|
44265
|
+
|
|
44276
44266
|
/***/ }),
|
|
44277
44267
|
|
|
44278
44268
|
/***/ 5862:
|
|
@@ -44298,7 +44288,7 @@ _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies_
|
|
|
44298
44288
|
|
|
44299
44289
|
|
|
44300
44290
|
|
|
44301
|
-
const {
|
|
44291
|
+
const { metadataShow, print } = _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_0__/* .exports */ .I;
|
|
44302
44292
|
|
|
44303
44293
|
let WASM_OPT;
|
|
44304
44294
|
try {
|
|
@@ -44354,7 +44344,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
44354
44344
|
const showSpinner = (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .getShowSpinner */ .AZ)();
|
|
44355
44345
|
let spinner;
|
|
44356
44346
|
try {
|
|
44357
|
-
const coreModules =
|
|
44347
|
+
const coreModules = metadataShow(componentBytes).slice(1, -1).map(({ range }) => range);
|
|
44358
44348
|
|
|
44359
44349
|
let completed = 0;
|
|
44360
44350
|
const spinnerText = () => chalk_template__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z`{cyan ${completed} / ${coreModules.length}} Running Binaryen on WebAssembly Component Internal Core Modules \n`;
|
|
@@ -44431,7 +44421,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
44431
44421
|
* @param {Uint8Array} source
|
|
44432
44422
|
* @returns {Promise<Uint8Array>}
|
|
44433
44423
|
*/
|
|
44434
|
-
async function wasmOpt (source, args = ['-
|
|
44424
|
+
async function wasmOpt (source, args = ['-O1', '--low-memory-unused', '--enable-bulk-memory']) {
|
|
44435
44425
|
try {
|
|
44436
44426
|
return await (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .spawnIOTmp */ .np)(WASM_OPT, source, [
|
|
44437
44427
|
...args, '-o'
|
|
@@ -45123,7 +45113,8 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
45123
45113
|
/* harmony import */ var _cmd_opt_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(5862);
|
|
45124
45114
|
/* harmony import */ var _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(2229);
|
|
45125
45115
|
/* harmony import */ var _cmd_wasm_tools_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(8154);
|
|
45126
|
-
/* harmony import */ var
|
|
45116
|
+
/* harmony import */ var _cmd_componentize_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(3452);
|
|
45117
|
+
/* harmony import */ var chalk_template__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(267);
|
|
45127
45118
|
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd_opt_js__WEBPACK_IMPORTED_MODULE_1__, _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_2__, _cmd_wasm_tools_js__WEBPACK_IMPORTED_MODULE_3__]);
|
|
45128
45119
|
([_cmd_opt_js__WEBPACK_IMPORTED_MODULE_1__, _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_2__, _cmd_wasm_tools_js__WEBPACK_IMPORTED_MODULE_3__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
|
|
45129
45120
|
|
|
@@ -45132,8 +45123,9 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd
|
|
|
45132
45123
|
|
|
45133
45124
|
|
|
45134
45125
|
|
|
45126
|
+
|
|
45135
45127
|
commander__WEBPACK_IMPORTED_MODULE_0__/* .program.name */ .Nx.name('jco')
|
|
45136
|
-
.description(
|
|
45128
|
+
.description(chalk_template__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
|
|
45137
45129
|
.usage('<command> [options]')
|
|
45138
45130
|
.version('0.1.0');
|
|
45139
45131
|
|
|
@@ -45141,6 +45133,14 @@ function myParseInt(value) {
|
|
|
45141
45133
|
return parseInt(value, 10);
|
|
45142
45134
|
}
|
|
45143
45135
|
|
|
45136
|
+
commander__WEBPACK_IMPORTED_MODULE_0__/* .program.command */ .Nx.command('componentize')
|
|
45137
|
+
.description('Create a component from a JavaScript module')
|
|
45138
|
+
.usage('<js-source> -o <component-path>')
|
|
45139
|
+
.argument('<js-source>', 'JS source file to build')
|
|
45140
|
+
.requiredOption('-w, --wit <world>', 'WIT world to build with')
|
|
45141
|
+
.requiredOption('-o, --out <out>', 'output component file')
|
|
45142
|
+
.action(asyncAction(_cmd_componentize_js__WEBPACK_IMPORTED_MODULE_4__/* .componentize */ .h));
|
|
45143
|
+
|
|
45144
45144
|
commander__WEBPACK_IMPORTED_MODULE_0__/* .program.command */ .Nx.command('transpile')
|
|
45145
45145
|
.description('Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution')
|
|
45146
45146
|
.usage('<component-path> -o <out-dir>')
|
|
@@ -45149,7 +45149,6 @@ commander__WEBPACK_IMPORTED_MODULE_0__/* .program.command */ .Nx.command('transp
|
|
|
45149
45149
|
.requiredOption('-o, --out-dir <out-dir>', 'output directory')
|
|
45150
45150
|
.option('-m, --minify', 'minify the JS output (--optimize / opt cmd still required)')
|
|
45151
45151
|
.option('-O, --optimize', 'optimize the component first')
|
|
45152
|
-
.option('-a, --args', 'when using --optimize, custom binaryen argument flags to pass')
|
|
45153
45152
|
.option('--no-typescript', 'do not output TypeScript .d.ts types')
|
|
45154
45153
|
.option('--valid-lifting-optimization', 'optimize component binary validations assuming all lifted values are valid')
|
|
45155
45154
|
.option('-b, --base64-cutoff <bytes>', 'set the byte size under which core Wasm binaries will be inlined as base64', myParseInt)
|
|
@@ -45234,7 +45233,7 @@ function asyncAction (cmd) {
|
|
|
45234
45233
|
catch (e) {
|
|
45235
45234
|
process.stdout.write(`(jsct ${cmd.name}) `);
|
|
45236
45235
|
if (typeof e === 'string') {
|
|
45237
|
-
console.error(
|
|
45236
|
+
console.error(chalk_template__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z`{red.bold Error}: ${e}\n`);
|
|
45238
45237
|
} else {
|
|
45239
45238
|
console.error(e);
|
|
45240
45239
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/jco",
|
|
3
3
|
"description": "JavaScript tooling for working with WebAssembly Components",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"exports": "./api.mjs",
|
|
6
6
|
"types": "api.d.ts",
|
|
7
7
|
"author": "Guy Bedford",
|
|
8
8
|
"bin": {
|
|
9
9
|
"jco": "cli.mjs"
|
|
10
10
|
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@bytecodealliance/componentize-js": "^0.0.1"
|
|
13
|
+
},
|
|
11
14
|
"repository": {
|
|
12
15
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/bytecodealliance/
|
|
16
|
+
"url": "git+https://github.com/bytecodealliance/jco.git"
|
|
14
17
|
},
|
|
15
18
|
"keywords": [
|
|
16
19
|
"Wasm",
|
|
@@ -19,7 +22,7 @@
|
|
|
19
22
|
],
|
|
20
23
|
"license": "(Apache-2.0 WITH LLVM-exception)",
|
|
21
24
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/bytecodealliance/
|
|
25
|
+
"url": "https://github.com/bytecodealliance/jco/issues"
|
|
23
26
|
},
|
|
24
|
-
"homepage": "https://github.com/bytecodealliance/
|
|
27
|
+
"homepage": "https://github.com/bytecodealliance/jco#readme"
|
|
25
28
|
}
|
package/wasm-tools.core.wasm
CHANGED
|
Binary file
|