@bytecodealliance/jco 0.4.1 → 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 -27
- package/api.mjs +17 -3
- package/cli.mjs +48 -5
- package/package.json +4 -1
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,31 +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 Transpilation 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-show [options] [module] extract the producer metadata for a Wasm binary [wasm-tools metadata show]
|
|
113
|
-
metadata-add [options] [module] add producer metadata for a Wasm binary [wasm-tools metadata add]
|
|
114
|
-
parse [options] <input> parses the Wasm text format into a binary file [wasm-tools parse]
|
|
115
|
-
new [options] <core-module> create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]
|
|
116
|
-
embed [options] [core-module] embed the component typing section into a core Wasm module [wasm-tools component embed]
|
|
117
|
-
help [command] display help for command
|
|
118
|
-
```
|
|
119
|
-
|
|
120
128
|
## Contributing
|
|
121
129
|
|
|
122
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:
|
|
@@ -40920,11 +40930,13 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
40920
40930
|
/* harmony export */ "S0": () => (/* binding */ print),
|
|
40921
40931
|
/* harmony export */ "Xs": () => (/* binding */ metadataAdd),
|
|
40922
40932
|
/* harmony export */ "YO": () => (/* binding */ componentWit),
|
|
40923
|
-
/* 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)
|
|
40924
40935
|
/* harmony export */ });
|
|
40925
40936
|
/* harmony import */ var _cmd_opt_js__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(5862);
|
|
40926
40937
|
/* harmony import */ var _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(2229);
|
|
40927
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);
|
|
40928
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__]);
|
|
40929
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__);
|
|
40930
40942
|
|
|
@@ -40932,6 +40944,7 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd
|
|
|
40932
40944
|
|
|
40933
40945
|
const { parse, print, componentNew, componentWit, componentEmbed, metadataAdd, metadataShow } = _obj_wasm_tools_js__WEBPACK_IMPORTED_MODULE_2__/* .exports */ .I;
|
|
40934
40946
|
|
|
40947
|
+
|
|
40935
40948
|
__webpack_async_result__();
|
|
40936
40949
|
} catch(e) { __webpack_async_result__(e); } });
|
|
40937
40950
|
|
|
@@ -41093,7 +41106,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
41093
41106
|
* @param {Uint8Array} source
|
|
41094
41107
|
* @returns {Promise<Uint8Array>}
|
|
41095
41108
|
*/
|
|
41096
|
-
async function wasmOpt (source, args = ['-
|
|
41109
|
+
async function wasmOpt (source, args = ['-O1', '--low-memory-unused', '--enable-bulk-memory']) {
|
|
41097
41110
|
try {
|
|
41098
41111
|
return await (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .spawnIOTmp */ .np)(WASM_OPT, source, [
|
|
41099
41112
|
...args, '-o'
|
|
@@ -41824,11 +41837,12 @@ module.exports = JSON.parse('{"dots":{"interval":80,"frames":["⠋","⠙","⠹",
|
|
|
41824
41837
|
/******/ var __webpack_exports__componentEmbed = __webpack_exports__.Ch;
|
|
41825
41838
|
/******/ var __webpack_exports__componentNew = __webpack_exports__.LM;
|
|
41826
41839
|
/******/ var __webpack_exports__componentWit = __webpack_exports__.YO;
|
|
41840
|
+
/******/ var __webpack_exports__componentize = __webpack_exports__.he;
|
|
41827
41841
|
/******/ var __webpack_exports__metadataAdd = __webpack_exports__.Xs;
|
|
41828
41842
|
/******/ var __webpack_exports__metadataShow = __webpack_exports__.eL;
|
|
41829
41843
|
/******/ var __webpack_exports__opt = __webpack_exports__.MD;
|
|
41830
41844
|
/******/ var __webpack_exports__parse = __webpack_exports__.Qc;
|
|
41831
41845
|
/******/ var __webpack_exports__print = __webpack_exports__.S0;
|
|
41832
41846
|
/******/ var __webpack_exports__transpile = __webpack_exports__.LZ;
|
|
41833
|
-
/******/ 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 };
|
|
41834
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:
|
|
@@ -44229,6 +44230,39 @@ await $init;
|
|
|
44229
44230
|
__webpack_async_result__();
|
|
44230
44231
|
} catch(e) { __webpack_async_result__(e); } }, 1);
|
|
44231
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
|
+
|
|
44232
44266
|
/***/ }),
|
|
44233
44267
|
|
|
44234
44268
|
/***/ 5862:
|
|
@@ -44387,7 +44421,7 @@ async function optimizeComponent (componentBytes, opts) {
|
|
|
44387
44421
|
* @param {Uint8Array} source
|
|
44388
44422
|
* @returns {Promise<Uint8Array>}
|
|
44389
44423
|
*/
|
|
44390
|
-
async function wasmOpt (source, args = ['-
|
|
44424
|
+
async function wasmOpt (source, args = ['-O1', '--low-memory-unused', '--enable-bulk-memory']) {
|
|
44391
44425
|
try {
|
|
44392
44426
|
return await (0,_common_js__WEBPACK_IMPORTED_MODULE_4__/* .spawnIOTmp */ .np)(WASM_OPT, source, [
|
|
44393
44427
|
...args, '-o'
|
|
@@ -45079,7 +45113,8 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen
|
|
|
45079
45113
|
/* harmony import */ var _cmd_opt_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(5862);
|
|
45080
45114
|
/* harmony import */ var _cmd_transpile_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(2229);
|
|
45081
45115
|
/* harmony import */ var _cmd_wasm_tools_js__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(8154);
|
|
45082
|
-
/* 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);
|
|
45083
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__]);
|
|
45084
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__);
|
|
45085
45120
|
|
|
@@ -45088,8 +45123,9 @@ var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_cmd
|
|
|
45088
45123
|
|
|
45089
45124
|
|
|
45090
45125
|
|
|
45126
|
+
|
|
45091
45127
|
commander__WEBPACK_IMPORTED_MODULE_0__/* .program.name */ .Nx.name('jco')
|
|
45092
|
-
.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`)
|
|
45093
45129
|
.usage('<command> [options]')
|
|
45094
45130
|
.version('0.1.0');
|
|
45095
45131
|
|
|
@@ -45097,6 +45133,14 @@ function myParseInt(value) {
|
|
|
45097
45133
|
return parseInt(value, 10);
|
|
45098
45134
|
}
|
|
45099
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
|
+
|
|
45100
45144
|
commander__WEBPACK_IMPORTED_MODULE_0__/* .program.command */ .Nx.command('transpile')
|
|
45101
45145
|
.description('Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution')
|
|
45102
45146
|
.usage('<component-path> -o <out-dir>')
|
|
@@ -45105,7 +45149,6 @@ commander__WEBPACK_IMPORTED_MODULE_0__/* .program.command */ .Nx.command('transp
|
|
|
45105
45149
|
.requiredOption('-o, --out-dir <out-dir>', 'output directory')
|
|
45106
45150
|
.option('-m, --minify', 'minify the JS output (--optimize / opt cmd still required)')
|
|
45107
45151
|
.option('-O, --optimize', 'optimize the component first')
|
|
45108
|
-
.option('-a, --args', 'when using --optimize, custom binaryen argument flags to pass')
|
|
45109
45152
|
.option('--no-typescript', 'do not output TypeScript .d.ts types')
|
|
45110
45153
|
.option('--valid-lifting-optimization', 'optimize component binary validations assuming all lifted values are valid')
|
|
45111
45154
|
.option('-b, --base64-cutoff <bytes>', 'set the byte size under which core Wasm binaries will be inlined as base64', myParseInt)
|
|
@@ -45190,7 +45233,7 @@ function asyncAction (cmd) {
|
|
|
45190
45233
|
catch (e) {
|
|
45191
45234
|
process.stdout.write(`(jsct ${cmd.name}) `);
|
|
45192
45235
|
if (typeof e === 'string') {
|
|
45193
|
-
console.error(
|
|
45236
|
+
console.error(chalk_template__WEBPACK_IMPORTED_MODULE_5__/* ["default"] */ .Z`{red.bold Error}: ${e}\n`);
|
|
45194
45237
|
} else {
|
|
45195
45238
|
console.error(e);
|
|
45196
45239
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
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
16
|
"url": "git+https://github.com/bytecodealliance/jco.git"
|