
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@bytecodealliance/jco-transpile
Advanced tools
WebAssembly Component transpilation functionality for Jco
@bytecodealliance/jco-transpile
This @bytecodealliance/jco
sub-project enables transpilation of WebAssembly Components into ES modules
that can be run in Javascript environments like NodeJS and the browser (experimental).
@bytecodealliance/jco-transpile
is used primarily when only transpilation functionality of jco
is needed,
and jco
derives it's use of transpilation from this library.
[!WARNING] Browser support is considered experimental, and not currently suitable for production applications.
To use @bytecodealliance/jco-transpile
as a library in your own code, you can use some of the exported functions.
To transpile an existing WebAssembly component (path on disk, Buffer
):
import { dirname } from "node:path";
import { mkdir, writeFile } from "node:fs/promises";
import { transpile } from '@bytecodealliance/jco-transpile';
async function example() {
const { files, imports, exports } = await transpile('path/to/component.wasm', { outDir: 'path/to/output/dir' });
// NOTE: Files is a serialization of the files produced of the following type:
// type FileBytes = { [filepath: string]: Uint8Array; };
//
// You can use the code below to write out all files to a given directory
await Promise.all(
Object.entries(files).map(async ([filePath, bytes]) => {
await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, bytes);
})
);
}
[!NOTE]
transpile
takes many options -- consulttranspile.d.ts
for more detailed type information.
outDir
controls the prefix of generated file paths, so it is specified, despite the fact that no files are actually written to disk.
To generate host types:
import { dirname } from "node:path";
import { mkdir, writeFile } from "node:fs/promises";
import { generateHostTypes } from '@bytecodealliance/jco-transpile';
async function example() {
const files = await generateHostTypes('path/to/wit/dir-or-file, { outDir: 'path/to/output/dir' });
// NOTE: Files is a serialization of the files produced of the following type:
// type FileBytes = { [filepath: string]: Uint8Array; };
//
// You can use the code below to write out all files to a given directory
await Promise.all(
Object.entries(files).map(async ([filePath, bytes]) => {
await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, bytes);
})
);
}
Host types are the implementations of WIT interfaces that are used by post-transpilation JS code, i.e. on the "host" (NodeJS + V8 or the browser), to make platform imports work.
For a given import in a WIT world, this type generation would enable implementation of the interface.
To generate guest types:
import { dirname } from "node:path";
import { mkdir, writeFile } from "node:fs/promises";
import { generateGuestTypes } from '@bytecodealliance/jco-transpile';
async function example() {
const files = await generateGuestTypes('path/to/wit/dir-or-file, { outDir: 'path/to/output/dir' });
// NOTE: Files is a serialization of the files produced of the following type:
// type FileBytes = { [filepath: string]: Uint8Array; };
//
// You can use the code below to write out all files to a given directory
await Promise.all(
Object.entries(files).map(async ([filePath, bytes]) => {
await mkdir(dirname(filePath), { recursive: true });
await writeFile(filePath, bytes);
})
);
}
Guest types are the implementations of WIT interfaces that are used by JS components -- i.e. JS code that is
turned into a component (by jco componentize
/componentize-js
) and performing useful work.
For a given import in a WIT world, this type generation would enable calling/using the interface.
This project is licensed under the Apache 2.0 license with the LLVM exception. See LICENSE for more details.
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.
FAQs
WebAssembly Component transpilation functionality for Jco
We found that @bytecodealliance/jco-transpile demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.