npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bytecodealliance/jco

v1.8.1

Published

JavaScript tooling for working with WebAssembly Components

Downloads

97,473

Readme

A Bytecode Alliance project

Overview

Jco provides a fully native JS toolchain for working with WebAssembly Components in JavaScript.

Features include:

  • "Transpiling" Wasm Component binaries into ES modules that can run in any JS environment.
  • WASI Preview2 support in Node.js & browsers (experimental).
  • Component builds of 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).

For creating components in other languages, see the Cargo Component project for Rust and Wit Bindgen for various guest bindgen helpers.

Installation

npm install @bytecodealliance/jco

Jco can be used as either a library import or as a CLI via the jco command.

Example

See the Example Workflow page for a full usage example.

CLI

Usage: jco <command> [options]

jco - WebAssembly JS Component Tools
      JS Component Transpilation Bindgen & Wasm Tools for JS

Options:
  -V, --version                         output the version number
  -h, --help                            display help for command

Commands:
  componentize [options] <js-source>    Create a component from a JavaScript module
  transpile [options] <component-path>  Transpile a WebAssembly Component to JS + core Wasm for JavaScript execution
  types [options] <wit-path>            Generate types for the given WIT
  run [options] <command> [args...]     Run a WASI Command component
  serve [options] <server> [args...]    Serve a WASI HTTP component
  opt [options] <component-file>        optimizes a Wasm component, including running wasm-opt Binaryen optimizations
  wit [options] <component-path>        extract the WIT from a WebAssembly Component [wasm-tools component wit]
  print [options] <input>               print the WebAssembly WAT text for a binary file [wasm-tools print]
  metadata-show [options] [module]      extract the producer metadata for a Wasm binary [wasm-tools metadata show]
  metadata-add [options] [module]       add producer metadata for a Wasm binary [wasm-tools metadata add]
  parse [options] <input>               parses the Wasm text format into a binary file [wasm-tools parse]
  new [options] <core-module>           create a WebAssembly component adapted from a component core Wasm [wasm-tools component new]
  embed [options] [core-module]         embed the component typing section into a core Wasm module [wasm-tools component embed]
  help [command]                        display help for command

For help with individual command options, use jco <cmd> --help.

Transpile

See the Transpiling Docs for more background and info.

Bindgen Crate

To directly call into the transpilation in Rust, the bindgen used in Jco is also available on crates.io as js-component-bindgen.

Run & Serve

For Wasm components that implement the WASI Command world, a jco run utility is provided to run these applications in Node.js.

jco run cowasy.component.wasm hello

Using the preview2-shim WASI implementation, full access to the underlying system primitives is provided, including filesystem and environment variable permissions.

For HTTP Proxy components, jco serve provides a JS server implementation:

jco serve --port 8080 server.wasm

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

Note: jco componentize is considered experimental, and breaking changes may be made without notice.

To componentize a JS file run:

jco componentize app.js --wit wit -n world-name -o component.wasm

Creates a component from a JS module implementing a WIT world definition, via a Spidermonkey engine embedding.

See ComponentizeJS for more details on this process.

API

transpile(component: Uint8Array, opts?): Promise<{ files: Record<string, Uint8Array> }>

Transpile a Component to JS.

opt(component: Uint8Array, opts?): Promise<{ component: Uint8Array }>

Optimize a Component with the Binaryen Wasm-opt project.

componentWit(component: Uint8Array, document?: string): string

Extract the WIT world from a component binary.

print(component: Uint8Array): string

Print the WAT for a Component binary.

metadataShow(wasm: Uint8Array): Metadata

Extract the producer toolchain metadata for a component and its nested modules.

parse(wat: string): Uint8Array

Parse a compoment WAT to output a Component binary.

componentNew(coreWasm: Uint8Array | null, adapters?: [String, Uint8Array][]): Uint8Array

"WIT Component" Component creation tool, optionally providing a set of named adapter binaries.

componentEmbed(coreWasm: Uint8Array | null, wit: String, opts?: { stringEncoding?, dummy?, world?, metadata? }): Uint8Array

"WIT Component" Component embedding tool, for embedding component types into core binaries, as an advanced use case of component generation.

metadataAdd(wasm: Uint8Array, metadata): Uint8Array

Add new producer metadata to a component or core Wasm binary.

Contributing

See the Contributing chapter of the Jco book.

License

This project is licensed under the Apache 2.0 license with the LLVM exception. See LICENSE for more details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.