@bytecodealliance/jco 1.16.1 → 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/src/jco.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { program, Option } from 'commander';
3
+ import { program, Option } from "commander";
4
4
 
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';
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 './cmd/wasm-tools.js';
18
- import { componentize } from './cmd/componentize.js';
19
- import { styleText } from './common.js';
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('jco')
22
+ .name("jco")
23
23
  .description(
24
- `${styleText('bold', "jco - WebAssembly JS Component Tools")}\n JS Component Transpilation Bindgen & Wasm Tools for JS`
24
+ `${styleText("bold", "jco - WebAssembly JS Component Tools")}\n JS Component Transpilation Bindgen & Wasm Tools for JS`,
25
25
  )
26
- .usage('<command> [options]')
26
+ .usage("<command> [options]")
27
27
  .enablePositionalOptions()
28
- .version('1.16.1');
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('componentize')
56
- .description('Create a component from a JavaScript module')
57
- .usage('<js-source> --wit wit-world.wit -o <component-path>')
58
- .argument('<js-source>', 'JS source file to build')
59
- .requiredOption('-w, --wit <path>', 'WIT path to build with')
60
- .option('-n, --world-name <name>', 'WIT world to build')
61
- .option('--aot', 'Enable Weval AOT compilation of JS')
62
- .option(
63
- '--aot-min-stack-size-bytes <number>',
64
- 'Set the min stack size to be used during AOT'
65
- )
66
- .option('--weval-bin <path>', 'Specify a custom weval binary to use')
67
- .addOption(
68
- new Option(
69
- '-d, --disable <feature...>',
70
- 'disable WASI features'
71
- ).choices(FEATURE_CHOICES)
72
- )
73
- .addOption(
74
- new Option('--enable <feature...>', 'enable WASI features').choices(
75
- FEATURE_CHOICES
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('transpile')
113
- .description(
114
- 'Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution'
115
- )
116
- .usage('<component-path> -o <out-dir>')
117
- .argument('<component-path>', 'Wasm component binary filepath')
118
- .option('--name <name>', 'custom output name')
119
- .requiredOption('-o, --out-dir <out-dir>', 'output directory')
120
- .option(
121
- '-m, --minify',
122
- 'minify the JS output (--optimize / opt cmd still required)'
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('--import-bindings [mode]', 'bindings mode for imports')
135
- .choices(['js', 'optimized', 'hybrid', 'direct-optimized'])
136
- .preset('js')
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
- '--async-mode [mode]',
141
- 'EXPERIMENTAL: use async imports and exports'
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
- '--async-exports <exports...>',
160
- 'EXPERIMENTAL: async component exports (examples: "wasi:cli/run@#run", "handle")'
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
- '-b, --base64-cutoff <bytes>',
165
- 'set the byte size under which core Wasm binaries will be inlined as base64',
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
- '--tla-compat',
170
- 'enables compatibility for JS environments without top-level await support via an async $init promise export'
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
- '--no-nodejs-compat',
174
- 'disables compatibility in Node.js without a fetch global'
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
- '-M, --map <mappings...>',
178
- 'specifier=./output custom mappings for the component imports'
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
- '-I, --instantiation [mode]',
189
- 'output for custom module instantiation'
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('--multi-memory', 'optimized output for Wasm multi-memory')
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('types')
205
- .description('Generate types for the given WIT')
206
- .usage('<wit-path> -o <out-dir>')
207
- .argument('[<wit-path>]', 'path to a WIT file or directory')
208
- .option('--name <name>', 'custom output name')
209
- .option('-n, --world-name <world>', 'WIT world to generate types for')
210
- .option('-o, --out-dir <out-dir>', 'output directory')
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
- '-I, --instantiation [mode]',
218
- 'type output for custom module instantiation'
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
- '--async-mode [mode]',
226
- 'EXPERIMENTAL: use async imports and exports'
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
- '--async-wasi-exports',
237
- 'EXPERIMENTAL: async component exports from WASI interfaces'
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
- '--async-imports <imports...>',
241
- 'EXPERIMENTAL: async component imports (examples: "wasi:io/poll@0.2.0#poll", "wasi:io/poll#[method]pollable.block")'
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('guest-types')
262
- .description('(experimental) Generate guest types for the given WIT')
263
- .usage('<wit-path> -o <out-dir>')
264
- .argument('[<wit-path>]', 'path to a WIT file or directory')
265
- .option('--name <name>', 'custom output name')
266
- .option('-n, --world-name <world>', 'WIT world to generate types for')
267
- .option('-o, --out-dir <out-dir>', 'output directory')
268
- .option('-q, --quiet', 'disable output summary')
269
- .option(
270
- '--feature <feature>',
271
- 'enable one specific WIT feature (repeatable)',
272
- collectOptions,
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
- '--async-mode [mode]',
283
- 'EXPERIMENTAL: use async imports and exports'
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('run')
292
- .description('Run a WASI Command component')
293
- .usage('<command.wasm> <args...>')
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('<command>', 'WASI command binary to run')
298
- .option(
299
- '--jco-dir <dir>',
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
- '--jco-import <module>',
305
- 'Custom module to import before the run executes to support custom environment setup'
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('--jco-import-bindings [mode]', 'bindings mode for imports')
313
- .choices(['js', 'optimized', 'hybrid', 'direct-optimized'])
314
- .preset('js')
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('[args...]', 'Any CLI arguments for the component')
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 === '--help' || cmd === '-h') {
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('serve')
330
- .description('Serve a WASI HTTP component')
331
- .usage('<server.wasm> <args...>')
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('<server>', 'WASI server binary to run')
336
- .option('--port <number>')
337
- .option('--host <host>')
338
- .option(
339
- '--jco-dir <dir>',
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
- '--jco-import <module>',
345
- 'Custom module to import before the server executes to support custom environment setup'
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('--jco-import-bindings [mode]', 'bindings mode for imports')
349
- .choices(['js', 'optimized', 'hybrid', 'direct-optimized'])
350
- .preset('js')
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
- .argument('[args...]', 'Any CLI arguments for the component')
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 === '--help' || cmd === '-h') {
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('opt')
370
- .description(
371
- 'optimizes a Wasm component, including running wasm-opt Binaryen optimizations'
372
- )
373
- .usage('<component-file> -o <output-file> -- [wasm-opt arguments]')
374
- .argument('<component-file>', 'Wasm component binary filepath')
375
- .requiredOption(
376
- '-o, --output <output-file>',
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('wit')
389
- .description(
390
- 'extract the WIT from a WebAssembly Component [wasm-tools component wit]'
391
- )
392
- .argument('<component-path>', 'Wasm component binary filepath')
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('print')
399
- .description(
400
- 'print the WebAssembly WAT text for a binary file [wasm-tools print]'
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('metadata-show')
408
- .description(
409
- 'extract the producer metadata for a Wasm binary [wasm-tools metadata show]'
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('metadata-add')
417
- .description(
418
- 'add producer metadata for a Wasm binary [wasm-tools metadata add]'
419
- )
420
- .argument('[module]', 'Wasm component or core module filepath')
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('parse')
430
- .description(
431
- 'parses the Wasm text format into a binary file [wasm-tools parse]'
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('new')
439
- .description(
440
- 'create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]'
441
- )
442
- .argument('<core-module>', 'Wasm core module filepath')
443
- .requiredOption(
444
- '-o, --output <output-file>',
445
- 'Wasm component output filepath'
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('embed')
455
- .description(
456
- 'embed the component typing section into a core Wasm module [wasm-tools component embed]'
457
- )
458
- .argument('[core-module]', 'Wasm core module filepath')
459
- .requiredOption(
460
- '-o, --output <output-file>',
461
- 'Wasm component output filepath'
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 === 'string') {
489
- console.error(`${styleText(['red', 'bold'], "Error")}: ${e}\n`);
341
+ if (typeof e === "string") {
342
+ console.error(`${styleText(["red", "bold"], "Error")}: ${e}\n`);
490
343
  } else {
491
344
  console.error(e);
492
345
  }