@bytecodealliance/jco
Advanced tools
Comparing version 0.14.1 to 0.14.2
@@ -72,3 +72,2 @@ export type Files = [string, Uint8Array][]; | ||
import { WasiRandomRandom } from './interfaces/wasi-random-random.js'; | ||
import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp.js'; | ||
export function generate(component: Uint8Array, options: GenerateOptions): Transpiled; | ||
@@ -75,0 +74,0 @@ export function generateTypes(name: string, options: TypeGenerationOptions): Files; |
@@ -17,3 +17,2 @@ import { WasiCliEnvironment } from './interfaces/wasi-cli-environment.js'; | ||
import { WasiRandomRandom } from './interfaces/wasi-random-random.js'; | ||
import { WasiSocketsTcp } from './interfaces/wasi-sockets-tcp.js'; | ||
import { LocalWasmToolsTools } from './interfaces/local-wasm-tools-tools.js'; | ||
@@ -20,0 +19,0 @@ export const tools: typeof LocalWasmToolsTools; |
{ | ||
"name": "@bytecodealliance/jco", | ||
"version": "0.14.1", | ||
"version": "0.14.2", | ||
"description": "JavaScript tooling for working with WebAssembly Components", | ||
@@ -21,3 +21,3 @@ "author": "Guy Bedford", | ||
"dependencies": { | ||
"@bytecodealliance/preview2-shim": "0.14.1", | ||
"@bytecodealliance/preview2-shim": "0.14.2", | ||
"binaryen": "^111.0.0", | ||
@@ -24,0 +24,0 @@ "chalk-template": "^0.4.0", |
@@ -13,2 +13,8 @@ <div align="center"> | ||
</p> | ||
<h3> | ||
<a href="https://bytecodealliance.github.io/jco/">Contributing</a> | ||
<span> | </span> | ||
<a href="https://bytecodealliance.zulipchat.com/#narrow/stream/409526-jco">Chat on Zulip</a> | ||
</h3> | ||
</div> | ||
@@ -18,3 +24,3 @@ | ||
`jco` is a fully native JS tool for working with [WebAssembly Components](https://github.com/WebAssembly/component-model) in JavaScript. | ||
JCO provides a fully native JS toolchain for working with [WebAssembly Components](https://github.com/WebAssembly/component-model) in JavaScript. | ||
@@ -26,2 +32,3 @@ Features include: | ||
* Component builds of [Wasm Tools](https://github.com/bytecodealliance/wasm-tools) helpers, available for use as a library or CLI commands for use in native JS environments, as well as optimization helper for Components via Binaryen. | ||
* Run and serve commands like Wasmtime, as JS implementations of the Command and HTTP Proxy worlds. | ||
* "Componentize" command to easily create components written in JavaScript (wrapper of [ComponentizeJS](https://github.com/bytecodealliance/ComponentizeJS)). | ||
@@ -39,3 +46,3 @@ | ||
jco can be used as either a library or a CLI via the `jco` CLI command. | ||
JCO can be used as either a library import or as a CLI via the `jco` command. | ||
@@ -61,3 +68,4 @@ ## Example | ||
transpile [options] <component-path> Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution | ||
run <command> [args...] Run a WebAssembly Command component | ||
run [options] <command> [args...] Run a WASI Command component | ||
serve [options] <command> [args...] Serve a WASI HTTP component | ||
opt [options] <component-file> optimizes a Wasm component, including running wasm-opt Binaryen optimizations | ||
@@ -118,5 +126,5 @@ wit [options] <component-path> extract the WIT from a WebAssembly Component [wasm-tools component wit] | ||
### Run | ||
### Run & Serve | ||
For Wasm components that implement the WASI Command world, a `jco run` utility is provided to run these applications in Node.js: | ||
For Wasm components that implement the WASI Command world, a `jco run` utility is provided to run these applications in Node.js. | ||
@@ -129,4 +137,10 @@ ``` | ||
> [preview2-shim](packages/preview2-shim) is currently being stabilized in Node.js, tracking in https://github.com/bytecodealliance/jco/milestone/1. | ||
For HTTP Proxy components, `jco serve` provides a JS server implementation: | ||
``` | ||
jco serve --port 8080 server.wasm | ||
``` | ||
> [Wasmtime](https://github.com/bytecodealliance/wasmtime) generally provides the most performant implementation for executing command and proxy worlds to use. These implementations are rather for when JS virtualization is required or the most convenient approach. | ||
### Componentize | ||
@@ -133,0 +147,0 @@ |
@@ -13,3 +13,50 @@ import { getTmpDir } from '../common.js'; | ||
args = [...args]; | ||
return runComponent(componentPath, args, opts, ` | ||
if (!mod.run || !mod.run.run) { | ||
console.error('Not a valid command component to execute.'); | ||
process.exit(1); | ||
} | ||
try { | ||
mod.run.run(); | ||
// for stdout flushing | ||
await new Promise(resolve => setTimeout(resolve)); | ||
process.exit(0); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
`); | ||
} | ||
export async function serve (componentPath, args, opts) { | ||
let tryFindPort = false; | ||
let { port, host } = opts; | ||
if (port === undefined) { | ||
tryFindPort = true; | ||
port = '8000'; | ||
} | ||
// Ensure that `args` is an array | ||
args = [...args]; | ||
return runComponent(componentPath, args, opts, ` | ||
import { HTTPServer } from '@bytecodealliance/preview2-shim/http'; | ||
const server = new HTTPServer(mod.incomingHandler); | ||
${tryFindPort ? ` | ||
let port = ${port}; | ||
while (true) { | ||
try { | ||
server.listen(port, ${JSON.stringify(host)}); | ||
break; | ||
} catch (e) { | ||
if (e.code !== 'EADDRINUSE') | ||
throw e; | ||
} | ||
port++; | ||
} | ||
` : `server.listen(${port}, ${JSON.stringify(host)})`} | ||
console.error(\`Server listening on \${port}...\`); | ||
`); | ||
} | ||
async function runComponent (componentPath, args, opts, executor) { | ||
const jcoImport = opts.jcoImport ? resolve(opts.jcoImport) : null; | ||
@@ -22,2 +69,3 @@ | ||
} | ||
try { | ||
@@ -31,3 +79,4 @@ try { | ||
outDir, | ||
tracing: opts.jcoTrace | ||
tracing: opts.jcoTrace, | ||
map: opts.jcoMap | ||
}); | ||
@@ -69,26 +118,7 @@ } | ||
${jcoImport ? `import ${JSON.stringify(pathToFileURL(jcoImport))}` : ''} | ||
function logInvalidCommand () { | ||
console.error('Not a valid command component to execute, make sure it was built to a command adapter and with the same version.'); | ||
} | ||
try { | ||
process.argv[1] = "${name}"; | ||
const mod = await import('./${name}.js'); | ||
if (!mod.run || !mod.run.run) { | ||
logInvalidCommand(); | ||
process.exit(1); | ||
} | ||
try { | ||
mod.run.run(); | ||
// TODO: figure out stdout flush! | ||
setTimeout(() => {}); | ||
} | ||
catch (e) { | ||
console.error(e); | ||
process.exit(1); | ||
} | ||
} | ||
catch (e) { | ||
logInvalidCommand(); | ||
throw e; | ||
} | ||
} catch {} | ||
const mod = await import('./${name}.js'); | ||
${executor} | ||
`); | ||
@@ -109,2 +139,2 @@ | ||
} | ||
} | ||
} |
@@ -84,3 +84,3 @@ import { $init, generate } from '../../obj/js-component-bindgen-component.js'; | ||
await $init; | ||
if (opts.noWasiShim || opts.instantiation) opts.wasiShim = false; | ||
if (opts.instantiation) opts.wasiShim = false; | ||
@@ -123,4 +123,4 @@ let spinner; | ||
tracing: opts.tracing ?? false, | ||
noNodejsCompat: !(opts.nodejsCompat ?? true), | ||
noTypescript: opts.noTypescript || false, | ||
noNodejsCompat: opts.nodejsCompat === false, | ||
noTypescript: opts.typescript === false, | ||
tlaCompat: opts.tlaCompat ?? false, | ||
@@ -127,0 +127,0 @@ base64Cutoff: opts.js ? 0 : opts.base64Cutoff ?? 5000, |
@@ -5,3 +5,3 @@ #!/usr/bin/env node | ||
import { transpile } from './cmd/transpile.js'; | ||
import { run } from './cmd/run.js'; | ||
import { run as runCmd, serve as serveCmd } from './cmd/run.js'; | ||
import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js'; | ||
@@ -15,3 +15,3 @@ import { componentize } from './cmd/componentize.js'; | ||
.usage('<command> [options]') | ||
.version('0.14.1'); | ||
.version('0.14.2'); | ||
@@ -57,12 +57,45 @@ function myParseInt(value) { | ||
program.command('run') | ||
.description('Run a WebAssembly Command component') | ||
.description('Run a WASI Command component') | ||
.usage('<command.wasm> <args...>') | ||
.helpOption(false) | ||
.argument('<command>', 'Wasm command binary to run') | ||
.allowUnknownOption(true) | ||
.allowExcessArguments(true) | ||
.argument('<command>', 'WASI command binary to run') | ||
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the run command') | ||
.option('--jco-trace', 'Enable call tracing') | ||
.option('--jco-import <module>', 'Custom module to import before the run executes to support custom environment setup') | ||
.argument('[args...]', 'Any CLI arguments to provide to the command') | ||
.action(asyncAction(run)); | ||
.option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports') | ||
.argument('[args...]', 'Any CLI arguments for the component') | ||
.action(asyncAction(async function run (cmd, args, opts, command) { | ||
// specially only allow help option in first position | ||
if (cmd === '--help' || cmd === '-h') { | ||
command.help(); | ||
} else { | ||
return runCmd(cmd, args, opts); | ||
} | ||
})); | ||
program.command('serve') | ||
.description('Serve a WASI HTTP component') | ||
.usage('<server.wasm> <args...>') | ||
.helpOption(false) | ||
.allowUnknownOption(true) | ||
.allowExcessArguments(true) | ||
.argument('<server>', 'WASI server binary to run') | ||
.option('--port <number>') | ||
.option('--host <host>') | ||
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the transpiled code') | ||
.option('--jco-trace', 'Enable call tracing') | ||
.option('--jco-import <module>', 'Custom module to import before the server executes to support custom environment setup') | ||
.option('--jco-map <mappings...>', 'specifier=./output custom mappings for the component imports') | ||
.argument('[args...]', 'Any CLI arguments for the component') | ||
.action(asyncAction(async function serve (cmd, args, opts, command) { | ||
// specially only allow help option in first position | ||
if (cmd === '--help' || cmd === '-h') { | ||
command.help(); | ||
} else { | ||
return serveCmd(cmd, args, opts); | ||
} | ||
})); | ||
program.command('opt') | ||
@@ -130,2 +163,4 @@ .description('optimizes a Wasm component, including running wasm-opt Binaryen optimizations') | ||
program.showHelpAfterError(); | ||
program.parse(); | ||
@@ -132,0 +167,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
7493
207
9499193
+ Added@bytecodealliance/preview2-shim@0.14.2(transitive)
- Removed@bytecodealliance/preview2-shim@0.14.1(transitive)