@bytecodealliance/jco 1.16.0 → 1.17.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 +6 -6
- package/obj/js-component-bindgen-component.core.wasm +0 -0
- package/obj/js-component-bindgen-component.js +1969 -1664
- package/obj/wasm-tools.core.wasm +0 -0
- package/obj/wasm-tools.js +2072 -1687
- package/package.json +94 -95
- package/src/api.js +5 -14
- package/src/browser.js +1 -1
- package/src/cmd/componentize.d.ts +1 -1
- package/src/cmd/componentize.js +14 -18
- package/src/cmd/opt.d.ts +10 -7
- package/src/cmd/opt.js +44 -96
- package/src/cmd/run.d.ts +1 -1
- package/src/cmd/run.js +31 -48
- package/src/cmd/transpile.d.ts +44 -39
- package/src/cmd/transpile.js +253 -316
- package/src/cmd/types.d.ts +15 -12
- package/src/cmd/types.js +27 -36
- package/src/cmd/wasm-tools.d.ts +1 -1
- package/src/cmd/wasm-tools.js +27 -44
- package/src/common.js +43 -57
- package/src/jco.js +200 -347
- package/types/api.d.ts.map +1 -1
- package/types/common.d.ts.map +1 -1
package/src/jco.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { program, Option } from
|
|
3
|
+
import { program, Option } from "commander";
|
|
4
4
|
|
|
5
|
-
import { opt } from
|
|
6
|
-
import { transpile } from
|
|
7
|
-
import { types, guestTypes } from
|
|
8
|
-
import { run as runCmd, serve as serveCmd } from
|
|
5
|
+
import { opt } from "./cmd/opt.js";
|
|
6
|
+
import { transpile } from "./cmd/transpile.js";
|
|
7
|
+
import { types, guestTypes } from "./cmd/types.js";
|
|
8
|
+
import { run as runCmd, serve as serveCmd } from "./cmd/run.js";
|
|
9
9
|
import {
|
|
10
10
|
parse,
|
|
11
11
|
print,
|
|
@@ -14,18 +14,18 @@ import {
|
|
|
14
14
|
metadataAdd,
|
|
15
15
|
metadataShow,
|
|
16
16
|
componentWit,
|
|
17
|
-
} from
|
|
18
|
-
import { componentize } from
|
|
19
|
-
import { styleText } from
|
|
17
|
+
} from "./cmd/wasm-tools.js";
|
|
18
|
+
import { componentize } from "./cmd/componentize.js";
|
|
19
|
+
import { styleText } from "./common.js";
|
|
20
20
|
|
|
21
21
|
program
|
|
22
|
-
.name(
|
|
22
|
+
.name("jco")
|
|
23
23
|
.description(
|
|
24
|
-
`${styleText(
|
|
24
|
+
`${styleText("bold", "jco - WebAssembly JS Component Tools")}\n JS Component Transpilation Bindgen & Wasm Tools for JS`,
|
|
25
25
|
)
|
|
26
|
-
.usage(
|
|
26
|
+
.usage("<command> [options]")
|
|
27
27
|
.enablePositionalOptions()
|
|
28
|
-
.version(
|
|
28
|
+
.version("1.16.1");
|
|
29
29
|
|
|
30
30
|
function myParseInt(value) {
|
|
31
31
|
return parseInt(value, 10);
|
|
@@ -42,435 +42,288 @@ function collectOptions(value, previous) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/** Choices for features (enabling/disabling) */
|
|
45
|
-
const FEATURE_CHOICES = [
|
|
46
|
-
'clocks',
|
|
47
|
-
'http',
|
|
48
|
-
'random',
|
|
49
|
-
'stdio',
|
|
50
|
-
'fetch-event',
|
|
51
|
-
'all',
|
|
52
|
-
];
|
|
45
|
+
const FEATURE_CHOICES = ["clocks", "http", "random", "stdio", "fetch-event", "all"];
|
|
53
46
|
|
|
54
47
|
program
|
|
55
|
-
.command(
|
|
56
|
-
.description(
|
|
57
|
-
.usage(
|
|
58
|
-
.argument(
|
|
59
|
-
.requiredOption(
|
|
60
|
-
.option(
|
|
61
|
-
.option(
|
|
62
|
-
.option(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
)
|
|
66
|
-
.option(
|
|
67
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
73
|
-
.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
)
|
|
78
|
-
.option(
|
|
79
|
-
'--debug',
|
|
80
|
-
'configure jco for debug (e.g. disable all features except stdio, etc)'
|
|
81
|
-
)
|
|
82
|
-
.option(
|
|
83
|
-
'--preview2-adapter <adapter>',
|
|
84
|
-
'provide a custom preview2 adapter path'
|
|
85
|
-
)
|
|
86
|
-
.option(
|
|
87
|
-
'--debug-starlingmonkey-build',
|
|
88
|
-
'use a debug build of StarlingMonkey'
|
|
89
|
-
)
|
|
90
|
-
.option('--engine <path>', 'use a specific StarlingMonkey build')
|
|
91
|
-
.requiredOption('-o, --out <out>', 'output component file')
|
|
92
|
-
.option(
|
|
93
|
-
'--debug-bindings',
|
|
94
|
-
'Output debug bindings and metadata during componentization (by default to stderr)'
|
|
95
|
-
)
|
|
96
|
-
.option(
|
|
97
|
-
'--debug-bindings-dir <dir>',
|
|
98
|
-
'Directory to which to output generated bindings and metadata'
|
|
99
|
-
)
|
|
100
|
-
.option(
|
|
101
|
-
'--debug-binary',
|
|
102
|
-
'Output binary (without component metadata) created during componentization (by default to tmp dir)'
|
|
103
|
-
)
|
|
104
|
-
.option(
|
|
105
|
-
'--debug-binary-path <path>',
|
|
106
|
-
'Path to which to write the generated debug binary'
|
|
107
|
-
)
|
|
108
|
-
.option('--debug-enable-wizer-logging', 'Enable wizer call debugging')
|
|
48
|
+
.command("componentize")
|
|
49
|
+
.description("Create a component from a JavaScript module")
|
|
50
|
+
.usage("<js-source> --wit wit-world.wit -o <component-path>")
|
|
51
|
+
.argument("<js-source>", "JS source file to build")
|
|
52
|
+
.requiredOption("-w, --wit <path>", "WIT path to build with")
|
|
53
|
+
.option("-n, --world-name <name>", "WIT world to build")
|
|
54
|
+
.option("--aot", "Enable Weval AOT compilation of JS")
|
|
55
|
+
.option("--aot-min-stack-size-bytes <number>", "Set the min stack size to be used during AOT")
|
|
56
|
+
.option("--weval-bin <path>", "Specify a custom weval binary to use")
|
|
57
|
+
.addOption(new Option("-d, --disable <feature...>", "disable WASI features").choices(FEATURE_CHOICES))
|
|
58
|
+
.addOption(new Option("--enable <feature...>", "enable WASI features").choices(FEATURE_CHOICES))
|
|
59
|
+
.option("--debug", "configure jco for debug (e.g. disable all features except stdio, etc)")
|
|
60
|
+
.option("--preview2-adapter <adapter>", "provide a custom preview2 adapter path")
|
|
61
|
+
.option("--debug-starlingmonkey-build", "use a debug build of StarlingMonkey")
|
|
62
|
+
.option("--engine <path>", "use a specific StarlingMonkey build")
|
|
63
|
+
.requiredOption("-o, --out <out>", "output component file")
|
|
64
|
+
.option("--debug-bindings", "Output debug bindings and metadata during componentization (by default to stderr)")
|
|
65
|
+
.option("--debug-bindings-dir <dir>", "Directory to which to output generated bindings and metadata")
|
|
66
|
+
.option(
|
|
67
|
+
"--debug-binary",
|
|
68
|
+
"Output binary (without component metadata) created during componentization (by default to tmp dir)",
|
|
69
|
+
)
|
|
70
|
+
.option("--debug-binary-path <path>", "Path to which to write the generated debug binary")
|
|
71
|
+
.option("--debug-enable-wizer-logging", "Enable wizer call debugging")
|
|
109
72
|
.action(asyncAction(componentize));
|
|
110
73
|
|
|
111
74
|
program
|
|
112
|
-
.command(
|
|
113
|
-
.description(
|
|
114
|
-
|
|
115
|
-
)
|
|
116
|
-
.
|
|
117
|
-
.
|
|
118
|
-
.option(
|
|
119
|
-
.
|
|
120
|
-
.option(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
.option(
|
|
125
|
-
'-O, --optimize',
|
|
126
|
-
`optimize the component first (use -- and arguments to wasm-opt)`
|
|
127
|
-
)
|
|
128
|
-
.option('--no-typescript', 'do not output TypeScript .d.ts types')
|
|
129
|
-
.option(
|
|
130
|
-
'--valid-lifting-optimization',
|
|
131
|
-
'optimize component binary validations assuming all lifted values are valid'
|
|
75
|
+
.command("transpile")
|
|
76
|
+
.description("Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution")
|
|
77
|
+
.usage("<component-path> -o <out-dir>")
|
|
78
|
+
.argument("<component-path>", "Wasm component binary filepath")
|
|
79
|
+
.option("--name <name>", "custom output name")
|
|
80
|
+
.requiredOption("-o, --out-dir <out-dir>", "output directory")
|
|
81
|
+
.option("-m, --minify", "minify the JS output (--optimize / opt cmd still required)")
|
|
82
|
+
.option("-O, --optimize", `optimize the component first (use -- and arguments to wasm-opt)`)
|
|
83
|
+
.option("--no-typescript", "do not output TypeScript .d.ts types")
|
|
84
|
+
.option(
|
|
85
|
+
"--valid-lifting-optimization",
|
|
86
|
+
"optimize component binary validations assuming all lifted values are valid",
|
|
132
87
|
)
|
|
133
88
|
.addOption(
|
|
134
|
-
new Option(
|
|
135
|
-
.choices([
|
|
136
|
-
.preset(
|
|
89
|
+
new Option("--import-bindings [mode]", "bindings mode for imports")
|
|
90
|
+
.choices(["js", "optimized", "hybrid", "direct-optimized"])
|
|
91
|
+
.preset("js"),
|
|
137
92
|
)
|
|
138
93
|
.addOption(
|
|
139
|
-
new Option(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
)
|
|
143
|
-
.choices(['sync', 'jspi'])
|
|
144
|
-
.preset('sync')
|
|
145
|
-
)
|
|
146
|
-
.option(
|
|
147
|
-
'--async-wasi-imports',
|
|
148
|
-
'EXPERIMENTAL: async component imports from WASI interfaces'
|
|
149
|
-
)
|
|
150
|
-
.option(
|
|
151
|
-
'--async-wasi-exports',
|
|
152
|
-
'EXPERIMENTAL: async component exports from WASI interfaces'
|
|
153
|
-
)
|
|
154
|
-
.option(
|
|
155
|
-
'--async-imports <imports...>',
|
|
156
|
-
'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")'
|
|
94
|
+
new Option("--async-mode [mode]", "EXPERIMENTAL: use async imports and exports")
|
|
95
|
+
.choices(["sync", "jspi"])
|
|
96
|
+
.preset("sync"),
|
|
157
97
|
)
|
|
98
|
+
.option("--async-wasi-imports", "EXPERIMENTAL: async component imports from WASI interfaces")
|
|
99
|
+
.option("--async-wasi-exports", "EXPERIMENTAL: async component exports from WASI interfaces")
|
|
158
100
|
.option(
|
|
159
|
-
|
|
160
|
-
'EXPERIMENTAL: async component
|
|
101
|
+
"--async-imports <imports...>",
|
|
102
|
+
'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")',
|
|
161
103
|
)
|
|
162
|
-
.option('--tracing', 'emit `tracing` calls on function entry/exit')
|
|
163
104
|
.option(
|
|
164
|
-
|
|
165
|
-
'
|
|
166
|
-
myParseInt
|
|
105
|
+
"--async-exports <exports...>",
|
|
106
|
+
'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")',
|
|
167
107
|
)
|
|
108
|
+
.option("--tracing", "emit `tracing` calls on function entry/exit")
|
|
168
109
|
.option(
|
|
169
|
-
|
|
170
|
-
|
|
110
|
+
"-b, --base64-cutoff <bytes>",
|
|
111
|
+
"set the byte size under which core Wasm binaries will be inlined as base64",
|
|
112
|
+
myParseInt,
|
|
171
113
|
)
|
|
172
114
|
.option(
|
|
173
|
-
|
|
174
|
-
|
|
115
|
+
"--tla-compat",
|
|
116
|
+
"enables compatibility for JS environments without top-level await support via an async $init promise export",
|
|
175
117
|
)
|
|
176
|
-
.option(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
)
|
|
180
|
-
.option(
|
|
181
|
-
'--no-wasi-shim',
|
|
182
|
-
'disable automatic rewriting of WASI imports to use @bytecodealliance/preview2-shim'
|
|
183
|
-
)
|
|
184
|
-
.option('--stub', 'generate a stub implementation from a WIT file directly')
|
|
185
|
-
.option('--js', 'output JS instead of core WebAssembly')
|
|
118
|
+
.option("--no-nodejs-compat", "disables compatibility in Node.js without a fetch global")
|
|
119
|
+
.option("-M, --map <mappings...>", "specifier=./output custom mappings for the component imports")
|
|
120
|
+
.option("--no-wasi-shim", "disable automatic rewriting of WASI imports to use @bytecodealliance/preview2-shim")
|
|
121
|
+
.option("--stub", "generate a stub implementation from a WIT file directly")
|
|
122
|
+
.option("--js", "output JS instead of core WebAssembly")
|
|
186
123
|
.addOption(
|
|
187
|
-
new Option(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
)
|
|
191
|
-
.choices(['async', 'sync'])
|
|
192
|
-
.preset('async')
|
|
193
|
-
)
|
|
194
|
-
.option('-q, --quiet', 'disable output summary')
|
|
195
|
-
.option(
|
|
196
|
-
'--no-namespaced-exports',
|
|
197
|
-
'disable namespaced exports for typescript compatibility'
|
|
124
|
+
new Option("-I, --instantiation [mode]", "output for custom module instantiation")
|
|
125
|
+
.choices(["async", "sync"])
|
|
126
|
+
.preset("async"),
|
|
198
127
|
)
|
|
199
|
-
.option(
|
|
128
|
+
.option("-q, --quiet", "disable output summary")
|
|
129
|
+
.option("--no-namespaced-exports", "disable namespaced exports for typescript compatibility")
|
|
130
|
+
.option("--multi-memory", "optimized output for Wasm multi-memory")
|
|
200
131
|
.allowExcessArguments(true)
|
|
201
132
|
.action(asyncAction(transpile));
|
|
202
133
|
|
|
203
134
|
program
|
|
204
|
-
.command(
|
|
205
|
-
.description(
|
|
206
|
-
.usage(
|
|
207
|
-
.argument(
|
|
208
|
-
.option(
|
|
209
|
-
.option(
|
|
210
|
-
.option(
|
|
211
|
-
.option(
|
|
212
|
-
'--tla-compat',
|
|
213
|
-
'generates types for the TLA compat output with an async $init promise export'
|
|
214
|
-
)
|
|
135
|
+
.command("types")
|
|
136
|
+
.description("Generate types for the given WIT")
|
|
137
|
+
.usage("<wit-path> -o <out-dir>")
|
|
138
|
+
.argument("[<wit-path>]", "path to a WIT file or directory")
|
|
139
|
+
.option("--name <name>", "custom output name")
|
|
140
|
+
.option("-n, --world-name <world>", "WIT world to generate types for")
|
|
141
|
+
.option("-o, --out-dir <out-dir>", "output directory")
|
|
142
|
+
.option("--tla-compat", "generates types for the TLA compat output with an async $init promise export")
|
|
215
143
|
.addOption(
|
|
216
|
-
new Option(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
)
|
|
220
|
-
.choices(['async', 'sync'])
|
|
221
|
-
.preset('async')
|
|
144
|
+
new Option("-I, --instantiation [mode]", "type output for custom module instantiation")
|
|
145
|
+
.choices(["async", "sync"])
|
|
146
|
+
.preset("async"),
|
|
222
147
|
)
|
|
223
148
|
.addOption(
|
|
224
|
-
new Option(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
)
|
|
228
|
-
.choices(['sync', 'jspi'])
|
|
229
|
-
.preset('sync')
|
|
230
|
-
)
|
|
231
|
-
.option(
|
|
232
|
-
'--async-wasi-imports',
|
|
233
|
-
'EXPERIMENTAL: async component imports from WASI interfaces'
|
|
149
|
+
new Option("--async-mode [mode]", "EXPERIMENTAL: use async imports and exports")
|
|
150
|
+
.choices(["sync", "jspi"])
|
|
151
|
+
.preset("sync"),
|
|
234
152
|
)
|
|
153
|
+
.option("--async-wasi-imports", "EXPERIMENTAL: async component imports from WASI interfaces")
|
|
154
|
+
.option("--async-wasi-exports", "EXPERIMENTAL: async component exports from WASI interfaces")
|
|
235
155
|
.option(
|
|
236
|
-
|
|
237
|
-
'EXPERIMENTAL: async component
|
|
156
|
+
"--async-imports <imports...>",
|
|
157
|
+
'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")',
|
|
238
158
|
)
|
|
239
159
|
.option(
|
|
240
|
-
|
|
241
|
-
'EXPERIMENTAL: async component
|
|
242
|
-
)
|
|
243
|
-
.option(
|
|
244
|
-
'--async-exports <exports...>',
|
|
245
|
-
'EXPERIMENTAL: async component exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")'
|
|
246
|
-
)
|
|
247
|
-
.option('-q, --quiet', 'disable output summary')
|
|
248
|
-
.option(
|
|
249
|
-
'--feature <feature>',
|
|
250
|
-
'enable one specific WIT feature (repeatable)',
|
|
251
|
-
collectOptions,
|
|
252
|
-
[]
|
|
253
|
-
)
|
|
254
|
-
.option('--all-features', 'enable all features')
|
|
255
|
-
.option(
|
|
256
|
-
"--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')"
|
|
160
|
+
"--async-exports <exports...>",
|
|
161
|
+
'EXPERIMENTAL: async component exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")',
|
|
257
162
|
)
|
|
163
|
+
.option("-q, --quiet", "disable output summary")
|
|
164
|
+
.option("--feature <feature>", "enable one specific WIT feature (repeatable)", collectOptions, [])
|
|
165
|
+
.option("--all-features", "enable all features")
|
|
166
|
+
.option("--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')")
|
|
258
167
|
.action(asyncAction(types));
|
|
259
168
|
|
|
260
169
|
program
|
|
261
|
-
.command(
|
|
262
|
-
.description(
|
|
263
|
-
.usage(
|
|
264
|
-
.argument(
|
|
265
|
-
.option(
|
|
266
|
-
.option(
|
|
267
|
-
.option(
|
|
268
|
-
.option(
|
|
269
|
-
.option(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
)
|
|
275
|
-
.option('--all-features', 'enable all features')
|
|
276
|
-
.option(
|
|
277
|
-
'--async-exports <exports...>',
|
|
278
|
-
'EXPERIMENTAL: generate async exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")'
|
|
170
|
+
.command("guest-types")
|
|
171
|
+
.description("(experimental) Generate guest types for the given WIT")
|
|
172
|
+
.usage("<wit-path> -o <out-dir>")
|
|
173
|
+
.argument("[<wit-path>]", "path to a WIT file or directory")
|
|
174
|
+
.option("--name <name>", "custom output name")
|
|
175
|
+
.option("-n, --world-name <world>", "WIT world to generate types for")
|
|
176
|
+
.option("-o, --out-dir <out-dir>", "output directory")
|
|
177
|
+
.option("-q, --quiet", "disable output summary")
|
|
178
|
+
.option("--feature <feature>", "enable one specific WIT feature (repeatable)", collectOptions, [])
|
|
179
|
+
.option("--all-features", "enable all features")
|
|
180
|
+
.option(
|
|
181
|
+
"--async-exports <exports...>",
|
|
182
|
+
'EXPERIMENTAL: generate async exports (examples: "ns:pkg/iface#func", "wasi:cli/run@0.2.3#run", "handle")',
|
|
279
183
|
)
|
|
280
184
|
.addOption(
|
|
281
|
-
new Option(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
)
|
|
285
|
-
.choices(['sync', 'jspi'])
|
|
286
|
-
.preset('sync')
|
|
185
|
+
new Option("--async-mode [mode]", "EXPERIMENTAL: use async imports and exports")
|
|
186
|
+
.choices(["sync", "jspi"])
|
|
187
|
+
.preset("sync"),
|
|
287
188
|
)
|
|
288
189
|
.action(asyncAction(guestTypes));
|
|
289
190
|
|
|
290
191
|
program
|
|
291
|
-
.command(
|
|
292
|
-
.description(
|
|
293
|
-
.usage(
|
|
192
|
+
.command("run")
|
|
193
|
+
.description("Run a WASI Command component")
|
|
194
|
+
.usage("<command.wasm> <args...>")
|
|
294
195
|
.helpOption(false)
|
|
295
196
|
.allowUnknownOption(true)
|
|
296
197
|
.allowExcessArguments(true)
|
|
297
|
-
.argument(
|
|
298
|
-
.option(
|
|
299
|
-
|
|
300
|
-
'Instead of using a temporary dir, set the output directory for the run command'
|
|
301
|
-
)
|
|
302
|
-
.option('--jco-trace', 'Enable call tracing')
|
|
198
|
+
.argument("<command>", "WASI command binary to run")
|
|
199
|
+
.option("--jco-dir <dir>", "Instead of using a temporary dir, set the output directory for the run command")
|
|
200
|
+
.option("--jco-trace", "Enable call tracing")
|
|
303
201
|
.option(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
)
|
|
307
|
-
.option(
|
|
308
|
-
'--jco-map <mappings...>',
|
|
309
|
-
'specifier=./output custom mappings for the component imports'
|
|
202
|
+
"--jco-import <module>",
|
|
203
|
+
"Custom module to import before the run executes to support custom environment setup",
|
|
310
204
|
)
|
|
205
|
+
.option("--jco-map <mappings...>", "specifier=./output custom mappings for the component imports")
|
|
311
206
|
.addOption(
|
|
312
|
-
new Option(
|
|
313
|
-
.choices([
|
|
314
|
-
.preset(
|
|
207
|
+
new Option("--jco-import-bindings [mode]", "bindings mode for imports")
|
|
208
|
+
.choices(["js", "optimized", "hybrid", "direct-optimized"])
|
|
209
|
+
.preset("js"),
|
|
315
210
|
)
|
|
316
|
-
.argument(
|
|
211
|
+
.argument("[args...]", "Any CLI arguments for the component")
|
|
317
212
|
.action(
|
|
318
213
|
asyncAction(async function run(cmd, args, opts, command) {
|
|
319
214
|
// specially only allow help option in first position
|
|
320
|
-
if (cmd ===
|
|
215
|
+
if (cmd === "--help" || cmd === "-h") {
|
|
321
216
|
command.help();
|
|
322
217
|
} else {
|
|
323
218
|
return runCmd(cmd, args, opts);
|
|
324
219
|
}
|
|
325
|
-
})
|
|
220
|
+
}),
|
|
326
221
|
);
|
|
327
222
|
|
|
328
223
|
program
|
|
329
|
-
.command(
|
|
330
|
-
.description(
|
|
331
|
-
.usage(
|
|
224
|
+
.command("serve")
|
|
225
|
+
.description("Serve a WASI HTTP component")
|
|
226
|
+
.usage("<server.wasm> <args...>")
|
|
332
227
|
.helpOption(false)
|
|
333
228
|
.allowUnknownOption(true)
|
|
334
229
|
.allowExcessArguments(true)
|
|
335
|
-
.argument(
|
|
336
|
-
.option(
|
|
337
|
-
.option(
|
|
338
|
-
.option(
|
|
339
|
-
|
|
340
|
-
'Instead of using a temporary dir, set the output directory for the transpiled code'
|
|
341
|
-
)
|
|
342
|
-
.option('--jco-trace', 'Enable call tracing')
|
|
230
|
+
.argument("<server>", "WASI server binary to run")
|
|
231
|
+
.option("--port <number>")
|
|
232
|
+
.option("--host <host>")
|
|
233
|
+
.option("--jco-dir <dir>", "Instead of using a temporary dir, set the output directory for the transpiled code")
|
|
234
|
+
.option("--jco-trace", "Enable call tracing")
|
|
343
235
|
.option(
|
|
344
|
-
|
|
345
|
-
|
|
236
|
+
"--jco-import <module>",
|
|
237
|
+
"Custom module to import before the server executes to support custom environment setup",
|
|
346
238
|
)
|
|
347
239
|
.addOption(
|
|
348
|
-
new Option(
|
|
349
|
-
.choices([
|
|
350
|
-
.preset(
|
|
351
|
-
)
|
|
352
|
-
.option(
|
|
353
|
-
'--jco-map <mappings...>',
|
|
354
|
-
'specifier=./output custom mappings for the component imports'
|
|
240
|
+
new Option("--jco-import-bindings [mode]", "bindings mode for imports")
|
|
241
|
+
.choices(["js", "optimized", "hybrid", "direct-optimized"])
|
|
242
|
+
.preset("js"),
|
|
355
243
|
)
|
|
356
|
-
.
|
|
244
|
+
.option("--jco-map <mappings...>", "specifier=./output custom mappings for the component imports")
|
|
245
|
+
.argument("[args...]", "Any CLI arguments for the component")
|
|
357
246
|
.action(
|
|
358
247
|
asyncAction(async function serve(cmd, args, opts, command) {
|
|
359
248
|
// specially only allow help option in first position
|
|
360
|
-
if (cmd ===
|
|
249
|
+
if (cmd === "--help" || cmd === "-h") {
|
|
361
250
|
command.help();
|
|
362
251
|
} else {
|
|
363
252
|
return serveCmd(cmd, args, opts);
|
|
364
253
|
}
|
|
365
|
-
})
|
|
254
|
+
}),
|
|
366
255
|
);
|
|
367
256
|
|
|
368
257
|
program
|
|
369
|
-
.command(
|
|
370
|
-
.description(
|
|
371
|
-
|
|
372
|
-
)
|
|
373
|
-
.
|
|
374
|
-
.
|
|
375
|
-
.
|
|
376
|
-
|
|
377
|
-
'optimized component output filepath'
|
|
378
|
-
)
|
|
379
|
-
.option('--asyncify', 'runs Asyncify pass in wasm-opt')
|
|
380
|
-
.option('-q, --quiet')
|
|
381
|
-
.option(
|
|
382
|
-
"--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')"
|
|
383
|
-
)
|
|
258
|
+
.command("opt")
|
|
259
|
+
.description("optimizes a Wasm component, including running wasm-opt Binaryen optimizations")
|
|
260
|
+
.usage("<component-file> -o <output-file> -- [wasm-opt arguments]")
|
|
261
|
+
.argument("<component-file>", "Wasm component binary filepath")
|
|
262
|
+
.requiredOption("-o, --output <output-file>", "optimized component output filepath")
|
|
263
|
+
.option("--asyncify", "runs Asyncify pass in wasm-opt")
|
|
264
|
+
.option("-q, --quiet")
|
|
265
|
+
.option("--wasm-opt-bin <path-to-wasm-opt>', 'wasm-opt binary path (default: 'binaryen/bin/wasm-opt')")
|
|
384
266
|
.allowExcessArguments(true)
|
|
385
267
|
.action(asyncAction(opt));
|
|
386
268
|
|
|
387
269
|
program
|
|
388
|
-
.command(
|
|
389
|
-
.description(
|
|
390
|
-
|
|
391
|
-
)
|
|
392
|
-
.
|
|
393
|
-
.option('-d, --document <name>', 'WIT document of a package to print')
|
|
394
|
-
.option('-o, --output <output-file>', 'WIT output file path')
|
|
270
|
+
.command("wit")
|
|
271
|
+
.description("extract the WIT from a WebAssembly Component [wasm-tools component wit]")
|
|
272
|
+
.argument("<component-path>", "Wasm component binary filepath")
|
|
273
|
+
.option("-d, --document <name>", "WIT document of a package to print")
|
|
274
|
+
.option("-o, --output <output-file>", "WIT output file path")
|
|
395
275
|
.action(asyncAction(componentWit));
|
|
396
276
|
|
|
397
277
|
program
|
|
398
|
-
.command(
|
|
399
|
-
.description(
|
|
400
|
-
|
|
401
|
-
)
|
|
402
|
-
.argument('<input>', 'input file to process')
|
|
403
|
-
.option('-o, --output <output-file>', 'output file path')
|
|
278
|
+
.command("print")
|
|
279
|
+
.description("print the WebAssembly WAT text for a binary file [wasm-tools print]")
|
|
280
|
+
.argument("<input>", "input file to process")
|
|
281
|
+
.option("-o, --output <output-file>", "output file path")
|
|
404
282
|
.action(asyncAction(print));
|
|
405
283
|
|
|
406
284
|
program
|
|
407
|
-
.command(
|
|
408
|
-
.description(
|
|
409
|
-
|
|
410
|
-
)
|
|
411
|
-
.argument('[module]', 'Wasm component or core module filepath')
|
|
412
|
-
.option('--json', 'output component metadata as JSON')
|
|
285
|
+
.command("metadata-show")
|
|
286
|
+
.description("extract the producer metadata for a Wasm binary [wasm-tools metadata show]")
|
|
287
|
+
.argument("[module]", "Wasm component or core module filepath")
|
|
288
|
+
.option("--json", "output component metadata as JSON")
|
|
413
289
|
.action(asyncAction(metadataShow));
|
|
414
290
|
|
|
415
291
|
program
|
|
416
|
-
.command(
|
|
417
|
-
.description(
|
|
418
|
-
|
|
419
|
-
)
|
|
420
|
-
.
|
|
421
|
-
.requiredOption(
|
|
422
|
-
'-m, --metadata <metadata...>',
|
|
423
|
-
'field=name[@version] producer metadata to add with the embedding'
|
|
424
|
-
)
|
|
425
|
-
.requiredOption('-o, --output <output-file>', 'output binary path')
|
|
292
|
+
.command("metadata-add")
|
|
293
|
+
.description("add producer metadata for a Wasm binary [wasm-tools metadata add]")
|
|
294
|
+
.argument("[module]", "Wasm component or core module filepath")
|
|
295
|
+
.requiredOption("-m, --metadata <metadata...>", "field=name[@version] producer metadata to add with the embedding")
|
|
296
|
+
.requiredOption("-o, --output <output-file>", "output binary path")
|
|
426
297
|
.action(asyncAction(metadataAdd));
|
|
427
298
|
|
|
428
299
|
program
|
|
429
|
-
.command(
|
|
430
|
-
.description(
|
|
431
|
-
|
|
432
|
-
)
|
|
433
|
-
.argument('<input>', 'input file to process')
|
|
434
|
-
.requiredOption('-o, --output <output-file>', 'output binary file path')
|
|
300
|
+
.command("parse")
|
|
301
|
+
.description("parses the Wasm text format into a binary file [wasm-tools parse]")
|
|
302
|
+
.argument("<input>", "input file to process")
|
|
303
|
+
.requiredOption("-o, --output <output-file>", "output binary file path")
|
|
435
304
|
.action(asyncAction(parse));
|
|
436
305
|
|
|
437
306
|
program
|
|
438
|
-
.command(
|
|
439
|
-
.description(
|
|
440
|
-
|
|
441
|
-
)
|
|
442
|
-
.
|
|
443
|
-
.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
)
|
|
447
|
-
.option('--name <name>', 'custom output name')
|
|
448
|
-
.option('--adapt <[NAME=]adapter...>', 'component adapters to apply')
|
|
449
|
-
.option('--wasi-reactor', 'build with the WASI Reactor adapter')
|
|
450
|
-
.option('--wasi-command', 'build with the WASI Command adapter')
|
|
307
|
+
.command("new")
|
|
308
|
+
.description("create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]")
|
|
309
|
+
.argument("<core-module>", "Wasm core module filepath")
|
|
310
|
+
.requiredOption("-o, --output <output-file>", "Wasm component output filepath")
|
|
311
|
+
.option("--name <name>", "custom output name")
|
|
312
|
+
.option("--adapt <[NAME=]adapter...>", "component adapters to apply")
|
|
313
|
+
.option("--wasi-reactor", "build with the WASI Reactor adapter")
|
|
314
|
+
.option("--wasi-command", "build with the WASI Command adapter")
|
|
451
315
|
.action(asyncAction(componentNew));
|
|
452
316
|
|
|
453
317
|
program
|
|
454
|
-
.command(
|
|
455
|
-
.description(
|
|
456
|
-
|
|
457
|
-
)
|
|
458
|
-
.
|
|
459
|
-
.
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
)
|
|
463
|
-
.requiredOption('--wit <wit-world>', 'WIT world path')
|
|
464
|
-
.option('--dummy', 'generate a dummy component')
|
|
465
|
-
.option(
|
|
466
|
-
'--string-encoding <utf8|utf16|compact-utf16>',
|
|
467
|
-
'set the component string encoding'
|
|
468
|
-
)
|
|
469
|
-
.option('-n, --world-name <world-name>', 'world name to embed')
|
|
470
|
-
.option(
|
|
471
|
-
'-m, --metadata <metadata...>',
|
|
472
|
-
'field=name[@version] producer metadata to add with the embedding'
|
|
473
|
-
)
|
|
318
|
+
.command("embed")
|
|
319
|
+
.description("embed the component typing section into a core Wasm module [wasm-tools component embed]")
|
|
320
|
+
.argument("[core-module]", "Wasm core module filepath")
|
|
321
|
+
.requiredOption("-o, --output <output-file>", "Wasm component output filepath")
|
|
322
|
+
.requiredOption("--wit <wit-world>", "WIT world path")
|
|
323
|
+
.option("--dummy", "generate a dummy component")
|
|
324
|
+
.option("--string-encoding <utf8|utf16|compact-utf16>", "set the component string encoding")
|
|
325
|
+
.option("-n, --world-name <world-name>", "world name to embed")
|
|
326
|
+
.option("-m, --metadata <metadata...>", "field=name[@version] producer metadata to add with the embedding")
|
|
474
327
|
.action(asyncAction(componentEmbed));
|
|
475
328
|
|
|
476
329
|
program.showHelpAfterError();
|
|
@@ -478,15 +331,15 @@ program.showHelpAfterError();
|
|
|
478
331
|
program.parse();
|
|
479
332
|
|
|
480
333
|
function asyncAction(cmd) {
|
|
481
|
-
return function() {
|
|
334
|
+
return function () {
|
|
482
335
|
const args = [...arguments];
|
|
483
336
|
(async () => {
|
|
484
337
|
try {
|
|
485
338
|
await cmd.apply(null, args);
|
|
486
339
|
} catch (e) {
|
|
487
340
|
process.stdout.write(`(jco ${cmd.name}) `);
|
|
488
|
-
if (typeof e ===
|
|
489
|
-
console.error(`${styleText([
|
|
341
|
+
if (typeof e === "string") {
|
|
342
|
+
console.error(`${styleText(["red", "bold"], "Error")}: ${e}\n`);
|
|
490
343
|
} else {
|
|
491
344
|
console.error(e);
|
|
492
345
|
}
|