@bytecodealliance/jco 1.1.1 → 1.2.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/README.md +0 -2
- package/obj/interfaces/wasi-io-streams.d.ts +5 -5
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +1193 -233
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +10 -20
- package/package.json +8 -5
- package/src/api.d.ts +1 -1
- package/src/api.js +1 -1
- package/src/cmd/componentize.d.ts.map +1 -1
- package/src/cmd/componentize.js +3 -3
- package/src/cmd/run.js +6 -2
- package/src/cmd/transpile.d.ts +30 -1
- package/src/cmd/transpile.d.ts.map +1 -1
- package/src/cmd/transpile.js +56 -16
- package/src/jco.js +17 -5
- package/lib/console.js +0 -7
- package/obj/js-component-bindgen-component.component.wasm +0 -0
- package/obj/js-component-bindgen-component.core2.wasm +0 -0
- package/obj/wasm-tools.component.wasm +0 -0
- package/obj/wasm-tools.core2.wasm +0 -0
package/obj/wasm-tools.core.wasm
CHANGED
|
Binary file
|
package/obj/wasm-tools.js
CHANGED
|
@@ -3399,11 +3399,6 @@ let exports3;
|
|
|
3399
3399
|
let realloc1;
|
|
3400
3400
|
let postReturn0;
|
|
3401
3401
|
let postReturn1;
|
|
3402
|
-
let postReturn2;
|
|
3403
|
-
let postReturn3;
|
|
3404
|
-
let postReturn4;
|
|
3405
|
-
let postReturn5;
|
|
3406
|
-
let postReturn6;
|
|
3407
3402
|
function trampoline0(handle) {
|
|
3408
3403
|
const handleEntry = rscTableRemove(handleTable6, handle);
|
|
3409
3404
|
if (handleEntry.own) {
|
|
@@ -3568,7 +3563,7 @@ function print(arg0) {
|
|
|
3568
3563
|
throw new TypeError('invalid variant discriminant for expected');
|
|
3569
3564
|
}
|
|
3570
3565
|
}
|
|
3571
|
-
|
|
3566
|
+
postReturn0(ret);
|
|
3572
3567
|
if (variant3.tag === 'err') {
|
|
3573
3568
|
throw new ComponentError(variant3.val);
|
|
3574
3569
|
}
|
|
@@ -3641,7 +3636,7 @@ function componentNew(arg0, arg1) {
|
|
|
3641
3636
|
throw new TypeError('invalid variant discriminant for expected');
|
|
3642
3637
|
}
|
|
3643
3638
|
}
|
|
3644
|
-
|
|
3639
|
+
postReturn0(ret);
|
|
3645
3640
|
if (variant8.tag === 'err') {
|
|
3646
3641
|
throw new ComponentError(variant8.val);
|
|
3647
3642
|
}
|
|
@@ -3682,7 +3677,7 @@ function componentWit(arg0) {
|
|
|
3682
3677
|
throw new TypeError('invalid variant discriminant for expected');
|
|
3683
3678
|
}
|
|
3684
3679
|
}
|
|
3685
|
-
|
|
3680
|
+
postReturn0(ret);
|
|
3686
3681
|
if (variant3.tag === 'err') {
|
|
3687
3682
|
throw new ComponentError(variant3.val);
|
|
3688
3683
|
}
|
|
@@ -3843,7 +3838,7 @@ function componentEmbed(arg0) {
|
|
|
3843
3838
|
throw new TypeError('invalid variant discriminant for expected');
|
|
3844
3839
|
}
|
|
3845
3840
|
}
|
|
3846
|
-
|
|
3841
|
+
postReturn0(ret);
|
|
3847
3842
|
if (variant23.tag === 'err') {
|
|
3848
3843
|
throw new ComponentError(variant23.val);
|
|
3849
3844
|
}
|
|
@@ -3952,7 +3947,7 @@ function metadataShow(arg0) {
|
|
|
3952
3947
|
throw new TypeError('invalid variant discriminant for expected');
|
|
3953
3948
|
}
|
|
3954
3949
|
}
|
|
3955
|
-
|
|
3950
|
+
postReturn1(ret);
|
|
3956
3951
|
if (variant11.tag === 'err') {
|
|
3957
3952
|
throw new ComponentError(variant11.val);
|
|
3958
3953
|
}
|
|
@@ -4021,7 +4016,7 @@ function metadataAdd(arg0, arg1) {
|
|
|
4021
4016
|
throw new TypeError('invalid variant discriminant for expected');
|
|
4022
4017
|
}
|
|
4023
4018
|
}
|
|
4024
|
-
|
|
4019
|
+
postReturn0(ret);
|
|
4025
4020
|
if (variant10.tag === 'err') {
|
|
4026
4021
|
throw new ComponentError(variant10.val);
|
|
4027
4022
|
}
|
|
@@ -4032,8 +4027,8 @@ let _initialized = false;
|
|
|
4032
4027
|
export const $init = (async() => {
|
|
4033
4028
|
const module0 = fetchCompile(new URL('./wasm-tools.core.wasm', import.meta.url));
|
|
4034
4029
|
const module1 = fetchCompile(new URL('./wasm-tools.core2.wasm', import.meta.url));
|
|
4035
|
-
const module2 = base64Compile('
|
|
4036
|
-
const module3 = base64Compile('
|
|
4030
|
+
const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBX9/f39/AGAEf39/fwBgBH9/f38Bf2AHf39/f39/fwBgAn5/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX8DJiUBAwMAAAAABAcABAAAAwMABQUACAEBAQEJCgsCAgYGAgIMAg0BBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+QMlCQAgAEEAEQEACw0AIAAgASACQQERAwALDQAgACABIAJBAhEDAAsLACAAIAFBAxEAAAsLACAAIAFBBBEAAAsLACAAIAFBBREAAAsLACAAIAFBBhEAAAsRACAAIAEgAiADIARBBxEEAAsVACAAIAEgAiADIAQgBSAGQQgRBwALCwAgACABQQkRAAALEQAgACABIAIgAyAEQQoRBAALCwAgACABQQsRAAALCwAgACABQQwRAAALDQAgACABIAJBDREDAAsNACAAIAEgAkEOEQMACwsAIAAgAUEPEQAACw8AIAAgASACIANBEBEFAAsPACAAIAEgAiADQRERBQALCwAgACABQRIRAAALCwAgACABQRMRCAALCQAgAEEUEQEACwkAIABBFREBAAsJACAAQRYRAQALCQAgAEEXEQEACxkAIAAgASACIAMgBCAFIAYgByAIQRgRCQALEQAgACABIAIgAyAEQRkRCgALEQAgACABIAIgAyAEQRoRCwALCwAgACABQRsRAgALCwAgACABQRwRAgALDwAgACABIAIgA0EdEQYACw8AIAAgASACIANBHhEGAAsLACAAIAFBHxECAAsLACAAIAFBIBECAAsJACAAQSERDAALCwAgACABQSIRAgALDQAgACABIAJBIxENAAsJACAAQSQRAQALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yMDIuMA');
|
|
4031
|
+
const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBX9/f39/AGAEf39/fwBgBH9/f38Bf2AHf39/f39/fwBgAn5/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX8C5AEmAAEwAAEAATEAAwABMgADAAEzAAAAATQAAAABNQAAAAE2AAAAATcABAABOAAHAAE5AAAAAjEwAAQAAjExAAAAAjEyAAAAAjEzAAMAAjE0AAMAAjE1AAAAAjE2AAUAAjE3AAUAAjE4AAAAAjE5AAgAAjIwAAEAAjIxAAEAAjIyAAEAAjIzAAEAAjI0AAkAAjI1AAoAAjI2AAsAAjI3AAIAAjI4AAIAAjI5AAYAAjMwAAYAAjMxAAIAAjMyAAIAAjMzAAwAAjM0AAIAAjM1AA0AAjM2AAEACCRpbXBvcnRzAXABJSUJKwEAQQALJQABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIwMi4w');
|
|
4037
4032
|
({ exports: exports0 } = await instantiateCore(await module2));
|
|
4038
4033
|
({ exports: exports1 } = await instantiateCore(await module0, {
|
|
4039
4034
|
wasi_snapshot_preview1: {
|
|
@@ -4170,13 +4165,8 @@ export const $init = (async() => {
|
|
|
4170
4165
|
},
|
|
4171
4166
|
}));
|
|
4172
4167
|
realloc1 = exports1.cabi_realloc;
|
|
4173
|
-
postReturn0 = exports1['cabi_post_local:wasm-tools/tools#
|
|
4174
|
-
postReturn1 = exports1['cabi_post_local:wasm-tools/tools#
|
|
4175
|
-
postReturn2 = exports1['cabi_post_local:wasm-tools/tools#component-new'];
|
|
4176
|
-
postReturn3 = exports1['cabi_post_local:wasm-tools/tools#component-wit'];
|
|
4177
|
-
postReturn4 = exports1['cabi_post_local:wasm-tools/tools#component-embed'];
|
|
4178
|
-
postReturn5 = exports1['cabi_post_local:wasm-tools/tools#metadata-show'];
|
|
4179
|
-
postReturn6 = exports1['cabi_post_local:wasm-tools/tools#metadata-add'];
|
|
4168
|
+
postReturn0 = exports1['cabi_post_local:wasm-tools/tools#component-embed'];
|
|
4169
|
+
postReturn1 = exports1['cabi_post_local:wasm-tools/tools#metadata-show'];
|
|
4180
4170
|
_initialized = true;
|
|
4181
4171
|
})();
|
|
4182
4172
|
const tools = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/jco",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JavaScript tooling for working with WebAssembly Components",
|
|
5
5
|
"author": "Guy Bedford",
|
|
6
6
|
"bin": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"type": "module",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@bytecodealliance/preview2-shim": "^0.16.
|
|
21
|
+
"@bytecodealliance/preview2-shim": "^0.16.2",
|
|
22
22
|
"binaryen": "^116.0.0",
|
|
23
23
|
"chalk-template": "^1",
|
|
24
24
|
"commander": "^12",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"terser": "^5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@bytecodealliance/componentize-js": "^0.8.
|
|
30
|
+
"@bytecodealliance/componentize-js": "^0.8.3",
|
|
31
31
|
"@types/node": "^18.11.17",
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
33
33
|
"@typescript-eslint/parser": "^5.41.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"build": "cargo xtask build debug",
|
|
55
55
|
"build:release": "cargo xtask build release",
|
|
56
56
|
"build:types:preview2-shim": "cargo xtask generate wasi-types",
|
|
57
|
-
"lint": "eslint -c eslintrc.cjs
|
|
57
|
+
"lint": "eslint -c eslintrc.cjs src/**/*.js packages/*/lib/**/*.js",
|
|
58
58
|
"test:lts": "mocha -u tdd test/test.js --timeout 30000",
|
|
59
59
|
"test": "node --stack-trace-limit=100 --experimental-wasm-multi-memory node_modules/mocha/bin/mocha.js -u tdd test/test.js --timeout 30000",
|
|
60
60
|
"prepublishOnly": "cargo xtask build release && npm run test"
|
|
@@ -62,7 +62,10 @@
|
|
|
62
62
|
"files": [
|
|
63
63
|
"lib",
|
|
64
64
|
"src",
|
|
65
|
-
"obj"
|
|
65
|
+
"obj/*.core.wasm",
|
|
66
|
+
"obj/*.js",
|
|
67
|
+
"obj/*.ts",
|
|
68
|
+
"obj/interfaces"
|
|
66
69
|
],
|
|
67
70
|
"workspaces": [
|
|
68
71
|
"packages/preview2-shim"
|
package/src/api.d.ts
CHANGED
|
@@ -38,5 +38,5 @@ export function metadataShow(binary: any): Promise<ReturnType<import('../obj/was
|
|
|
38
38
|
export function preview1AdapterCommandPath(): URL;
|
|
39
39
|
export function preview1AdapterReactorPath(): URL;
|
|
40
40
|
export { optimizeComponent as opt } from "./cmd/opt.js";
|
|
41
|
-
export { transpileComponent as transpile } from "./cmd/transpile.js";
|
|
41
|
+
export { transpileComponent as transpile, typesComponent as types } from "./cmd/transpile.js";
|
|
42
42
|
//# sourceMappingURL=api.d.ts.map
|
package/src/api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { optimizeComponent as opt } from './cmd/opt.js';
|
|
2
|
-
export { transpileComponent as transpile } from './cmd/transpile.js';
|
|
2
|
+
export { transpileComponent as transpile, typesComponent as types } from './cmd/transpile.js';
|
|
3
3
|
import { $init, tools } from "../obj/wasm-tools.js";
|
|
4
4
|
const { print: printFn, parse: parseFn, componentWit: componentWitFn, componentNew: componentNewFn, componentEmbed: componentEmbedFn, metadataAdd: metadataAddFn, metadataShow: metadataShowFn } = tools;
|
|
5
5
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"componentize.d.ts","sourceRoot":"","sources":["componentize.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"componentize.d.ts","sourceRoot":"","sources":["componentize.js"],"names":[],"mappings":"AAIA,sEAmBC"}
|
package/src/cmd/componentize.js
CHANGED
|
@@ -12,13 +12,13 @@ export async function componentize (jsSource, opts) {
|
|
|
12
12
|
throw e;
|
|
13
13
|
}
|
|
14
14
|
const source = await readFile(jsSource, 'utf8');
|
|
15
|
-
const { component
|
|
15
|
+
const { component } = await componentizeFn(source, {
|
|
16
16
|
sourceName: basename(jsSource),
|
|
17
17
|
witPath: resolve(opts.wit),
|
|
18
18
|
worldName: opts.worldName,
|
|
19
|
-
|
|
19
|
+
disableFeatures: opts.disable,
|
|
20
20
|
preview2Adapter: opts.preview2Adapter,
|
|
21
21
|
});
|
|
22
22
|
await writeFile(opts.out, component);
|
|
23
|
-
console.log(c`{green OK} Successfully written {bold ${opts.out}}
|
|
23
|
+
console.log(c`{green OK} Successfully written {bold ${opts.out}}.`);
|
|
24
24
|
}
|
package/src/cmd/run.js
CHANGED
|
@@ -92,7 +92,9 @@ async function runComponent (componentPath, args, opts, executor) {
|
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
catch {
|
|
95
|
+
catch {
|
|
96
|
+
// empty
|
|
97
|
+
}
|
|
96
98
|
let len = preview2ShimPath.length;
|
|
97
99
|
preview2ShimPath = resolve(preview2ShimPath, '..', '..', '..', 'node_modules', '@bytecodealliance', 'preview2-shim');
|
|
98
100
|
if (preview2ShimPath.length === len) {
|
|
@@ -134,6 +136,8 @@ async function runComponent (componentPath, args, opts, executor) {
|
|
|
134
136
|
try {
|
|
135
137
|
if (!opts.jcoDir)
|
|
136
138
|
await rm(outDir, { recursive: true });
|
|
137
|
-
} catch {
|
|
139
|
+
} catch {
|
|
140
|
+
// empty
|
|
141
|
+
}
|
|
138
142
|
}
|
|
139
143
|
}
|
package/src/cmd/transpile.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
export function types(witPath: any, opts: any): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} witPath
|
|
4
|
+
* @param {{
|
|
5
|
+
* name?: string,
|
|
6
|
+
* worldName?: string,
|
|
7
|
+
* instantiation?: 'async' | 'sync',
|
|
8
|
+
* tlaCompat?: bool,
|
|
9
|
+
* outDir?: string,
|
|
10
|
+
* }} opts
|
|
11
|
+
* @returns {Promise<{ [filename: string]: Uint8Array }>}
|
|
12
|
+
*/
|
|
13
|
+
export function typesComponent(witPath: string, opts: {
|
|
14
|
+
name?: string;
|
|
15
|
+
worldName?: string;
|
|
16
|
+
instantiation?: 'async' | 'sync';
|
|
17
|
+
tlaCompat?: bool;
|
|
18
|
+
outDir?: string;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
[filename: string]: Uint8Array;
|
|
21
|
+
}>;
|
|
1
22
|
export function transpile(componentPath: any, opts: any, program: any): Promise<void>;
|
|
2
23
|
/**
|
|
3
24
|
*
|
|
@@ -5,6 +26,7 @@ export function transpile(componentPath: any, opts: any, program: any): Promise<
|
|
|
5
26
|
* @param {{
|
|
6
27
|
* name: string,
|
|
7
28
|
* instantiation?: 'async' | 'sync',
|
|
29
|
+
* importBindings?: 'js' | 'optimized', 'hybrid', 'direct-optimized',
|
|
8
30
|
* map?: Record<string, string>,
|
|
9
31
|
* validLiftingOptimization?: bool,
|
|
10
32
|
* tracing?: bool,
|
|
@@ -15,6 +37,8 @@ export function transpile(componentPath: any, opts: any, program: any): Promise<
|
|
|
15
37
|
* minify?: bool,
|
|
16
38
|
* optimize?: bool,
|
|
17
39
|
* namespacedExports?: bool,
|
|
40
|
+
* outDir?: string,
|
|
41
|
+
* multiMemory?: bool,
|
|
18
42
|
* optArgs?: string[],
|
|
19
43
|
* }} opts
|
|
20
44
|
* @returns {Promise<{ files: { [filename: string]: Uint8Array }, imports: string[], exports: [string, 'function' | 'instance'][] }>}
|
|
@@ -22,6 +46,9 @@ export function transpile(componentPath: any, opts: any, program: any): Promise<
|
|
|
22
46
|
export function transpileComponent(component: Uint8Array, opts?: {
|
|
23
47
|
name: string;
|
|
24
48
|
instantiation?: 'async' | 'sync';
|
|
49
|
+
importBindings?: 'js' | 'optimized';
|
|
50
|
+
hybrid: any;
|
|
51
|
+
'direct-optimized': any;
|
|
25
52
|
map?: Record<string, string>;
|
|
26
53
|
validLiftingOptimization?: bool;
|
|
27
54
|
tracing?: bool;
|
|
@@ -32,6 +59,8 @@ export function transpileComponent(component: Uint8Array, opts?: {
|
|
|
32
59
|
minify?: bool;
|
|
33
60
|
optimize?: bool;
|
|
34
61
|
namespacedExports?: bool;
|
|
62
|
+
outDir?: string;
|
|
63
|
+
multiMemory?: bool;
|
|
35
64
|
optArgs?: string[];
|
|
36
65
|
}): Promise<{
|
|
37
66
|
files: {
|
|
@@ -40,5 +69,5 @@ export function transpileComponent(component: Uint8Array, opts?: {
|
|
|
40
69
|
imports: string[];
|
|
41
70
|
exports: [string, 'function' | 'instance'][];
|
|
42
71
|
}>;
|
|
43
|
-
import { minify } from
|
|
72
|
+
import { minify } from 'terser';
|
|
44
73
|
//# sourceMappingURL=transpile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["transpile.js"],"names":[],"mappings":"AAgBA,
|
|
1
|
+
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["transpile.js"],"names":[],"mappings":"AAgBA,8DAGC;AAED;;;;;;;;;;GAUG;AACH,wCAVW,MAAM;WAEL,MAAM;gBACD,MAAM;oBACF,OAAO,GAAG,MAAM;;aAEvB,MAAM;;;GAsBnB;AAkBD,sFAwBC;AAuBD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8CArBW,UAAU;UAEV,MAAM;oBACI,OAAO,GAAG,MAAM;qBACf,IAAI,GAAG,WAAW;;;UAC7B,OAAO,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;aAUnB,MAAM;;cAEL,MAAM,EAAE;;;;;aAEoD,MAAM,EAAE;aAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,EAAE;GAmShI;uBApasB,QAAQ"}
|
package/src/cmd/transpile.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $init, generate } from '../../obj/js-component-bindgen-component.js';
|
|
1
|
+
import { $init, generate, generateTypes } from '../../obj/js-component-bindgen-component.js';
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
3
|
import { mkdir } from 'node:fs/promises';
|
|
4
4
|
import { dirname, extname, basename, resolve } from 'node:path';
|
|
@@ -14,6 +14,58 @@ import { platform } from 'node:process';
|
|
|
14
14
|
|
|
15
15
|
const isWindows = platform === 'win32';
|
|
16
16
|
|
|
17
|
+
export async function types (witPath, opts) {
|
|
18
|
+
const files = await typesComponent(witPath, opts);
|
|
19
|
+
await writeFiles(files, opts.quiet ? false : 'Generated Type Files');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {string} witPath
|
|
24
|
+
* @param {{
|
|
25
|
+
* name?: string,
|
|
26
|
+
* worldName?: string,
|
|
27
|
+
* instantiation?: 'async' | 'sync',
|
|
28
|
+
* tlaCompat?: bool,
|
|
29
|
+
* outDir?: string,
|
|
30
|
+
* }} opts
|
|
31
|
+
* @returns {Promise<{ [filename: string]: Uint8Array }>}
|
|
32
|
+
*/
|
|
33
|
+
export async function typesComponent (witPath, opts) {
|
|
34
|
+
await $init;
|
|
35
|
+
const name = opts.name || (opts.worldName
|
|
36
|
+
? opts.worldName.split(':').pop().split('/').pop()
|
|
37
|
+
: basename(witPath.slice(0, -extname(witPath).length || Infinity)));
|
|
38
|
+
let instantiation;
|
|
39
|
+
if (opts.instantiation) {
|
|
40
|
+
instantiation = { tag: opts.instantiation };
|
|
41
|
+
}
|
|
42
|
+
let outDir = (opts.outDir ?? '').replace(/\\/g, '/');
|
|
43
|
+
if (!outDir.endsWith('/') && outDir !== '')
|
|
44
|
+
outDir += '/';
|
|
45
|
+
return Object.fromEntries(generateTypes(name, {
|
|
46
|
+
wit: { tag: 'path', val: (isWindows ? '//?/' : '') + resolve(witPath) },
|
|
47
|
+
instantiation,
|
|
48
|
+
tlaCompat: opts.tlaCompat ?? false,
|
|
49
|
+
world: opts.worldName
|
|
50
|
+
}).map(([name, file]) => [`${outDir}${name}`, file]));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function writeFiles(files, summaryTitle) {
|
|
54
|
+
await Promise.all(Object.entries(files).map(async ([name, file]) => {
|
|
55
|
+
await mkdir(dirname(name), { recursive: true });
|
|
56
|
+
await writeFile(name, file);
|
|
57
|
+
}));
|
|
58
|
+
if (!summaryTitle)
|
|
59
|
+
return;
|
|
60
|
+
console.log(c`
|
|
61
|
+
{bold ${summaryTitle}:}
|
|
62
|
+
|
|
63
|
+
${table(Object.entries(files).map(([name, source]) => [
|
|
64
|
+
c` - {italic ${name}} `,
|
|
65
|
+
c`{black.italic ${sizeStr(source.length)}}`
|
|
66
|
+
]))}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
17
69
|
export async function transpile (componentPath, opts, program) {
|
|
18
70
|
const varIdx = program?.parent.rawArgs.indexOf('--');
|
|
19
71
|
if (varIdx !== undefined && varIdx !== -1)
|
|
@@ -37,20 +89,7 @@ export async function transpile (componentPath, opts, program) {
|
|
|
37
89
|
if (opts.map)
|
|
38
90
|
opts.map = Object.fromEntries(opts.map.map(mapping => mapping.split('=')));
|
|
39
91
|
const { files } = await transpileComponent(component, opts);
|
|
40
|
-
|
|
41
|
-
await Promise.all(Object.entries(files).map(async ([name, file]) => {
|
|
42
|
-
await mkdir(dirname(name), { recursive: true });
|
|
43
|
-
await writeFile(name, file);
|
|
44
|
-
}));
|
|
45
|
-
|
|
46
|
-
if (!opts.quiet)
|
|
47
|
-
console.log(c`
|
|
48
|
-
{bold Transpiled JS Component Files:}
|
|
49
|
-
|
|
50
|
-
${table(Object.entries(files).map(([name, source]) => [
|
|
51
|
-
c` - {italic ${name}} `,
|
|
52
|
-
c`{black.italic ${sizeStr(source.length)}}`
|
|
53
|
-
]))}`);
|
|
92
|
+
await writeFiles(files, opts.quiet ? false : 'Transpiled JS Component Files');
|
|
54
93
|
}
|
|
55
94
|
|
|
56
95
|
let WASM_2_JS;
|
|
@@ -91,6 +130,7 @@ async function wasm2Js (source) {
|
|
|
91
130
|
* minify?: bool,
|
|
92
131
|
* optimize?: bool,
|
|
93
132
|
* namespacedExports?: bool,
|
|
133
|
+
* outDir?: string,
|
|
94
134
|
* multiMemory?: bool,
|
|
95
135
|
* optArgs?: string[],
|
|
96
136
|
* }} opts
|
|
@@ -284,7 +324,7 @@ ${
|
|
|
284
324
|
}${
|
|
285
325
|
exports
|
|
286
326
|
.map(([name]) => {
|
|
287
|
-
if (name === asmMangle(name))
|
|
327
|
+
if (name === asmMangle(name)){
|
|
288
328
|
return ` ${name},`;
|
|
289
329
|
} else {
|
|
290
330
|
return ` ${asmMangle(name)} as '${name}',`;
|
package/src/jco.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { program, Option } from 'commander';
|
|
3
3
|
import { opt } from './cmd/opt.js';
|
|
4
|
-
import { transpile } from './cmd/transpile.js';
|
|
4
|
+
import { transpile, types } from './cmd/transpile.js';
|
|
5
5
|
import { run as runCmd, serve as serveCmd } from './cmd/run.js';
|
|
6
6
|
import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js';
|
|
7
7
|
import { componentize } from './cmd/componentize.js';
|
|
@@ -11,7 +11,7 @@ program
|
|
|
11
11
|
.name('jco')
|
|
12
12
|
.description(c`{bold jco - WebAssembly JS Component Tools}\n JS Component Transpilation Bindgen & Wasm Tools for JS`)
|
|
13
13
|
.usage('<command> [options]')
|
|
14
|
-
.version('1.
|
|
14
|
+
.version('1.2.0');
|
|
15
15
|
|
|
16
16
|
function myParseInt(value) {
|
|
17
17
|
return parseInt(value, 10);
|
|
@@ -23,7 +23,7 @@ program.command('componentize')
|
|
|
23
23
|
.argument('<js-source>', 'JS source file to build')
|
|
24
24
|
.requiredOption('-w, --wit <path>', 'WIT path to build with')
|
|
25
25
|
.option('-n, --world-name <name>', 'WIT world to build')
|
|
26
|
-
.
|
|
26
|
+
.addOption(new Option('-d, --disable <feature...>', 'disable WASI features').choices(['stdio', 'random', 'clocks']))
|
|
27
27
|
.option('--preview2-adapter <adapter>', 'provide a custom preview2 adapter path')
|
|
28
28
|
.requiredOption('-o, --out <out>', 'output component file')
|
|
29
29
|
.action(asyncAction(componentize));
|
|
@@ -48,12 +48,24 @@ program.command('transpile')
|
|
|
48
48
|
.option('--stub', 'generate a stub implementation from a WIT file directly')
|
|
49
49
|
.option('--js', 'output JS instead of core WebAssembly')
|
|
50
50
|
.addOption(new Option('-I, --instantiation [mode]', 'output for custom module instantiation').choices(['async', 'sync']).preset('async'))
|
|
51
|
-
.option('-q, --quiet', 'disable
|
|
51
|
+
.option('-q, --quiet', 'disable output summary')
|
|
52
52
|
.option('--no-namespaced-exports', 'disable namespaced exports for typescript compatibility')
|
|
53
53
|
.option('--multi-memory', 'optimized output for Wasm multi-memory')
|
|
54
54
|
.option('--', 'for --optimize, custom wasm-opt arguments (defaults to best size optimization)')
|
|
55
55
|
.action(asyncAction(transpile));
|
|
56
56
|
|
|
57
|
+
program.command('types')
|
|
58
|
+
.description('Generate types for the given WIT')
|
|
59
|
+
.usage('<wit-path> -o <out-dir>')
|
|
60
|
+
.argument('<wit-path>', 'path to a WIT file or directory')
|
|
61
|
+
.option('--name <name>', 'custom output name')
|
|
62
|
+
.option('-n, --world-name <world>', 'WIT world to generate types for')
|
|
63
|
+
.requiredOption('-o, --out-dir <out-dir>', 'output directory')
|
|
64
|
+
.option('--tla-compat', 'generates types for the TLA compat output with an async $init promise export')
|
|
65
|
+
.addOption(new Option('-I, --instantiation [mode]', 'type output for custom module instantiation').choices(['async', 'sync']).preset('async'))
|
|
66
|
+
.option('-q, --quiet', 'disable output summary')
|
|
67
|
+
.action(asyncAction(types));
|
|
68
|
+
|
|
57
69
|
program.command('run')
|
|
58
70
|
.description('Run a WASI Command component')
|
|
59
71
|
.usage('<command.wasm> <args...>')
|
|
@@ -158,7 +170,7 @@ program.command('embed')
|
|
|
158
170
|
.requiredOption('--wit <wit-world>', 'WIT world path')
|
|
159
171
|
.option('--dummy', 'generate a dummy component')
|
|
160
172
|
.option('--string-encoding <utf8|utf16|compact-utf16>', 'set the component string encoding')
|
|
161
|
-
.option('--world <world-name>', '
|
|
173
|
+
.option('-n, --world-name <world-name>', 'world name to embed')
|
|
162
174
|
.option('-m, --metadata <metadata...>', 'field=name[@version] producer metadata to add with the embedding')
|
|
163
175
|
.action(asyncAction(componentEmbed));
|
|
164
176
|
|
package/lib/console.js
DELETED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|