@bytecodealliance/jco 1.14.0 → 1.15.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/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +2 -6
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +2 -6
- package/package.json +7 -6
- package/src/cmd/componentize.js +52 -12
- package/src/cmd/opt.js +38 -34
- package/src/cmd/run.js +8 -8
- package/src/cmd/transpile.js +171 -171
- package/src/cmd/types.js +39 -8
- package/src/cmd/wasm-tools.js +6 -6
- package/src/common.js +118 -25
- package/src/jco.js +28 -10
- package/types/api.d.ts.map +1 -0
- package/types/browser.d.ts.map +1 -0
- package/types/common.d.ts +80 -0
- package/types/common.d.ts.map +1 -0
- package/types/jco.d.ts.map +1 -0
- package/types/ora-shim.d.ts.map +1 -0
- package/src/api.d.ts.map +0 -1
- package/src/browser.d.ts.map +0 -1
- package/src/common.d.ts +0 -20
- package/src/common.d.ts.map +0 -1
- package/src/jco.d.ts.map +0 -1
- package/src/ora-shim.d.ts.map +0 -1
- /package/{src → types}/api.d.ts +0 -0
- /package/{src → types}/browser.d.ts +0 -0
- /package/{src → types}/jco.d.ts +0 -0
- /package/{src → types}/ora-shim.d.ts +0 -0
|
Binary file
|
|
@@ -261,8 +261,6 @@ class AsyncTask {
|
|
|
261
261
|
this.#state = AsyncTask.State.CANCEL_DELIVERED;
|
|
262
262
|
return {
|
|
263
263
|
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
264
|
-
something: 0,
|
|
265
|
-
something: 0,
|
|
266
264
|
};
|
|
267
265
|
}
|
|
268
266
|
|
|
@@ -283,8 +281,6 @@ class AsyncTask {
|
|
|
283
281
|
this.#state = AsyncTask.State.CANCELLED;
|
|
284
282
|
return {
|
|
285
283
|
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
286
|
-
something: 0,
|
|
287
|
-
something: 0,
|
|
288
284
|
};
|
|
289
285
|
}
|
|
290
286
|
|
|
@@ -5040,8 +5036,8 @@ export const $init = (() => {
|
|
|
5040
5036
|
let gen = (function* init () {
|
|
5041
5037
|
const module0 = fetchCompile(new URL('./js-component-bindgen-component.core.wasm', import.meta.url));
|
|
5042
5038
|
const module1 = fetchCompile(new URL('./js-component-bindgen-component.core2.wasm', import.meta.url));
|
|
5043
|
-
const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAFf39/fn8Bf2AFf39/f38Bf2AJf39/f39+fn9/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUCBAcECAkCAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+
|
|
5044
|
-
const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAFf39/fn8Bf2AFf39/f38Bf2AJf39/f39+fn9/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+
|
|
5039
|
+
const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAFf39/fn8Bf2AFf39/f38Bf2AJf39/f39+fn9/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUCBAcECAkCAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+QMlCwAgACABQQARAgALDwAgACABIAIgA0EBEQQACxEAIAAgASACIAMgBEECEQcACw8AIAAgASACIANBAxEEAAsRACAAIAEgAiADIARBBBEIAAsZACAAIAEgAiADIAQgBSAGIAcgCEEFEQkACwsAIAAgAUEGEQIACwsAIAAgAUEHEQIACwsAIAAgAUEIEQIACwkAIABBCREKAAsLACAAIAFBChECAAsNACAAIAEgAkELEQsACwkAIABBDBEBAAsJACAAQQ0RAQALCwAgACABQQ4RAAALCwAgACABQQ8RAAALCwAgACABQRARAAALEQAgACABIAIgAyAEQRERBQALDQAgACABIAJBEhEDAAsNACAAIAEgAkETEQMACwsAIAAgAUEUEQAACwsAIAAgAUEVEQAACwsAIAAgAUEWEQAACxEAIAAgASACIAMgBEEXEQUACxUAIAAgASACIAMgBCAFIAZBGBEMAAsLACAAIAFBGREAAAsNACAAIAEgAkEaEQMACw0AIAAgASACQRsRAwALCwAgACABQRwRAAALDwAgACABIAIgA0EdEQYACw8AIAAgASACIANBHhEGAAsLACAAIAFBHxEAAAsLACAAIAFBIBENAAsJACAAQSERAQALCQAgAEEiEQEACwkAIABBIxEBAAsJACAAQSQRAQALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yMzguMQ');
|
|
5040
|
+
const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAFf39/fn8Bf2AFf39/f38Bf2AJf39/f39+fn9/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwAC5AEmAAEwAAIAATEABAABMgAHAAEzAAQAATQACAABNQAJAAE2AAIAATcAAgABOAACAAE5AAoAAjEwAAIAAjExAAsAAjEyAAEAAjEzAAEAAjE0AAAAAjE1AAAAAjE2AAAAAjE3AAUAAjE4AAMAAjE5AAMAAjIwAAAAAjIxAAAAAjIyAAAAAjIzAAUAAjI0AAwAAjI1AAAAAjI2AAMAAjI3AAMAAjI4AAAAAjI5AAYAAjMwAAYAAjMxAAAAAjMyAA0AAjMzAAEAAjM0AAEAAjM1AAEAAjM2AAEACCRpbXBvcnRzAXABJSUJKwEAQQALJQABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIzOC4x');
|
|
5045
5041
|
({ exports: exports0 } = yield instantiateCore(yield module2));
|
|
5046
5042
|
({ exports: exports1 } = yield instantiateCore(yield module0, {
|
|
5047
5043
|
wasi_snapshot_preview1: {
|
package/obj/wasm-tools.core.wasm
CHANGED
|
Binary file
|
package/obj/wasm-tools.js
CHANGED
|
@@ -261,8 +261,6 @@ class AsyncTask {
|
|
|
261
261
|
this.#state = AsyncTask.State.CANCEL_DELIVERED;
|
|
262
262
|
return {
|
|
263
263
|
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
264
|
-
something: 0,
|
|
265
|
-
something: 0,
|
|
266
264
|
};
|
|
267
265
|
}
|
|
268
266
|
|
|
@@ -283,8 +281,6 @@ class AsyncTask {
|
|
|
283
281
|
this.#state = AsyncTask.State.CANCELLED;
|
|
284
282
|
return {
|
|
285
283
|
code: ASYNC_EVENT_CODE.TASK_CANCELLED,
|
|
286
|
-
something: 0,
|
|
287
|
-
something: 0,
|
|
288
284
|
};
|
|
289
285
|
}
|
|
290
286
|
|
|
@@ -5172,8 +5168,8 @@ export const $init = (() => {
|
|
|
5172
5168
|
let gen = (function* init () {
|
|
5173
5169
|
const module0 = fetchCompile(new URL('./wasm-tools.core.wasm', import.meta.url));
|
|
5174
5170
|
const module1 = fetchCompile(new URL('./wasm-tools.core2.wasm', import.meta.url));
|
|
5175
|
-
const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUHCAkCAgQEAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+
|
|
5176
|
-
const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+
|
|
5171
|
+
const module2 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwADJiUHCAkCAgQEAgIKAgsBAQAAAAUDAwAAAAUMAAMDAAYGAA0BAQEBBAUBcAElJQe7ASYBMAAAATEAAQEyAAIBMwADATQABAE1AAUBNgAGATcABwE4AAgBOQAJAjEwAAoCMTEACwIxMgAMAjEzAA0CMTQADgIxNQAPAjE2ABACMTcAEQIxOAASAjE5ABMCMjAAFAIyMQAVAjIyABYCMjMAFwIyNAAYAjI1ABkCMjYAGgIyNwAbAjI4ABwCMjkAHQIzMAAeAjMxAB8CMzIAIAIzMwAhAjM0ACICMzUAIwIzNgAkCCRpbXBvcnRzAQAK+QMlGQAgACABIAIgAyAEIAUgBiAHIAhBABEHAAsRACAAIAEgAiADIARBAREIAAsRACAAIAEgAiADIARBAhEJAAsLACAAIAFBAxECAAsLACAAIAFBBBECAAsPACAAIAEgAiADQQURBAALDwAgACABIAIgA0EGEQQACwsAIAAgAUEHEQIACwsAIAAgAUEIEQIACwkAIABBCREKAAsLACAAIAFBChECAAsNACAAIAEgAkELEQsACwkAIABBDBEBAAsJACAAQQ0RAQALCwAgACABQQ4RAAALCwAgACABQQ8RAAALCwAgACABQRARAAALEQAgACABIAIgAyAEQRERBQALDQAgACABIAJBEhEDAAsNACAAIAEgAkETEQMACwsAIAAgAUEUEQAACwsAIAAgAUEVEQAACwsAIAAgAUEWEQAACxEAIAAgASACIAMgBEEXEQUACxUAIAAgASACIAMgBCAFIAZBGBEMAAsLACAAIAFBGREAAAsNACAAIAEgAkEaEQMACw0AIAAgASACQRsRAwALCwAgACABQRwRAAALDwAgACABIAIgA0EdEQYACw8AIAAgASACIANBHhEGAAsLACAAIAFBHxEAAAsLACAAIAFBIBENAAsJACAAQSERAQALCQAgAEEiEQEACwkAIABBIxEBAAsJACAAQSQRAQALAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBDXdpdC1jb21wb25lbnQHMC4yMzguMQ');
|
|
5172
|
+
const module3 = base64Compile('AGFzbQEAAAABZw5gAn9/AGABfwBgAn9/AX9gA39+fwBgBH9/f38Bf2AFf39/f38AYAR/f39/AGAJf39/f39+fn9/AX9gBX9/f35/AX9gBX9/f39/AX9gAX8Bf2ADf39/AX9gB39/f39/f38AYAJ+fwAC5AEmAAEwAAcAATEACAABMgAJAAEzAAIAATQAAgABNQAEAAE2AAQAATcAAgABOAACAAE5AAoAAjEwAAIAAjExAAsAAjEyAAEAAjEzAAEAAjE0AAAAAjE1AAAAAjE2AAAAAjE3AAUAAjE4AAMAAjE5AAMAAjIwAAAAAjIxAAAAAjIyAAAAAjIzAAUAAjI0AAwAAjI1AAAAAjI2AAMAAjI3AAMAAjI4AAAAAjI5AAYAAjMwAAYAAjMxAAAAAjMyAA0AAjMzAAEAAjM0AAEAAjM1AAEAAjM2AAEACCRpbXBvcnRzAXABJSUJKwEAQQALJQABAgMEBQYHCAkKCwwNDg8QERITFBUWFxgZGhscHR4fICEiIyQALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIzOC4x');
|
|
5177
5173
|
({ exports: exports0 } = yield instantiateCore(yield module2));
|
|
5178
5174
|
({ exports: exports1 } = yield instantiateCore(yield module0, {
|
|
5179
5175
|
wasi_snapshot_preview1: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/jco",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "JavaScript tooling for working with WebAssembly Components",
|
|
5
5
|
"homepage": "https://github.com/bytecodealliance/jco#readme",
|
|
6
6
|
"author": "Guy Bedford",
|
|
@@ -23,18 +23,22 @@
|
|
|
23
23
|
"WebAssembly",
|
|
24
24
|
"Component"
|
|
25
25
|
],
|
|
26
|
+
"main": "src/jco.js",
|
|
27
|
+
"types": "types/jco.d.ts",
|
|
26
28
|
"repository": {
|
|
27
29
|
"type": "git",
|
|
28
30
|
"url": "git+https://github.com/bytecodealliance/jco.git"
|
|
29
31
|
},
|
|
30
32
|
"imports": {
|
|
31
33
|
"#ora": {
|
|
34
|
+
"types": "./src/ora-shim.d.ts",
|
|
32
35
|
"browser": "./src/ora-shim.js",
|
|
33
36
|
"default": "ora"
|
|
34
37
|
}
|
|
35
38
|
},
|
|
36
39
|
"exports": {
|
|
37
40
|
".": {
|
|
41
|
+
"types": "./types/api.d.ts",
|
|
38
42
|
"browser": "./src/browser.js",
|
|
39
43
|
"default": "./src/api.js"
|
|
40
44
|
},
|
|
@@ -49,6 +53,7 @@
|
|
|
49
53
|
"files": [
|
|
50
54
|
"lib",
|
|
51
55
|
"src",
|
|
56
|
+
"types",
|
|
52
57
|
"obj/*.core*.wasm",
|
|
53
58
|
"obj/*.js",
|
|
54
59
|
"obj/*.ts",
|
|
@@ -58,7 +63,7 @@
|
|
|
58
63
|
"build": "cargo xtask build debug",
|
|
59
64
|
"build:release": "cargo xtask build release",
|
|
60
65
|
"build:types:preview2-shim": "npm run build:types:preview2-shim --include-workspace-root",
|
|
61
|
-
"fmt": "
|
|
66
|
+
"fmt": "npm run lint:fix",
|
|
62
67
|
"lint": "eslint -c ../../eslint.config.mjs --ext .js src test",
|
|
63
68
|
"lint:fix": "npm run lint -- --fix",
|
|
64
69
|
"test": "vitest run -c test/vitest.ts",
|
|
@@ -69,7 +74,6 @@
|
|
|
69
74
|
"@bytecodealliance/componentize-js": "^0.18.4",
|
|
70
75
|
"@bytecodealliance/preview2-shim": "^0.17.3",
|
|
71
76
|
"binaryen": "^123.0.0",
|
|
72
|
-
"chalk-template": "^1",
|
|
73
77
|
"commander": "^14",
|
|
74
78
|
"mkdirp": "^3",
|
|
75
79
|
"ora": "^8",
|
|
@@ -83,10 +87,7 @@
|
|
|
83
87
|
"commitlint": "^19.8.1",
|
|
84
88
|
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
85
89
|
"eslint": "^9.33.0",
|
|
86
|
-
"eslint-config-prettier": "^10.1.8",
|
|
87
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
88
90
|
"mime": "^4.0.7",
|
|
89
|
-
"prettier": "^3.6.2",
|
|
90
91
|
"puppeteer": "^24.16.2",
|
|
91
92
|
"semver": "^7.7.1",
|
|
92
93
|
"smol-toml": "^1.4.2",
|
package/src/cmd/componentize.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { stat, readFile, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { resolve, basename } from 'node:path';
|
|
3
|
+
import { styleText } from '../common.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
/** All features that can be enabled/disabled */
|
|
6
|
+
const ALL_FEATURES = ['clocks', 'http', 'random', 'stdio', 'fetch-event'];
|
|
7
|
+
|
|
8
|
+
/** Features that should be used for --debug mode */
|
|
9
|
+
const DEBUG_FEATURES = ['stdio'];
|
|
5
10
|
|
|
6
11
|
export async function componentize(jsSource, opts) {
|
|
7
12
|
const { componentize: componentizeFn } = await eval(
|
|
8
13
|
'import("@bytecodealliance/componentize-js")'
|
|
9
14
|
);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
const { disableFeatures, enableFeatures } = calculateFeatureSet(opts);
|
|
17
|
+
|
|
13
18
|
const source = await readFile(jsSource, 'utf8');
|
|
14
19
|
|
|
15
20
|
const witPath = resolve(opts.wit);
|
|
@@ -24,8 +29,8 @@ export async function componentize(jsSource, opts) {
|
|
|
24
29
|
sourceName,
|
|
25
30
|
witPath,
|
|
26
31
|
worldName: opts.worldName,
|
|
27
|
-
disableFeatures
|
|
28
|
-
enableFeatures
|
|
32
|
+
disableFeatures,
|
|
33
|
+
enableFeatures,
|
|
29
34
|
preview2Adapter: opts.preview2Adapter,
|
|
30
35
|
debugBuild: opts.debugStarlingmonkeyBuild,
|
|
31
36
|
engine: opts.engine,
|
|
@@ -39,7 +44,7 @@ export async function componentize(jsSource, opts) {
|
|
|
39
44
|
});
|
|
40
45
|
if (result.debug) {
|
|
41
46
|
console.error(
|
|
42
|
-
|
|
47
|
+
`${styleText('cyan', 'DEBUG')} Debug output\n${JSON.stringify(debug, null, 2)}\n`
|
|
43
48
|
);
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -60,7 +65,7 @@ export async function componentize(jsSource, opts) {
|
|
|
60
65
|
|
|
61
66
|
await writeFile(opts.out, component);
|
|
62
67
|
|
|
63
|
-
console.log(
|
|
68
|
+
console.log(`${styleText('green', 'OK')} Successfully written ${styleText('bold', opts.out)}.`);
|
|
64
69
|
}
|
|
65
70
|
|
|
66
71
|
/**
|
|
@@ -70,14 +75,49 @@ export async function componentize(jsSource, opts) {
|
|
|
70
75
|
* @returns {string} user-visible, highlighted output that can be printed
|
|
71
76
|
*/
|
|
72
77
|
async function printWITPathHint(witPath) {
|
|
78
|
+
const warningPrefix = styleText(['yellow', 'bold'], 'warning');
|
|
73
79
|
const pathMeta = await stat(witPath);
|
|
74
80
|
let output = '\n';
|
|
75
81
|
if (!pathMeta.isFile() && !pathMeta.isDirectory()) {
|
|
76
|
-
output +=
|
|
82
|
+
output += `${warningPrefix} The supplited WIT path [${witPath}] is neither a file or directory.\n`;
|
|
77
83
|
return output;
|
|
78
84
|
}
|
|
79
|
-
output +=
|
|
80
|
-
output +=
|
|
81
|
-
output +=
|
|
85
|
+
output += `${warningPrefix} Your WIT path option [${witPath}] may be incorrect\n`;
|
|
86
|
+
output += `${warningPrefix} When using a world with dependencies, you must pass the enclosing WIT folder, not a single file.\n`;
|
|
87
|
+
output += `${warningPrefix} (e.g. 'wit/', rather than 'wit/component.wit').\n`;
|
|
82
88
|
return output;
|
|
83
89
|
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Build set of disabled features
|
|
93
|
+
*
|
|
94
|
+
* At present, `componentize-js` does not use enabled features but exclusively
|
|
95
|
+
* takes into account disabled features.
|
|
96
|
+
*
|
|
97
|
+
* @param {{ debug: boolean, disable: string[], enable: string[] }} opts
|
|
98
|
+
* @returns {{ disableFeatures: string[], enableFeatures: string[] }}
|
|
99
|
+
*/
|
|
100
|
+
function calculateFeatureSet(opts) {
|
|
101
|
+
const disableFeatures = new Set(opts?.debug ? DEBUG_FEATURES : []);
|
|
102
|
+
const disable = opts?.disable ?? [];
|
|
103
|
+
const enable = opts?.enable ?? [];
|
|
104
|
+
|
|
105
|
+
// Process disabled features
|
|
106
|
+
if (disable.includes('all')) {
|
|
107
|
+
ALL_FEATURES.forEach((v) => disableFeatures.add(v));
|
|
108
|
+
} else {
|
|
109
|
+
disable.forEach((v) => disableFeatures.add(v));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Process enabled features
|
|
113
|
+
if (enable.includes('all')) {
|
|
114
|
+
ALL_FEATURES.forEach((v) => disableFeatures.delete(v));
|
|
115
|
+
} else {
|
|
116
|
+
enable.forEach((v) => disableFeatures.delete(v));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
disableFeatures: [...disableFeatures],
|
|
121
|
+
enableFeatures: ALL_FEATURES.filter((v) => !disableFeatures.has(v)),
|
|
122
|
+
};
|
|
123
|
+
}
|
package/src/cmd/opt.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
|
+
|
|
1
3
|
import { $init, tools } from '../../obj/wasm-tools.js';
|
|
2
4
|
const { metadataShow, print } = tools;
|
|
3
|
-
import { writeFile } from 'fs/promises';
|
|
4
5
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import c from 'chalk-template';
|
|
6
6
|
import {
|
|
7
7
|
readFile,
|
|
8
8
|
sizeStr,
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
} from '../common.js';
|
|
15
15
|
import ora from '#ora';
|
|
16
16
|
|
|
17
|
+
import { styleText } from '../common.js';
|
|
18
|
+
|
|
17
19
|
export async function opt(componentPath, opts, program) {
|
|
18
20
|
await $init;
|
|
19
21
|
const varIdx = program.parent.rawArgs.indexOf('--');
|
|
@@ -34,33 +36,35 @@ export async function opt(componentPath, opts, program) {
|
|
|
34
36
|
totalAfterBytes = 0;
|
|
35
37
|
|
|
36
38
|
if (!opts.quiet) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const tableContent = table(
|
|
40
|
+
[
|
|
41
|
+
...compressionInfo.map(({ beforeBytes, afterBytes }, i) => {
|
|
42
|
+
totalBeforeBytes += beforeBytes;
|
|
43
|
+
totalAfterBytes += afterBytes;
|
|
44
|
+
return [
|
|
45
|
+
` - Core Module ${i + 1}: `,
|
|
46
|
+
sizeStr(beforeBytes),
|
|
47
|
+
' -> ',
|
|
48
|
+
`${styleText('cyan', sizeStr(afterBytes))} `,
|
|
49
|
+
`(${fixedDigitDisplay((afterBytes / beforeBytes) * 100, 2)}%)`,
|
|
50
|
+
];
|
|
51
|
+
}),
|
|
52
|
+
['', '', '', '', ''],
|
|
53
|
+
[
|
|
54
|
+
` = Total: `,
|
|
55
|
+
`${sizeStr(totalBeforeBytes)}`,
|
|
56
|
+
` => `,
|
|
57
|
+
`${styleText('cyan', sizeStr(totalAfterBytes))} `,
|
|
58
|
+
`(${fixedDigitDisplay((totalAfterBytes / totalBeforeBytes) * 100, 2)}%)`,
|
|
59
|
+
],
|
|
60
|
+
],
|
|
61
|
+
[, , , , 'right']
|
|
62
|
+
);
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
totalAfterBytes += afterBytes;
|
|
45
|
-
return [
|
|
46
|
-
` - Core Module ${i + 1}: `,
|
|
47
|
-
sizeStr(beforeBytes),
|
|
48
|
-
' -> ',
|
|
49
|
-
c`{cyan ${sizeStr(afterBytes)}} `,
|
|
50
|
-
`(${fixedDigitDisplay((afterBytes / beforeBytes) * 100, 2)}%)`,
|
|
51
|
-
];
|
|
52
|
-
}),
|
|
53
|
-
['', '', '', '', ''],
|
|
54
|
-
[
|
|
55
|
-
` = Total: `,
|
|
56
|
-
`${sizeStr(totalBeforeBytes)}`,
|
|
57
|
-
` => `,
|
|
58
|
-
c`{cyan ${sizeStr(totalAfterBytes)}} `,
|
|
59
|
-
`(${fixedDigitDisplay((totalAfterBytes / totalBeforeBytes) * 100, 2)}%)`,
|
|
60
|
-
],
|
|
61
|
-
],
|
|
62
|
-
[, , , , 'right']
|
|
63
|
-
)}`);
|
|
64
|
+
console.log(`
|
|
65
|
+
${styleText('bold', "Optimized WebAssembly Component Internal Core Modules:")}
|
|
66
|
+
|
|
67
|
+
${tableContent}`);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
|
|
@@ -104,7 +108,7 @@ export async function optimizeComponent(componentBytes, opts) {
|
|
|
104
108
|
// log number of core Wasm modules to be run with wasm-opt
|
|
105
109
|
let completed = 0;
|
|
106
110
|
const spinnerText = () =>
|
|
107
|
-
|
|
111
|
+
`${styleText('cyan', `${completed} / ${coreModules.length}`)} Running Binaryen on WebAssembly Component Internal Core Modules \n`;
|
|
108
112
|
if (showSpinner) {
|
|
109
113
|
spinner = ora({
|
|
110
114
|
color: 'cyan',
|
|
@@ -117,11 +121,11 @@ export async function optimizeComponent(componentBytes, opts) {
|
|
|
117
121
|
const args = opts?.optArgs
|
|
118
122
|
? [...opts.optArgs]
|
|
119
123
|
: [
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
'-Oz',
|
|
125
|
+
'--low-memory-unused',
|
|
126
|
+
'--enable-bulk-memory',
|
|
127
|
+
'--strip-debug',
|
|
128
|
+
];
|
|
125
129
|
if (opts?.asyncify) {
|
|
126
130
|
args.push('--asyncify');
|
|
127
131
|
}
|
package/src/cmd/run.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getTmpDir } from '../common.js';
|
|
2
|
-
import { transpile } from './transpile.js';
|
|
3
1
|
import { rm, mkdir, writeFile, symlink } from 'node:fs/promises';
|
|
4
2
|
import { basename, resolve, extname } from 'node:path';
|
|
5
3
|
import { spawn } from 'node:child_process';
|
|
6
4
|
import process from 'node:process';
|
|
7
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
import { getTmpDir, styleText } from '../common.js';
|
|
8
|
+
import { transpile } from './transpile.js';
|
|
9
9
|
|
|
10
10
|
const DEFAULT_SERVE_HOST = 'localhost';
|
|
11
11
|
|
|
@@ -54,8 +54,8 @@ export async function serve(componentPath, args, opts) {
|
|
|
54
54
|
const server = new HTTPServer(mod.incomingHandler);
|
|
55
55
|
let port = ${port};
|
|
56
56
|
${
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
tryFindPort
|
|
58
|
+
? `
|
|
59
59
|
while (true) {
|
|
60
60
|
try {
|
|
61
61
|
server.listen(port, ${JSON.stringify(host)});
|
|
@@ -67,8 +67,8 @@ export async function serve(componentPath, args, opts) {
|
|
|
67
67
|
port++;
|
|
68
68
|
}
|
|
69
69
|
`
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
: `server.listen(port, ${JSON.stringify(host)})`
|
|
71
|
+
}
|
|
72
72
|
console.error(\`Server listening @ ${host}:${port}...\`);
|
|
73
73
|
`
|
|
74
74
|
);
|
|
@@ -117,7 +117,7 @@ async function runComponent(componentPath, args, opts, executor) {
|
|
|
117
117
|
'../../../'
|
|
118
118
|
);
|
|
119
119
|
} catch (err) {
|
|
120
|
-
let msg =
|
|
120
|
+
let msg = `${styleText(['red', 'bold'], 'error')} Failed to resolve ${styleText('bold', '@bytecodealliance/preview2-shim')}, ensure it is installed.`;
|
|
121
121
|
msg += `\nERROR:\n${err.toString()}`;
|
|
122
122
|
throw new Error(msg);
|
|
123
123
|
}
|