@bytecodealliance/jco 1.11.2-rc.2 → 1.11.3-rc.1
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/obj/interfaces/wasi-filesystem-types.d.ts +30 -30
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +54 -50
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +54 -50
- package/package.json +11 -15
- package/src/api.d.ts.map +1 -1
- package/src/api.js +45 -28
- package/src/browser.d.ts.map +1 -1
- package/src/browser.js +12 -8
- package/src/cmd/componentize.d.ts.map +1 -1
- package/src/cmd/opt.d.ts.map +1 -1
- package/src/cmd/opt.js +17 -7
- package/src/cmd/run.d.ts.map +1 -1
- package/src/cmd/run.js +6 -2
- package/src/cmd/transpile.d.ts +14 -14
- package/src/cmd/transpile.d.ts.map +1 -1
- package/src/cmd/transpile.js +89 -35
- package/src/cmd/wasm-tools.d.ts.map +1 -1
- package/src/cmd/wasm-tools.js +22 -10
- package/src/common.d.ts.map +1 -1
- package/src/common.js +86 -75
- package/src/jco.js +419 -216
- package/src/ora-shim.d.ts +1 -0
- package/src/ora-shim.d.ts.map +1 -1
- package/src/ora-shim.js +5 -5
- package/LICENSE +0 -220
package/src/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,8BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2BAHW,UAAU,CAAC,GAAoC,CAAC,CAAC,CAAC,CAAC,GAClD,OAAO,CAAC,UAAU,CAAC,GAAoC,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,qCAJW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,YAC1D,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,0CAHW,UAAU,CAAC,GAA6C,CAAC,CAAC,CAAC,CAAC,GAC3D,OAAO,CAAC,UAAU,CAAC,GAA6C,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,oCAJW,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,YACzD,UAAU,CAAC,GAA0C,CAAC,CAAC,CAAC,CAAC,GACxD,OAAO,CAAC,UAAU,CAAC,GAA0C,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,qCAHW,UAAU,CAAC,GAA2C,CAAC,CAAC,CAAC,CAAC,GACzD,OAAO,CAAC,UAAU,CAAC,GAA2C,CAAC,CAAC,CAK3E;AACD,kDAKC;AACD,kDAKC"}
|
package/src/api.js
CHANGED
|
@@ -1,69 +1,86 @@
|
|
|
1
1
|
export { optimizeComponent as opt } from './cmd/opt.js';
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export {
|
|
3
|
+
transpileComponent as transpile,
|
|
4
|
+
typesComponent as types,
|
|
5
|
+
} from './cmd/transpile.js';
|
|
6
|
+
import { $init, tools } from '../obj/wasm-tools.js';
|
|
7
|
+
const {
|
|
8
|
+
print: printFn,
|
|
9
|
+
parse: parseFn,
|
|
10
|
+
componentWit: componentWitFn,
|
|
11
|
+
componentNew: componentNewFn,
|
|
12
|
+
componentEmbed: componentEmbedFn,
|
|
13
|
+
metadataAdd: metadataAddFn,
|
|
14
|
+
metadataShow: metadataShowFn,
|
|
15
|
+
} = tools;
|
|
5
16
|
|
|
6
17
|
/**
|
|
7
18
|
* @param {Parameters<import('../obj/wasm-tools.js').print>[0]} binary
|
|
8
19
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').print>>}
|
|
9
20
|
*/
|
|
10
|
-
export async function print
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
export async function print(binary) {
|
|
22
|
+
await $init;
|
|
23
|
+
return printFn(binary);
|
|
13
24
|
}
|
|
14
25
|
/**
|
|
15
26
|
* @param {Parameters<import('../obj/wasm-tools.js').parse>[0]} wat
|
|
16
27
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').parse>>}
|
|
17
28
|
*/
|
|
18
|
-
export async function parse
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
export async function parse(wat) {
|
|
30
|
+
await $init;
|
|
31
|
+
return parseFn(wat);
|
|
21
32
|
}
|
|
22
33
|
/**
|
|
23
34
|
* @param {Parameters<import('../obj/wasm-tools.js').componentWit>[0]} binary
|
|
24
35
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentWit>>}
|
|
25
36
|
*/
|
|
26
|
-
export async function componentWit
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
export async function componentWit(binary) {
|
|
38
|
+
await $init;
|
|
39
|
+
return componentWitFn(binary);
|
|
29
40
|
}
|
|
30
41
|
/**
|
|
31
42
|
* @param {Parameters<import('../obj/wasm-tools.js').componentNew>[0]} binary
|
|
32
43
|
* @param {Parameters<import('../obj/wasm-tools.js').componentNew>[1]} adapters
|
|
33
44
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentNew>>}
|
|
34
45
|
*/
|
|
35
|
-
export async function componentNew
|
|
36
|
-
|
|
37
|
-
|
|
46
|
+
export async function componentNew(binary, adapters) {
|
|
47
|
+
await $init;
|
|
48
|
+
return componentNewFn(binary, adapters);
|
|
38
49
|
}
|
|
39
50
|
/**
|
|
40
51
|
* @param {Parameters<import('../obj/wasm-tools.js').componentEmbed>[0]} embedOpts
|
|
41
52
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentEmbed>>}
|
|
42
53
|
*/
|
|
43
|
-
export async function componentEmbed
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
export async function componentEmbed(embedOpts) {
|
|
55
|
+
await $init;
|
|
56
|
+
return componentEmbedFn(embedOpts);
|
|
46
57
|
}
|
|
47
58
|
/**
|
|
48
59
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[0]} binary
|
|
49
60
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[1]} metadata
|
|
50
61
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataAdd>>}
|
|
51
62
|
*/
|
|
52
|
-
export async function metadataAdd
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
export async function metadataAdd(binary, metadata) {
|
|
64
|
+
await $init;
|
|
65
|
+
return metadataAddFn(binary, metadata);
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
57
68
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataShow>[0]} binary
|
|
58
69
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataShow>>}
|
|
59
70
|
*/
|
|
60
|
-
export async function metadataShow
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
export async function metadataShow(binary) {
|
|
72
|
+
await $init;
|
|
73
|
+
return metadataShowFn(binary);
|
|
63
74
|
}
|
|
64
|
-
export function preview1AdapterCommandPath
|
|
65
|
-
|
|
75
|
+
export function preview1AdapterCommandPath() {
|
|
76
|
+
return new URL(
|
|
77
|
+
'../lib/wasi_snapshot_preview1.command.wasm',
|
|
78
|
+
import.meta.url
|
|
79
|
+
);
|
|
66
80
|
}
|
|
67
|
-
export function preview1AdapterReactorPath
|
|
68
|
-
|
|
81
|
+
export function preview1AdapterReactorPath() {
|
|
82
|
+
return new URL(
|
|
83
|
+
'../lib/wasi_snapshot_preview1.reactor.wasm',
|
|
84
|
+
import.meta.url
|
|
85
|
+
);
|
|
69
86
|
}
|
package/src/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["browser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["browser.js"],"names":[],"mappings":"AAMA,uDAGC;AAED,4DAGC"}
|
package/src/browser.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
$init,
|
|
3
|
+
generate as _generate,
|
|
4
|
+
generateTypes as _generateTypes,
|
|
5
|
+
} from '../obj/js-component-bindgen-component.js';
|
|
2
6
|
|
|
3
|
-
export async function generate
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
export async function generate() {
|
|
8
|
+
await $init;
|
|
9
|
+
return _generate.apply(this, arguments);
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
export async function generateTypes
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
export async function generateTypes() {
|
|
13
|
+
await $init;
|
|
14
|
+
return _generateTypes.apply(this, arguments);
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
// for backwards compat
|
|
14
|
-
export { generate as transpile }
|
|
18
|
+
export { generate as transpile };
|
|
@@ -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,sEAkBC"}
|
package/src/cmd/opt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opt.d.ts","sourceRoot":"","sources":["opt.js"],"names":[],"mappings":"AAgBA,gFA2CC;AAgBD;;;;;GAKG;AACH,kDAJW,UAAU,QACV;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E,OAAO,CAAC;IAAE,SAAS,EAAE,UAAU,CAAC;IAAC,eAAe,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAA,CAAE,
|
|
1
|
+
{"version":3,"file":"opt.d.ts","sourceRoot":"","sources":["opt.js"],"names":[],"mappings":"AAgBA,gFA2CC;AAgBD;;;;;GAKG;AACH,kDAJW,UAAU,QACV;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC5E,OAAO,CAAC;IAAE,SAAS,EAAE,UAAU,CAAC;IAAC,eAAe,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAA,CAAE,CAkK7G"}
|
package/src/cmd/opt.js
CHANGED
|
@@ -17,10 +17,14 @@ import ora from '#ora';
|
|
|
17
17
|
export async function opt(componentPath, opts, program) {
|
|
18
18
|
await $init;
|
|
19
19
|
const varIdx = program.parent.rawArgs.indexOf('--');
|
|
20
|
-
if (varIdx !== -1)
|
|
20
|
+
if (varIdx !== -1) {
|
|
21
|
+
opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
|
|
22
|
+
}
|
|
21
23
|
const componentBytes = await readFile(componentPath);
|
|
22
24
|
|
|
23
|
-
if (!opts.quiet)
|
|
25
|
+
if (!opts.quiet) {
|
|
26
|
+
setShowSpinner(true);
|
|
27
|
+
}
|
|
24
28
|
const optPromise = optimizeComponent(componentBytes, opts);
|
|
25
29
|
const { component, compressionInfo } = await optPromise;
|
|
26
30
|
|
|
@@ -29,7 +33,7 @@ export async function opt(componentPath, opts, program) {
|
|
|
29
33
|
let totalBeforeBytes = 0,
|
|
30
34
|
totalAfterBytes = 0;
|
|
31
35
|
|
|
32
|
-
if (!opts.quiet)
|
|
36
|
+
if (!opts.quiet) {
|
|
33
37
|
console.log(c`
|
|
34
38
|
{bold Optimized WebAssembly Component Internal Core Modules:}
|
|
35
39
|
|
|
@@ -57,6 +61,7 @@ ${table(
|
|
|
57
61
|
],
|
|
58
62
|
[, , , , 'right']
|
|
59
63
|
)}`);
|
|
64
|
+
}
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
/**
|
|
@@ -117,7 +122,9 @@ export async function optimizeComponent(componentBytes, opts) {
|
|
|
117
122
|
'--enable-bulk-memory',
|
|
118
123
|
'--strip-debug',
|
|
119
124
|
];
|
|
120
|
-
if (opts?.asyncify)
|
|
125
|
+
if (opts?.asyncify) {
|
|
126
|
+
args.push('--asyncify');
|
|
127
|
+
}
|
|
121
128
|
|
|
122
129
|
// process core Wasm modules with wasm-opt
|
|
123
130
|
await Promise.all(
|
|
@@ -246,7 +253,7 @@ export async function optimizeComponent(componentBytes, opts) {
|
|
|
246
253
|
// verify it still parses ok
|
|
247
254
|
if (!opts?.noVerify) {
|
|
248
255
|
try {
|
|
249
|
-
|
|
256
|
+
print(outComponentBytes);
|
|
250
257
|
} catch (e) {
|
|
251
258
|
throw new Error(
|
|
252
259
|
`Internal error performing optimization.\n${e.message}`
|
|
@@ -262,7 +269,9 @@ export async function optimizeComponent(componentBytes, opts) {
|
|
|
262
269
|
})),
|
|
263
270
|
};
|
|
264
271
|
} finally {
|
|
265
|
-
if (spinner)
|
|
272
|
+
if (spinner) {
|
|
273
|
+
spinner.stop();
|
|
274
|
+
}
|
|
266
275
|
}
|
|
267
276
|
}
|
|
268
277
|
|
|
@@ -279,8 +288,9 @@ async function wasmOpt(source, args) {
|
|
|
279
288
|
try {
|
|
280
289
|
return await spawnIOTmp(wasmOptPath, source, [...args, '-o']);
|
|
281
290
|
} catch (e) {
|
|
282
|
-
if (e.toString().includes('BasicBlock requested'))
|
|
291
|
+
if (e.toString().includes('BasicBlock requested')) {
|
|
283
292
|
return wasmOpt(source, args);
|
|
293
|
+
}
|
|
284
294
|
throw e;
|
|
285
295
|
}
|
|
286
296
|
}
|
package/src/cmd/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AASA,6EAmBC;AAED,+EA2BC"}
|
package/src/cmd/run.js
CHANGED
|
@@ -132,7 +132,9 @@ async function runComponent(componentPath, args, opts, executor) {
|
|
|
132
132
|
'dir'
|
|
133
133
|
);
|
|
134
134
|
} catch (e) {
|
|
135
|
-
if (e.code !== 'EEXIST')
|
|
135
|
+
if (e.code !== 'EEXIST') {
|
|
136
|
+
throw e;
|
|
137
|
+
}
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
const runPath = resolve(outDir, '_run.js');
|
|
@@ -169,7 +171,9 @@ async function runComponent(componentPath, args, opts, executor) {
|
|
|
169
171
|
});
|
|
170
172
|
} finally {
|
|
171
173
|
try {
|
|
172
|
-
if (!opts.jcoDir)
|
|
174
|
+
if (!opts.jcoDir) {
|
|
175
|
+
await rm(outDir, { recursive: true });
|
|
176
|
+
}
|
|
173
177
|
} catch {
|
|
174
178
|
// empty
|
|
175
179
|
}
|
package/src/cmd/transpile.d.ts
CHANGED
|
@@ -20,13 +20,13 @@ export function typesComponent(witPath: string, opts: {
|
|
|
20
20
|
name?: string;
|
|
21
21
|
worldName?: string;
|
|
22
22
|
instantiation?: "async" | "sync";
|
|
23
|
-
tlaCompat?:
|
|
23
|
+
tlaCompat?: boolean;
|
|
24
24
|
asyncMode?: string;
|
|
25
25
|
asyncImports?: string[];
|
|
26
26
|
asyncExports?: string[];
|
|
27
27
|
outDir?: string;
|
|
28
28
|
features?: string[] | "all";
|
|
29
|
-
guest?:
|
|
29
|
+
guest?: boolean;
|
|
30
30
|
}): Promise<{
|
|
31
31
|
[filename: string]: Uint8Array;
|
|
32
32
|
}>;
|
|
@@ -66,18 +66,18 @@ export function transpileComponent(component: Uint8Array, opts?: {
|
|
|
66
66
|
asyncMode?: string;
|
|
67
67
|
asyncImports?: string[];
|
|
68
68
|
asyncExports?: string[];
|
|
69
|
-
validLiftingOptimization?:
|
|
70
|
-
tracing?:
|
|
71
|
-
nodejsCompat?:
|
|
72
|
-
tlaCompat?:
|
|
73
|
-
base64Cutoff?:
|
|
74
|
-
js?:
|
|
75
|
-
minify?:
|
|
76
|
-
optimize?:
|
|
77
|
-
namespacedExports?:
|
|
69
|
+
validLiftingOptimization?: boolean;
|
|
70
|
+
tracing?: boolean;
|
|
71
|
+
nodejsCompat?: boolean;
|
|
72
|
+
tlaCompat?: boolean;
|
|
73
|
+
base64Cutoff?: boolean;
|
|
74
|
+
js?: boolean;
|
|
75
|
+
minify?: boolean;
|
|
76
|
+
optimize?: boolean;
|
|
77
|
+
namespacedExports?: boolean;
|
|
78
78
|
outDir?: string;
|
|
79
|
-
multiMemory?:
|
|
80
|
-
experimentalIdlImports?:
|
|
79
|
+
multiMemory?: boolean;
|
|
80
|
+
experimentalIdlImports?: boolean;
|
|
81
81
|
optArgs?: string[];
|
|
82
82
|
}): Promise<{
|
|
83
83
|
files: {
|
|
@@ -86,4 +86,4 @@ export function transpileComponent(component: Uint8Array, opts?: {
|
|
|
86
86
|
imports: string[];
|
|
87
87
|
exports: [string, "function" | "instance"][];
|
|
88
88
|
}>;
|
|
89
|
-
//# sourceMappingURL=transpile.d.ts.map
|
|
89
|
+
//# sourceMappingURL=transpile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["transpile.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transpile.d.ts","sourceRoot":"","sources":["transpile.js"],"names":[],"mappings":"AA+CA,8DAGC;AAED,mEAMC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wCAfW,MAAM,QACN;IACN,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAC5B,KAAK,CAAC,EAAE,IAAI,CAAC;CACd,GACS,OAAO,CAAC;IAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,CAAC,CA+DvD;AAyCD,sFAoCC;AAmBD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,8CAzBW,UAAU,SACV;IACN,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,QAAQ,GAAG,kBAAkB,CAAC;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,wBAAwB,CAAC,EAAE,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,YAAY,CAAC,EAAE,IAAI,CAAC;IACpB,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,QAAQ,CAAC,EAAE,IAAI,CAAC;IAChB,iBAAiB,CAAC,EAAE,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,sBAAsB,CAAC,EAAE,IAAI,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,GACS,OAAO,CAAC;IAAE,KAAK,EAAE;QAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,EAAE,CAAA;CAAE,CAAC,CAyTnI"}
|
package/src/cmd/transpile.js
CHANGED
|
@@ -70,7 +70,11 @@ export async function guestTypes(witPath, opts) {
|
|
|
70
70
|
* asyncImports?: string[],
|
|
71
71
|
* asyncExports?: string[],
|
|
72
72
|
* outDir?: string,
|
|
73
|
+
* allFeatures?: bool,
|
|
74
|
+
* feature?: string[] | 'all', // backwards compat
|
|
73
75
|
* features?: string[] | 'all',
|
|
76
|
+
* asyncWasiImports?: string[],
|
|
77
|
+
* asyncWasiExports?: string[],
|
|
74
78
|
* guest?: bool,
|
|
75
79
|
* }} opts
|
|
76
80
|
* @returns {Promise<{ [filename: string]: Uint8Array }>}
|
|
@@ -87,19 +91,25 @@ export async function typesComponent(witPath, opts) {
|
|
|
87
91
|
instantiation = { tag: opts.instantiation };
|
|
88
92
|
}
|
|
89
93
|
let outDir = (opts.outDir ?? '').replace(/\\/g, '/');
|
|
90
|
-
if (!outDir.endsWith('/') && outDir !== '')
|
|
94
|
+
if (!outDir.endsWith('/') && outDir !== '') {
|
|
95
|
+
outDir += '/';
|
|
96
|
+
}
|
|
91
97
|
|
|
92
98
|
let features = null;
|
|
93
99
|
if (opts.allFeatures) {
|
|
94
100
|
features = { tag: 'all' };
|
|
95
101
|
} else if (Array.isArray(opts.feature)) {
|
|
96
102
|
features = { tag: 'list', val: opts.feature };
|
|
103
|
+
} else if (Array.isArray(opts.features)) {
|
|
104
|
+
features = { tag: 'list', val: opts.features };
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
if (opts.asyncWasiImports)
|
|
107
|
+
if (opts.asyncWasiImports) {
|
|
100
108
|
opts.asyncImports = ASYNC_WASI_IMPORTS.concat(opts.asyncImports || []);
|
|
101
|
-
|
|
109
|
+
}
|
|
110
|
+
if (opts.asyncWasiExports) {
|
|
102
111
|
opts.asyncExports = ASYNC_WASI_EXPORTS.concat(opts.asyncExports || []);
|
|
112
|
+
}
|
|
103
113
|
|
|
104
114
|
const asyncMode =
|
|
105
115
|
!opts.asyncMode || opts.asyncMode === 'sync'
|
|
@@ -165,7 +175,9 @@ async function writeFiles(files, summaryTitle) {
|
|
|
165
175
|
await writeFile(name, file);
|
|
166
176
|
})
|
|
167
177
|
);
|
|
168
|
-
if (!summaryTitle)
|
|
178
|
+
if (!summaryTitle) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
169
181
|
console.log(c`
|
|
170
182
|
{bold ${summaryTitle}:}
|
|
171
183
|
|
|
@@ -177,39 +189,46 @@ ${table(
|
|
|
177
189
|
)}`);
|
|
178
190
|
}
|
|
179
191
|
|
|
180
|
-
export async function transpile(
|
|
192
|
+
export async function transpile(witPath, opts, program) {
|
|
181
193
|
const varIdx = program?.parent.rawArgs.indexOf('--');
|
|
182
|
-
if (varIdx !== undefined && varIdx !== -1)
|
|
194
|
+
if (varIdx !== undefined && varIdx !== -1) {
|
|
183
195
|
opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
|
|
196
|
+
}
|
|
184
197
|
|
|
185
198
|
let component;
|
|
186
199
|
if (!opts.stub) {
|
|
187
|
-
component = await readFile(
|
|
200
|
+
component = await readFile(witPath);
|
|
188
201
|
} else {
|
|
189
202
|
await wasmToolsInit;
|
|
190
203
|
component = componentNew(
|
|
191
204
|
componentEmbed({
|
|
192
205
|
dummy: true,
|
|
193
|
-
witPath: (isWindows ? '//?/' : '') + resolve(
|
|
206
|
+
witPath: (isWindows ? '//?/' : '') + resolve(witPath),
|
|
194
207
|
}),
|
|
195
208
|
[]
|
|
196
209
|
);
|
|
197
210
|
}
|
|
198
211
|
|
|
199
|
-
if (!opts.quiet)
|
|
200
|
-
|
|
212
|
+
if (!opts.quiet) {
|
|
213
|
+
setShowSpinner(true);
|
|
214
|
+
}
|
|
215
|
+
if (!opts.name) {
|
|
201
216
|
opts.name = basename(
|
|
202
|
-
|
|
217
|
+
witPath.slice(0, -extname(witPath).length || Infinity)
|
|
203
218
|
);
|
|
204
|
-
|
|
219
|
+
}
|
|
220
|
+
if (opts.map) {
|
|
205
221
|
opts.map = Object.fromEntries(
|
|
206
222
|
opts.map.map((mapping) => mapping.split('='))
|
|
207
223
|
);
|
|
224
|
+
}
|
|
208
225
|
|
|
209
|
-
if (opts.asyncWasiImports)
|
|
226
|
+
if (opts.asyncWasiImports) {
|
|
210
227
|
opts.asyncImports = ASYNC_WASI_IMPORTS.concat(opts.asyncImports || []);
|
|
211
|
-
|
|
228
|
+
}
|
|
229
|
+
if (opts.asyncWasiExports) {
|
|
212
230
|
opts.asyncExports = ASYNC_WASI_EXPORTS.concat(opts.asyncExports || []);
|
|
231
|
+
}
|
|
213
232
|
|
|
214
233
|
const { files } = await transpileComponent(component, opts);
|
|
215
234
|
await writeFiles(
|
|
@@ -230,13 +249,16 @@ async function wasm2Js(source) {
|
|
|
230
249
|
try {
|
|
231
250
|
return await spawnIOTmp(wasm2jsPath, source, ['-Oz', '-o']);
|
|
232
251
|
} catch (e) {
|
|
233
|
-
if (e.toString().includes('BasicBlock requested'))
|
|
252
|
+
if (e.toString().includes('BasicBlock requested')) {
|
|
234
253
|
return wasm2Js(source);
|
|
254
|
+
}
|
|
235
255
|
throw e;
|
|
236
256
|
}
|
|
237
257
|
}
|
|
238
258
|
|
|
239
259
|
/**
|
|
260
|
+
* Execute the bundled pre-transpiled component that can perform component transpilation,
|
|
261
|
+
* for the given component.
|
|
240
262
|
*
|
|
241
263
|
* @param {Uint8Array} component
|
|
242
264
|
* @param {{
|
|
@@ -265,13 +287,17 @@ async function wasm2Js(source) {
|
|
|
265
287
|
*/
|
|
266
288
|
export async function transpileComponent(component, opts = {}) {
|
|
267
289
|
await $init;
|
|
268
|
-
if (opts.instantiation)
|
|
290
|
+
if (opts.instantiation) {
|
|
291
|
+
opts.wasiShim = false;
|
|
292
|
+
}
|
|
269
293
|
|
|
270
294
|
let spinner;
|
|
271
295
|
const showSpinner = getShowSpinner();
|
|
272
296
|
|
|
273
297
|
if (opts.optimize) {
|
|
274
|
-
if (showSpinner)
|
|
298
|
+
if (showSpinner) {
|
|
299
|
+
setShowSpinner(true);
|
|
300
|
+
}
|
|
275
301
|
({ component } = await optimizeComponent(component, opts));
|
|
276
302
|
}
|
|
277
303
|
|
|
@@ -333,7 +359,9 @@ export async function transpileComponent(component, opts = {}) {
|
|
|
333
359
|
});
|
|
334
360
|
|
|
335
361
|
let outDir = (opts.outDir ?? '').replace(/\\/g, '/');
|
|
336
|
-
if (!outDir.endsWith('/') && outDir !== '')
|
|
362
|
+
if (!outDir.endsWith('/') && outDir !== '') {
|
|
363
|
+
outDir += '/';
|
|
364
|
+
}
|
|
337
365
|
files = files.map(([name, source]) => [`${outDir}${name}`, source]);
|
|
338
366
|
|
|
339
367
|
const jsFile = files.find(([name]) => name.endsWith('.js'));
|
|
@@ -583,7 +611,9 @@ ${autoInstantiate}`;
|
|
|
583
611
|
// for imports to match up we must do the same
|
|
584
612
|
// See https://github.com/WebAssembly/binaryen/blob/main/src/asmjs/asmangle.cpp
|
|
585
613
|
function asmMangle(name) {
|
|
586
|
-
if (name === '')
|
|
614
|
+
if (name === '') {
|
|
615
|
+
return '$';
|
|
616
|
+
}
|
|
587
617
|
|
|
588
618
|
let mightBeKeyword = true;
|
|
589
619
|
let i = 1;
|
|
@@ -657,11 +687,15 @@ function asmMangle(name) {
|
|
|
657
687
|
if (mightBeKeyword && len >= 2 && len <= 10) {
|
|
658
688
|
switch (name[0]) {
|
|
659
689
|
case 'a': {
|
|
660
|
-
if (name == 'arguments')
|
|
690
|
+
if (name == 'arguments') {
|
|
691
|
+
return name + '_';
|
|
692
|
+
}
|
|
661
693
|
break;
|
|
662
694
|
}
|
|
663
695
|
case 'b': {
|
|
664
|
-
if (name == 'break')
|
|
696
|
+
if (name == 'break') {
|
|
697
|
+
return name + '_';
|
|
698
|
+
}
|
|
665
699
|
break;
|
|
666
700
|
}
|
|
667
701
|
case 'c': {
|
|
@@ -671,13 +705,15 @@ function asmMangle(name) {
|
|
|
671
705
|
name == 'catch' ||
|
|
672
706
|
name == 'const' ||
|
|
673
707
|
name == 'class'
|
|
674
|
-
)
|
|
708
|
+
) {
|
|
675
709
|
return name + '_';
|
|
710
|
+
}
|
|
676
711
|
break;
|
|
677
712
|
}
|
|
678
713
|
case 'd': {
|
|
679
|
-
if (name == 'do' || name == 'default' || name == 'debugger')
|
|
714
|
+
if (name == 'do' || name == 'default' || name == 'debugger') {
|
|
680
715
|
return name + '_';
|
|
716
|
+
}
|
|
681
717
|
break;
|
|
682
718
|
}
|
|
683
719
|
case 'e': {
|
|
@@ -687,8 +723,9 @@ function asmMangle(name) {
|
|
|
687
723
|
name == 'eval' || // to be sure
|
|
688
724
|
name == 'export' ||
|
|
689
725
|
name == 'extends'
|
|
690
|
-
)
|
|
726
|
+
) {
|
|
691
727
|
return name + '_';
|
|
728
|
+
}
|
|
692
729
|
break;
|
|
693
730
|
}
|
|
694
731
|
case 'f': {
|
|
@@ -697,8 +734,9 @@ function asmMangle(name) {
|
|
|
697
734
|
name == 'false' ||
|
|
698
735
|
name == 'finally' ||
|
|
699
736
|
name == 'function'
|
|
700
|
-
)
|
|
737
|
+
) {
|
|
701
738
|
return name + '_';
|
|
739
|
+
}
|
|
702
740
|
break;
|
|
703
741
|
}
|
|
704
742
|
case 'i': {
|
|
@@ -709,16 +747,21 @@ function asmMangle(name) {
|
|
|
709
747
|
name == 'interface' ||
|
|
710
748
|
name == 'implements' ||
|
|
711
749
|
name == 'instanceof'
|
|
712
|
-
)
|
|
750
|
+
) {
|
|
713
751
|
return name + '_';
|
|
752
|
+
}
|
|
714
753
|
break;
|
|
715
754
|
}
|
|
716
755
|
case 'l': {
|
|
717
|
-
if (name == 'let')
|
|
756
|
+
if (name == 'let') {
|
|
757
|
+
return name + '_';
|
|
758
|
+
}
|
|
718
759
|
break;
|
|
719
760
|
}
|
|
720
761
|
case 'n': {
|
|
721
|
-
if (name == 'new' || name == 'null')
|
|
762
|
+
if (name == 'new' || name == 'null') {
|
|
763
|
+
return name + '_';
|
|
764
|
+
}
|
|
722
765
|
break;
|
|
723
766
|
}
|
|
724
767
|
case 'p': {
|
|
@@ -727,17 +770,21 @@ function asmMangle(name) {
|
|
|
727
770
|
name == 'package' ||
|
|
728
771
|
name == 'private' ||
|
|
729
772
|
name == 'protected'
|
|
730
|
-
)
|
|
773
|
+
) {
|
|
731
774
|
return name + '_';
|
|
775
|
+
}
|
|
732
776
|
break;
|
|
733
777
|
}
|
|
734
778
|
case 'r': {
|
|
735
|
-
if (name == 'return')
|
|
779
|
+
if (name == 'return') {
|
|
780
|
+
return name + '_';
|
|
781
|
+
}
|
|
736
782
|
break;
|
|
737
783
|
}
|
|
738
784
|
case 's': {
|
|
739
|
-
if (name == 'super' || name == 'static' || name == 'switch')
|
|
785
|
+
if (name == 'super' || name == 'static' || name == 'switch') {
|
|
740
786
|
return name + '_';
|
|
787
|
+
}
|
|
741
788
|
break;
|
|
742
789
|
}
|
|
743
790
|
case 't': {
|
|
@@ -747,20 +794,27 @@ function asmMangle(name) {
|
|
|
747
794
|
name == 'true' ||
|
|
748
795
|
name == 'throw' ||
|
|
749
796
|
name == 'typeof'
|
|
750
|
-
)
|
|
797
|
+
) {
|
|
751
798
|
return name + '_';
|
|
799
|
+
}
|
|
752
800
|
break;
|
|
753
801
|
}
|
|
754
802
|
case 'v': {
|
|
755
|
-
if (name == 'var' || name == 'void')
|
|
803
|
+
if (name == 'var' || name == 'void') {
|
|
804
|
+
return name + '_';
|
|
805
|
+
}
|
|
756
806
|
break;
|
|
757
807
|
}
|
|
758
808
|
case 'w': {
|
|
759
|
-
if (name == 'with' || name == 'while')
|
|
809
|
+
if (name == 'with' || name == 'while') {
|
|
810
|
+
return name + '_';
|
|
811
|
+
}
|
|
760
812
|
break;
|
|
761
813
|
}
|
|
762
814
|
case 'y': {
|
|
763
|
-
if (name == 'yield')
|
|
815
|
+
if (name == 'yield') {
|
|
816
|
+
return name + '_';
|
|
817
|
+
}
|
|
764
818
|
break;
|
|
765
819
|
}
|
|
766
820
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wasm-tools.d.ts","sourceRoot":"","sources":["wasm-tools.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wasm-tools.d.ts","sourceRoot":"","sources":["wasm-tools.js"],"names":[],"mappings":"AAOA,2DAKC;AAED,2DASC;AAED,kEASC;AAED,kEAsBC;AAED,oEAaC;AAED,iEAUC;AAED,kEAiCC"}
|