@bytecodealliance/jco 0.14.1 → 1.0.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 +20 -6
- package/lib/wasi_snapshot_preview1.command.wasm +0 -0
- package/lib/wasi_snapshot_preview1.reactor.wasm +0 -0
- package/obj/interfaces/wasi-filesystem-types.d.ts +12 -4
- package/obj/js-component-bindgen-component.component.wasm +0 -0
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.core2.wasm +0 -0
- package/obj/js-component-bindgen-component.d.ts +0 -1
- package/obj/js-component-bindgen-component.js +91 -106
- package/obj/wasm-tools.component.wasm +0 -0
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.core2.wasm +0 -0
- package/obj/wasm-tools.d.ts +0 -1
- package/obj/wasm-tools.js +1209 -304
- package/package.json +4 -4
- package/src/api.d.ts +7 -7
- package/src/api.d.ts.map +1 -1
- package/src/cmd/run.d.ts +1 -0
- package/src/cmd/run.d.ts.map +1 -1
- package/src/cmd/run.js +54 -24
- package/src/cmd/transpile.d.ts.map +1 -1
- package/src/cmd/transpile.js +22 -7
- package/src/cmd/wasm-tools.d.ts.map +1 -1
- package/src/cmd/wasm-tools.js +0 -1
- package/src/jco.js +43 -7
- package/obj/interfaces/wasi-sockets-tcp.d.ts +0 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytecodealliance/jco",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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.
|
|
21
|
+
"@bytecodealliance/preview2-shim": "0.15.1",
|
|
22
22
|
"binaryen": "^111.0.0",
|
|
23
23
|
"chalk-template": "^0.4.0",
|
|
24
24
|
"commander": "^9.4.1",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"terser": "^5.16.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@bytecodealliance/componentize-js": "^0.
|
|
30
|
+
"@bytecodealliance/componentize-js": "^0.6.0",
|
|
31
31
|
"@types/node": "^18.11.17",
|
|
32
32
|
"@typescript-eslint/eslint-plugin": "^5.41.0",
|
|
33
33
|
"@typescript-eslint/parser": "^5.41.0",
|
|
34
34
|
"eslint": "^8.30.0",
|
|
35
35
|
"mocha": "^10.2.0",
|
|
36
36
|
"terser": "^5.16.1",
|
|
37
|
-
"typescript": "^
|
|
37
|
+
"typescript": "^5.3.3"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
package/src/api.d.ts
CHANGED
|
@@ -2,39 +2,39 @@
|
|
|
2
2
|
* @param {Parameters<import('../obj/wasm-tools.js').print>[0]} binary
|
|
3
3
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').print>>}
|
|
4
4
|
*/
|
|
5
|
-
export function print(binary:
|
|
5
|
+
export function print(binary: any): Promise<ReturnType<import('../obj/wasm-tools.js').print>>;
|
|
6
6
|
/**
|
|
7
7
|
* @param {Parameters<import('../obj/wasm-tools.js').parse>[0]} wat
|
|
8
8
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').parse>>}
|
|
9
9
|
*/
|
|
10
|
-
export function parse(wat:
|
|
10
|
+
export function parse(wat: any): Promise<ReturnType<import('../obj/wasm-tools.js').parse>>;
|
|
11
11
|
/**
|
|
12
12
|
* @param {Parameters<import('../obj/wasm-tools.js').componentWit>[0]} binary
|
|
13
13
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentWit>>}
|
|
14
14
|
*/
|
|
15
|
-
export function componentWit(binary:
|
|
15
|
+
export function componentWit(binary: any): Promise<ReturnType<import('../obj/wasm-tools.js').componentWit>>;
|
|
16
16
|
/**
|
|
17
17
|
* @param {Parameters<import('../obj/wasm-tools.js').componentNew>[0]} binary
|
|
18
18
|
* @param {Parameters<import('../obj/wasm-tools.js').componentNew>[1]} adapters
|
|
19
19
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentNew>>}
|
|
20
20
|
*/
|
|
21
|
-
export function componentNew(binary:
|
|
21
|
+
export function componentNew(binary: any, adapters: any): Promise<ReturnType<import('../obj/wasm-tools.js').componentNew>>;
|
|
22
22
|
/**
|
|
23
23
|
* @param {Parameters<import('../obj/wasm-tools.js').componentEmbed>[0]} embedOpts
|
|
24
24
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').componentEmbed>>}
|
|
25
25
|
*/
|
|
26
|
-
export function componentEmbed(embedOpts:
|
|
26
|
+
export function componentEmbed(embedOpts: any): Promise<ReturnType<import('../obj/wasm-tools.js').componentEmbed>>;
|
|
27
27
|
/**
|
|
28
28
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[0]} binary
|
|
29
29
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataAdd>[1]} metadata
|
|
30
30
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataAdd>>}
|
|
31
31
|
*/
|
|
32
|
-
export function metadataAdd(binary:
|
|
32
|
+
export function metadataAdd(binary: any, metadata: any): Promise<ReturnType<import('../obj/wasm-tools.js').metadataAdd>>;
|
|
33
33
|
/**
|
|
34
34
|
* @param {Parameters<import('../obj/wasm-tools.js').metadataShow>[0]} binary
|
|
35
35
|
* @return {Promise<ReturnType<import('../obj/wasm-tools.js').metadataShow>>}
|
|
36
36
|
*/
|
|
37
|
-
export function metadataShow(binary:
|
|
37
|
+
export function metadataShow(binary: any): Promise<ReturnType<import('../obj/wasm-tools.js').metadataShow>>;
|
|
38
38
|
export function preview1AdapterCommandPath(): URL;
|
|
39
39
|
export function preview1AdapterReactorPath(): URL;
|
|
40
40
|
export { optimizeComponent as opt } from "./cmd/opt.js";
|
package/src/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.js"],"names":[],"mappings":"AAKA;;;GAGG;AACH,oCAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,iCAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,KAAK,CAAC,CAAC,CAKpE;AACD;;;GAGG;AACH,2CAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC,CAK3E;AACD;;;;GAIG;AACH,0DAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC,CAK3E;AACD;;;GAGG;AACH,gDAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,cAAc,CAAC,CAAC,CAK7E;AACD;;;;GAIG;AACH,yDAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,WAAW,CAAC,CAAC,CAK1E;AACD;;;GAGG;AACH,2CAFY,QAAQ,WAAW,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC,CAK3E;AACD,kDAEC;AACD,kDAEC"}
|
package/src/cmd/run.d.ts
CHANGED
package/src/cmd/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AASA,
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AASA,6EAmBC;AAED,+EA2BC"}
|
package/src/cmd/run.js
CHANGED
|
@@ -10,7 +10,54 @@ import c from 'chalk-template';
|
|
|
10
10
|
export async function run (componentPath, args, opts) {
|
|
11
11
|
// Ensure that `args` is an array
|
|
12
12
|
args = [...args];
|
|
13
|
+
return runComponent(componentPath, args, opts, `
|
|
14
|
+
if (!mod.run || !mod.run.run) {
|
|
15
|
+
console.error('Not a valid command component to execute.');
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
mod.run.run();
|
|
20
|
+
// for stdout flushing
|
|
21
|
+
await new Promise(resolve => setTimeout(resolve));
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
console.error(e);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function serve (componentPath, args, opts) {
|
|
32
|
+
let tryFindPort = false;
|
|
33
|
+
let { port, host } = opts;
|
|
34
|
+
if (port === undefined) {
|
|
35
|
+
tryFindPort = true;
|
|
36
|
+
port = '8000';
|
|
37
|
+
}
|
|
38
|
+
// Ensure that `args` is an array
|
|
39
|
+
args = [...args];
|
|
40
|
+
return runComponent(componentPath, args, opts, `
|
|
41
|
+
import { HTTPServer } from '@bytecodealliance/preview2-shim/http';
|
|
42
|
+
const server = new HTTPServer(mod.incomingHandler);
|
|
43
|
+
${tryFindPort ? `
|
|
44
|
+
let port = ${port};
|
|
45
|
+
while (true) {
|
|
46
|
+
try {
|
|
47
|
+
server.listen(port, ${JSON.stringify(host)});
|
|
48
|
+
break;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (e.code !== 'EADDRINUSE')
|
|
51
|
+
throw e;
|
|
52
|
+
}
|
|
53
|
+
port++;
|
|
54
|
+
}
|
|
55
|
+
` : `server.listen(${port}, ${JSON.stringify(host)})`}
|
|
56
|
+
console.error(\`Server listening on \${port}...\`);
|
|
57
|
+
`);
|
|
58
|
+
}
|
|
13
59
|
|
|
60
|
+
async function runComponent (componentPath, args, opts, executor) {
|
|
14
61
|
const jcoImport = opts.jcoImport ? resolve(opts.jcoImport) : null;
|
|
15
62
|
|
|
16
63
|
const name = basename(componentPath.slice(0, -extname(componentPath).length || Infinity));
|
|
@@ -18,6 +65,7 @@ export async function run (componentPath, args, opts) {
|
|
|
18
65
|
if (opts.jcoDir) {
|
|
19
66
|
await mkdir(outDir, { recursive: true });
|
|
20
67
|
}
|
|
68
|
+
|
|
21
69
|
try {
|
|
22
70
|
try {
|
|
23
71
|
await transpile(componentPath, {
|
|
@@ -26,7 +74,8 @@ export async function run (componentPath, args, opts) {
|
|
|
26
74
|
noTypescript: true,
|
|
27
75
|
wasiShim: true,
|
|
28
76
|
outDir,
|
|
29
|
-
tracing: opts.jcoTrace
|
|
77
|
+
tracing: opts.jcoTrace,
|
|
78
|
+
map: opts.jcoMap
|
|
30
79
|
});
|
|
31
80
|
}
|
|
32
81
|
catch (e) {
|
|
@@ -63,30 +112,11 @@ export async function run (componentPath, args, opts) {
|
|
|
63
112
|
const runPath = resolve(outDir, '_run.js');
|
|
64
113
|
await writeFile(runPath, `
|
|
65
114
|
${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` : ''}
|
|
66
|
-
function logInvalidCommand () {
|
|
67
|
-
console.error('Not a valid command component to execute, make sure it was built to a command adapter and with the same version.');
|
|
68
|
-
}
|
|
69
115
|
try {
|
|
70
116
|
process.argv[1] = "${name}";
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
mod.run.run();
|
|
78
|
-
// TODO: figure out stdout flush!
|
|
79
|
-
setTimeout(() => {});
|
|
80
|
-
}
|
|
81
|
-
catch (e) {
|
|
82
|
-
console.error(e);
|
|
83
|
-
process.exit(1);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
logInvalidCommand();
|
|
88
|
-
throw e;
|
|
89
|
-
}
|
|
117
|
+
} catch {}
|
|
118
|
+
const mod = await import('./${name}.js');
|
|
119
|
+
${executor}
|
|
90
120
|
`);
|
|
91
121
|
|
|
92
122
|
process.exitCode = await new Promise((resolve, reject) => {
|
|
@@ -102,4 +132,4 @@ export async function run (componentPath, args, opts) {
|
|
|
102
132
|
await rm(outDir, { recursive: true });
|
|
103
133
|
} catch {}
|
|
104
134
|
}
|
|
105
|
-
}
|
|
135
|
+
}
|
|
@@ -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":"AAgBA,sFAqCC;AAuBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8CAlBW,UAAU;UAEV,MAAM;oBACI,OAAO,GAAG,MAAM;UAC1B,OAAO,MAAM,EAAE,MAAM,CAAC;;;;;;;;;;cAUlB,MAAM,EAAE;;;;;aAEoD,MAAM,EAAE;aAAW,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC,EAAE;GAiShI"}
|
package/src/cmd/transpile.js
CHANGED
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import { $init, generate } from '../../obj/js-component-bindgen-component.js';
|
|
2
|
-
import { writeFile } from 'fs/promises';
|
|
3
|
-
import { mkdir } from 'fs/promises';
|
|
4
|
-
import { dirname, extname, basename } from 'path';
|
|
2
|
+
import { writeFile } from 'node:fs/promises';
|
|
3
|
+
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
import { dirname, extname, basename, resolve } from 'node:path';
|
|
5
5
|
import c from 'chalk-template';
|
|
6
6
|
import { readFile, sizeStr, table, spawnIOTmp, setShowSpinner, getShowSpinner } from '../common.js';
|
|
7
7
|
import { optimizeComponent } from './opt.js';
|
|
8
8
|
import { minify } from 'terser';
|
|
9
9
|
import { fileURLToPath } from 'url';
|
|
10
|
+
import { $init as wasmToolsInit, tools } from "../../obj/wasm-tools.js";
|
|
11
|
+
const { componentEmbed, componentNew } = tools;
|
|
10
12
|
import ora from '#ora';
|
|
13
|
+
import { platform } from 'node:process';
|
|
14
|
+
|
|
15
|
+
const isWindows = platform === 'win32';
|
|
11
16
|
|
|
12
17
|
export async function transpile (componentPath, opts, program) {
|
|
13
18
|
const varIdx = program?.parent.rawArgs.indexOf('--');
|
|
14
19
|
if (varIdx !== undefined && varIdx !== -1)
|
|
15
20
|
opts.optArgs = program.parent.rawArgs.slice(varIdx + 1);
|
|
16
|
-
|
|
21
|
+
|
|
22
|
+
let component;
|
|
23
|
+
if (!opts.stub) {
|
|
24
|
+
component = await readFile(componentPath);
|
|
25
|
+
} else {
|
|
26
|
+
await wasmToolsInit;
|
|
27
|
+
component = componentNew(componentEmbed({
|
|
28
|
+
dummy: true,
|
|
29
|
+
witPath: (isWindows ? '//?/' : '') + resolve(componentPath)
|
|
30
|
+
}), []);
|
|
31
|
+
}
|
|
17
32
|
|
|
18
33
|
if (!opts.quiet)
|
|
19
34
|
setShowSpinner(true);
|
|
@@ -81,7 +96,7 @@ async function wasm2Js (source) {
|
|
|
81
96
|
*/
|
|
82
97
|
export async function transpileComponent (component, opts = {}) {
|
|
83
98
|
await $init;
|
|
84
|
-
if (opts.
|
|
99
|
+
if (opts.instantiation) opts.wasiShim = false;
|
|
85
100
|
|
|
86
101
|
let spinner;
|
|
87
102
|
const showSpinner = getShowSpinner();
|
|
@@ -119,8 +134,8 @@ export async function transpileComponent (component, opts = {}) {
|
|
|
119
134
|
instantiation,
|
|
120
135
|
validLiftingOptimization: opts.validLiftingOptimization ?? false,
|
|
121
136
|
tracing: opts.tracing ?? false,
|
|
122
|
-
noNodejsCompat:
|
|
123
|
-
noTypescript: opts.
|
|
137
|
+
noNodejsCompat: opts.nodejsCompat === false,
|
|
138
|
+
noTypescript: opts.typescript === false,
|
|
124
139
|
tlaCompat: opts.tlaCompat ?? false,
|
|
125
140
|
base64Cutoff: opts.js ? 0 : opts.base64Cutoff ?? 5000,
|
|
126
141
|
noNamespacedExports: opts.namespacedExports === false,
|
|
@@ -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"}
|
package/src/cmd/wasm-tools.js
CHANGED
|
@@ -4,7 +4,6 @@ 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
|
import { resolve, basename, extname } from 'node:path';
|
|
6
6
|
import c from 'chalk-template';
|
|
7
|
-
import { platform } from 'node:process';
|
|
8
7
|
|
|
9
8
|
export async function parse(file, opts) {
|
|
10
9
|
await $init;
|
package/src/jco.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { program, Option } from 'commander';
|
|
3
3
|
import { opt } from './cmd/opt.js';
|
|
4
4
|
import { transpile } from './cmd/transpile.js';
|
|
5
|
-
import { run } from './cmd/run.js';
|
|
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';
|
|
8
8
|
import c from 'chalk-template';
|
|
@@ -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('0.
|
|
14
|
+
.version('1.0.0');
|
|
15
15
|
|
|
16
16
|
function myParseInt(value) {
|
|
17
17
|
return parseInt(value, 10);
|
|
@@ -19,7 +19,7 @@ function myParseInt(value) {
|
|
|
19
19
|
|
|
20
20
|
program.command('componentize')
|
|
21
21
|
.description('Create a component from a JavaScript module')
|
|
22
|
-
.usage('<js-source> -o <component-path>')
|
|
22
|
+
.usage('<js-source> --wit wit-world.wit -o <component-path>')
|
|
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')
|
|
@@ -44,6 +44,7 @@ program.command('transpile')
|
|
|
44
44
|
.option('--no-nodejs-compat', 'disables compatibility in Node.js without a fetch global')
|
|
45
45
|
.option('-M, --map <mappings...>', 'specifier=./output custom mappings for the component imports')
|
|
46
46
|
.option('--no-wasi-shim', 'disable automatic rewriting of WASI imports to use @bytecodealliance/preview2-shim')
|
|
47
|
+
.option('--stub', 'generate a stub implementation from a WIT file directly')
|
|
47
48
|
.option('--js', 'output JS instead of core WebAssembly')
|
|
48
49
|
.addOption(new Option('-I, --instantiation [mode]', 'output for custom module instantiation').choices(['async', 'sync']).preset('async'))
|
|
49
50
|
.option('-q, --quiet', 'disable logging')
|
|
@@ -52,15 +53,48 @@ program.command('transpile')
|
|
|
52
53
|
.action(asyncAction(transpile));
|
|
53
54
|
|
|
54
55
|
program.command('run')
|
|
55
|
-
.description('Run a
|
|
56
|
+
.description('Run a WASI Command component')
|
|
56
57
|
.usage('<command.wasm> <args...>')
|
|
57
58
|
.helpOption(false)
|
|
58
|
-
.
|
|
59
|
+
.allowUnknownOption(true)
|
|
60
|
+
.allowExcessArguments(true)
|
|
61
|
+
.argument('<command>', 'WASI command binary to run')
|
|
59
62
|
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the run command')
|
|
60
63
|
.option('--jco-trace', 'Enable call tracing')
|
|
61
64
|
.option('--jco-import <module>', 'Custom module to import before the run executes to support custom environment setup')
|
|
62
|
-
.
|
|
63
|
-
.
|
|
65
|
+
.option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports')
|
|
66
|
+
.argument('[args...]', 'Any CLI arguments for the component')
|
|
67
|
+
.action(asyncAction(async function run (cmd, args, opts, command) {
|
|
68
|
+
// specially only allow help option in first position
|
|
69
|
+
if (cmd === '--help' || cmd === '-h') {
|
|
70
|
+
command.help();
|
|
71
|
+
} else {
|
|
72
|
+
return runCmd(cmd, args, opts);
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
program.command('serve')
|
|
77
|
+
.description('Serve a WASI HTTP component')
|
|
78
|
+
.usage('<server.wasm> <args...>')
|
|
79
|
+
.helpOption(false)
|
|
80
|
+
.allowUnknownOption(true)
|
|
81
|
+
.allowExcessArguments(true)
|
|
82
|
+
.argument('<server>', 'WASI server binary to run')
|
|
83
|
+
.option('--port <number>')
|
|
84
|
+
.option('--host <host>')
|
|
85
|
+
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the transpiled code')
|
|
86
|
+
.option('--jco-trace', 'Enable call tracing')
|
|
87
|
+
.option('--jco-import <module>', 'Custom module to import before the server executes to support custom environment setup')
|
|
88
|
+
.option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports')
|
|
89
|
+
.argument('[args...]', 'Any CLI arguments for the component')
|
|
90
|
+
.action(asyncAction(async function serve (cmd, args, opts, command) {
|
|
91
|
+
// specially only allow help option in first position
|
|
92
|
+
if (cmd === '--help' || cmd === '-h') {
|
|
93
|
+
command.help();
|
|
94
|
+
} else {
|
|
95
|
+
return serveCmd(cmd, args, opts);
|
|
96
|
+
}
|
|
97
|
+
}));
|
|
64
98
|
|
|
65
99
|
program.command('opt')
|
|
66
100
|
.description('optimizes a Wasm component, including running wasm-opt Binaryen optimizations')
|
|
@@ -124,6 +158,8 @@ program.command('embed')
|
|
|
124
158
|
.option('-m, --metadata <metadata...>', 'field=name[@version] producer metadata to add with the embedding')
|
|
125
159
|
.action(asyncAction(componentEmbed));
|
|
126
160
|
|
|
161
|
+
program.showHelpAfterError();
|
|
162
|
+
|
|
127
163
|
program.parse();
|
|
128
164
|
|
|
129
165
|
function asyncAction (cmd) {
|