@bytecodealliance/jco-std

中文文档
0.10.0发布于 2026/10/28(Apache-2.0 WITH LLVM-exception)TypeScriptES Module构建来源已验证近 30 天下载 17.1万

Library of shared functionality for use with the JS WebAssembly components

原始使用文档
文档目录19 节
  1. HTTP
  2. NodeJS API (experimental)
  3. Http (via the Hono Adapter)
  4. Node.js compatibility APIs
  5. node:path
  6. node:string_decoder
  7. node:repl
  8. node:tty
  9. node:wasi
  10. Node.js error globals
  11. node:child_process
  12. node:fs
  13. node:os
  14. node:dns
  15. node:net
  16. node:http and node:https
  17. node:http2
  18. node:timers
  19. Contribution

@bytecodealliance/jco-std

This @bytecodealliance/jco sub-project contains shared functionality and reusable libraries that can be used for building WebAssembly Components in Javascript.

WebAssembly Components are a WebAssembly binaries that use the Component Model, an evolving architecture for interoperable WebAssembly libraries, applications and environments.

WebAssembly components can be used from server side applications and in the browser, and @bytecodealliance/jco-std contains shared functionality and helpers for both environments.

@bytecodealliance/preview2-shim is an optional peer dependency used by the opt-in Node implementation of wasi:tls. Applications using this provider must share the same shim instance with their WASI sockets and streams: separate instances have different resource classes and IO workers. Use a shim version that satisfies the installed jco-std release's peer requirement. Other consumers do not need the shim.

Adapters

Below is a list of adapters provided by @bytecodealliance/jco-std:

HTTP

ExportDescription
http/adapters/honoEnables easier building of Hono HTTP servers

NodeJS API (experimental)

jco-std also makes available an experimental NodeJS API that is used by tools like jco to build NodeJS programs as components.

ExportDescription
wasi/0.2.x/node/24.x.x/assertnode:assert adapter, Node 24 on WASI p2
wasi/0.2.x/node/24.x.x/consolenode:console guest adapter over an explicit host capability
wasi/0.2.x/node/24.x.x/errorsNode 24 global error constructors and shared coded-error behavior
wasi/0.2.x/node/24.x.x/dnsnode:dns guest adapter over an explicit host capability
wasi/0.2.x/node/24.x.x/fsnode:fs and node:fs/promises over an explicit host capability
wasi/0.2.x/node/24.x.x/httpnode:http API with direct, WASI sockets, and WASI HTTP implementations
wasi/0.2.x/node/24.x.x/http2node:http2 API with direct and cleartext WASI sockets implementations
wasi/0.2.x/node/24.x.x/httpsnode:https API sharing the node:http core and implementations
wasi/0.2.x/node/24.x.x/netnode:net module over WASI Preview 2 0.2.12 sockets
wasi/0.2.x/node/24.x.x/net/corenode:net core over injected WASI Preview 2 sockets
wasi/0.2.x/node/24.x.x/osnode:os guest adapter over an explicit host capability
wasi/0.2.x/node/24.x.x/pathnode:path adapter, Node 24 on WASI p2
wasi/0.3.x/node/24.x.x/pathThe same Node 24 path implementation and types, used with P3 environment providers
wasi/0.2.x/node/24.x.x/string-decoderGuest-local node:string_decoder implementation for Node 24
wasi/0.2.x/node/24.x.x/timersNode 24 callback timers over engine scheduling
wasi/0.2.x/node/24.x.x/timers/promisesPromise timers, abortable interval iterators and scheduler
wasi/0.2.x/node/24.x.x/domainnode:domain, deprecated upstream: every use throws
wasi/0.2.x/node/24.x.x/async-hooksnode:async_hooks guest adapter, Node 24, synchronous scopes only
wasi/0.2.x/node/24.x.x/diagnostics-channelnode:diagnostics_channel guest adapter, Node 24
wasi/0.2.x/node/24.x.x/child-processnode:child_process guest adapter, Node 24 over an explicit host capability
wasi/0.2.x/node/24.x.x/clusternode:cluster guest adapter, Node 24 over an explicit host capability
wasi/0.2.x/node/24.x.x/eventsnode:events entry points Jco implements over a supplied emitter core
wasi/0.2.x/node/24.x.x/modulenode:module, Node 24: classification and source maps; loading refuses
wasi/0.2.x/node/26.x.x/ffinode:ffi guest adapter, Node 26 over an explicit host capability
wasi/0.2.x/node/26.x.x/ffi/hostDeny-by-default host for jco:node/ffi
wasi/0.2.x/node/26.x.x/ffi/host/nodeOpt-in host over the runtime's real node:ffi; setSuffix() pins the suffix
wasi/0.2.x/node/24.x.x/inspectornode:inspector guest adapter, Node 24 over an explicit host capability
wasi/0.2.x/node/24.x.x/inspector/promisesnode:inspector/promises, sharing one core with node:inspector
wasi/0.2.x/node/24.x.x/inspector/hostDeny-by-default host for jco:node/inspector
wasi/0.2.x/node/24.x.x/inspector/host/nodeOpt-in host over the runtime's real node:inspector
wasi/0.2.x/node/24.x.x/stream and /stream/promisesClassic Node streams over readable-stream 4.7.0, with Node 24 adapters
wasi/0.2.x/node/24.x.x/stream/consumersPortable node:stream/consumers, Node 24
wasi/0.2.x/node/24.x.x/stream/iterExperimental iterable streams from Node 24.20
wasi/0.2.x/node/24.x.x/replnode:repl over the readline port; global-scope evaluation only
wasi/0.2.x/node/24.x.x/ttynode:tty guest adapter, Node 24 over an explicit host capability
wasi/0.2.x/node/24.x.x/tty/hostDeny-by-default host for jco:node/tty
wasi/0.2.x/node/24.x.x/tty/host/nodeOpt-in host over the runtime's real node:tty and its descriptors
wasi/0.2.x/node/24.x.x/wasinode:wasi guest adapter, Node 24; construction only, running refuses
wasi/0.2.x/node/24.x.x/wasi/hostDeny-by-default host for jco:node/wasi
wasi/0.2.x/node/24.x.x/wasi/host/nodeOpt-in host running the real node:wasi constructor for its uvwasi checks
wasi/0.2.x/node/24.x.x/child-process/hostDeny-by-default host for jco:node/child-process
wasi/0.2.x/node/24.x.x/child-process/host/nodeOpt-in host over the runtime's real node:child_process
wasi/0.2.x/node/24.x.x/cluster/hostDeny-by-default host for jco:node/cluster
wasi/0.2.x/node/24.x.x/cluster/host/nodeOpt-in host over the runtime's real node:cluster
wasi/0.2.x/node/24.x.x/console/hostDeny-by-default host for jco:node/console
wasi/0.2.x/node/24.x.x/console/host/nodeOpt-in host over the runtime's real node:console
wasi/0.2.x/node/24.x.x/dns/promisesnode:dns/promises, sharing one core with node:dns
wasi/0.2.x/node/24.x.x/dns/hostDeny-by-default host for jco:node/dns
wasi/0.2.x/node/24.x.x/dns/host/nodeOpt-in host over the runtime's real node:dns
wasi/0.2.x/node/24.x.x/fs/promisesnode:fs/promises, sharing one core with node:fs
wasi/0.2.x/node/24.x.x/fs/hostDeny-by-default host for jco:node/fs
wasi/0.2.x/node/24.x.x/fs/host/nodeOpt-in host over the runtime's real node:fs
wasi/0.2.x/node/24.x.x/http/corenode:http core shared by the selectable implementations
wasi/0.2.x/node/24.x.x/http/impl/wasi-socketsnode:http implementation over WASI Preview 2 sockets
wasi/0.2.x/node/24.x.x/http/impl/wasi-httpnode:http implementation over WASI Preview 2 HTTP
wasi/0.2.x/node/24.x.x/http/hostDeny-by-default host for jco:node/http
wasi/0.2.x/node/24.x.x/http/host/nodeOpt-in host over the runtime's real node:http and node:https
wasi/0.2.x/node/24.x.x/https/corenode:https core shared by the selectable implementations
wasi/0.2.x/node/24.x.x/os/hostDeny-by-default host for jco:node/os
wasi/0.2.x/node/24.x.x/os/host/nodeOpt-in host over the runtime's real node:os
node/pathLegacy unversioned alias for wasi/0.2.x/node/24.x.x/path

Quickstart

@bytecodealliance/jco-std can be used in varied ways via it's exports, this section contains some examples of how to get started quickly.

Http (via the Hono Adapter)

To use @bytecodealliance/jco-std to make building Hono applications easier with WebAssembly, use the @bytecodealliance/jco-std/http/adapters/hono export:

import { Hono } from "hono";

import { fire } from "@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server";

const app = new Hono();
app.get("/", () => "Hello World!");

fire(app);

// Although we've called `fire()` with wasi HTTP configured for use above,
// we still need to actually export the `wasi:http/incoming-handler` interface object,
// as componentize-js will be looking for the ES module export.
export { incomingHandler } from "@bytecodealliance/jco-std/wasi/0.2.x/http/adapters/hono/server";

[!NOTE] We use @bytecodealliance/jco-std/wasi/0.2.x, but if you'd like to use a specific version, you can use an explicitly versioned export like @bytecodealliance/jco-std/wasi/0.2.12.

The 0.2.x path selects the newest WASI 0.2 adapter verified with the ComponentizeJS version used by Jco. It may change in any jco-std release. Use an explicitly versioned path when your component must retain an older WIT world.

Node.js compatibility APIs

[!WARNING] Jco's Node.js built-in compatibility for components is experimental and subject to change. APIs, behavior, and generated component interfaces may change incompatibly without a semver-major release.

The table above lists the available adapters. Application code should normally keep its node: imports and let jco componentize select the implementation. See the Node.js built-in compatibility guide for setup, versioning, capabilities, and compatibility boundaries.

node:path

import path, { matchesGlob } from "node:path";
import { join as winJoin } from "node:path/win32";

export function outputPath(name) {
  if (!matchesGlob(name, "**/*.js")) throw new TypeError("expected JavaScript");
  return `${path.resolve("dist", name)}|${winJoin("C:\\dist", name)}`;
}

See node:path.

node:string_decoder

import { Buffer } from "node:buffer";
import { StringDecoder } from "node:string_decoder";

const decoder = new StringDecoder("utf8");
decoder.write(Buffer.from([0xf0, 0x9f]));
decoder.end(Buffer.from([0x8c, 0x8d])); // "🌍"

See node:string_decoder.

node:repl

import repl from "node:repl";

export function attach(input, output) {
  const server = repl.start({ prompt: "app> ", input, output, useGlobal: true });
  server.context.app = { version: "1.0.0" };
  return server;
}

See node:repl.

node:tty

import { ReadStream, WriteStream, isatty } from "node:tty";

export function terminal() {
  if (!isatty(0) || !isatty(1)) throw new Error("a terminal is required");
  return { input: new ReadStream(0), output: new WriteStream(1) };
}

See node:tty.

node:wasi

import { WASI } from "node:wasi";

export function createWasi() {
  return new WASI({ version: "preview1" });
}

See node:wasi.

Node.js error globals

export function describeFailure() {
  const cause = new TypeError("invalid input");
  return new Error("operation failed", { cause }).cause.message;
}

See Node.js error globals.

node:child_process

import { execFileSync } from "node:child_process";

export function nodeVersion() {
  return execFileSync("node", ["--version"], { encoding: "utf8" }).trim();
}

See node:child_process.

node:fs

import { readFileSync } from "node:fs";
import { writeFile } from "node:fs/promises";

export async function replace(path, contents) {
  await writeFile(path, contents);
  return readFileSync(path, "utf8");
}

See node:fs.

node:os

import os from "node:os";

export function hostSummary() {
  return `${os.platform()} ${os.arch()} (${os.availableParallelism()} CPUs)`;
}

See node:os.

node:dns

import dns from "node:dns";
import dnsPromises from "node:dns/promises";

export function configuredServers() {
  return [...dns.getServers(), ...dnsPromises.getServers()];
}

See node:dns.

node:net

import { connect, createServer } from "node:net";

createServer((socket) => socket.end("hello")).listen(8080, "127.0.0.1");
connect(8080, "127.0.0.1").setEncoding("utf8").on("data", console.log);

See node:net.

node:http and node:https

import { createServer } from "node:http";
import { get } from "node:https";

createServer((request, response) => {
  response.end(`received ${request.method} ${request.url}`);
}).listen(8080, "127.0.0.1");

get("https://example.com/", (response) => response.resume());

See node:http and node:https.

node:http2

import { connect } from "node:http2";

const session = connect("https://example.com");
const stream = session.request({ ":path": "/status" });
stream.on("end", () => session.close());
stream.end();

See node:http2.

node:timers

import { setTimeout as delay, scheduler } from "node:timers/promises";

await delay(10, "ready");
await scheduler.yield();

See node:timers.

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.

版本与发布记录

@bytecodealliance/jco-std 共发布 17 个版本,首次发布于 2025/11/07;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/10/2811 天前
0.9.02026/10/1624 天前
0.8.02026/10/1425 天前
0.7.02026/10/061 个月前
0.6.02026/10/051 个月前
0.5.02026/09/231 个月前

关于 @bytecodealliance/jco-std 的常见问题

@bytecodealliance/jco-std 是什么?

Library of shared functionality for use with the JS WebAssembly components

如何安装 @bytecodealliance/jco-std?

在项目目录运行 npm install @bytecodealliance/jco-std,或使用 pnpm add / yarn add / bun add。

@bytecodealliance/jco-std 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bytecodealliance/jco-std 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bytecodealliance/jco-std 可以商用吗?

@bytecodealliance/jco-std 使用 (Apache-2.0 WITH LLVM-exception) 许可。声明的许可为 (Apache-2.0 WITH LLVM-exception),请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@bytecodealliance/jco-std 的下载量有多少?

根据 npm 官方下载统计,@bytecodealliance/jco-std 在 2026/10/09 – 2026/11/07 这 30 天内被下载 171,058 次,日均约 5,702 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bytecodealliance/jco-std 还在维护吗?

最新版本 0.10.0 发布于 2026/10/28(11 天前);至今共发布 17 个版本,其中过去 12 个月发布了 14 个;首次发布于 2025/11/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。