@bytecodealliance/jco-std

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

与JS WebAssembly组件共享功能库

中文使用文档
文档目录19 节
  1. HTTP 密码
  2. 节点JS API(实验)
  3. Http( 通过Hono适配器)
  4. 节点.js 兼容 API
  5. node:path
  6. node:string_decoder
  7. node:repl
  8. node:tty
  9. node:wasi
  10. 节点.js 错误全局
  11. node:child_process
  12. node:fs
  13. node:os
  14. node:dns
  15. node:net
  16. node:http 财务报告和审定财务报表 node:https
  17. node:http2
  18. node:timers
  19. 捐款

@bytecodealliance/jco-std

这个 @bytecodealliance/jco 子项目包含共享功能和 用于在 Javascript 中构建 Web Assembly 组件的可重复使用的库.

Web大会组件 是使用组件模型的网络大会二进制, 用于互操作的WebAssembly库、应用程序和环境的不断发展的架构.

WebAssembly 组件可以从服务器侧式应用程序使用 财务报告和审定财务报表 在浏览器中,以及 @bytecodealliance/jco-std 包含两种环境的共享功能和辅助工具.

@bytecodealliance/preview2-shim 是选入时使用的可选对等依赖 节点执行 wasi:tls。使用此提供者的应用程序必须共享 同样的shim 实例与他们的 WASI 套接字和流: 单独的例子 不同的资源类 和IO工人。 使用符合 已安装 jco-std 释放的对等要求。 其他消费者并不需要这个.

适配器

以下是由下列人员提供的适配器列表: @bytecodealliance/jco-std数字 :

HTTP 密码

导出说明
http/adapters/hono启用更容易的构建 浩诺 HTTP 服务器

节点JS API(实验)

jco-std 还提供实验性节点JS API,用于工具如 jco 改为 将NodeJS程序建设为组件.

导出说明
wasi/0.2.x/node/24.x.x/assertnode:assert 适配器, WASI p2 上的节点 24
wasi/0.2.x/node/24.x.x/consolenode:console 宾客适配器,以取代明确的主机能力
wasi/0.2.x/node/24.x.x/errors节点 24 全球错误构建器和共享编码错误行为
wasi/0.2.x/node/24.x.x/dnsnode:dns 宾客适配器,以取代明确的主机能力
wasi/0.2.x/node/24.x.x/fsnode:fs 财务报告和审定财务报表 node:fs/promises 超过明确的东道方能力
wasi/0.2.x/node/24.x.x/httpnode:http API 有直接的 WASI 套接字 和 WASI HTTP 执行
wasi/0.2.x/node/24.x.x/http2node:http2 API 有直接和清晰文本 WASI 套接字执行
wasi/0.2.x/node/24.x.x/httpsnode:https API 共享 node:http 核心和执行
wasi/0.2.x/node/24.x.x/netnode:net 预览
wasi/0.2.x/node/24.x.x/net/corenode:net 核心在注入的 WASI 预览 2 套接字
wasi/0.2.x/node/24.x.x/osnode:os 宾客适配器,以取代明确的主机能力
wasi/0.2.x/node/24.x.x/pathnode:path 适配器, WASI p2 上的节点 24
wasi/0.3.x/node/24.x.x/path相同的节点 24 路径执行和类型,与 P3 环境提供者使用
wasi/0.2.x/node/24.x.x/string-decoder来宾-当地 node:string_decoder 执行节点24
wasi/0.2.x/node/24.x.x/timers节点 24 调用时间与引擎调度
wasi/0.2.x/node/24.x.x/timers/promises承诺计时器、可中止间隔计时器和排程器
wasi/0.2.x/node/24.x.x/domainnode:domain,在上游贬值:每个用途
wasi/0.2.x/node/24.x.x/async-hooksnode:async_hooks 客机适配器,节点 24,仅同步瞄准镜
wasi/0.2.x/node/24.x.x/diagnostics-channelnode:diagnostics_channel 客机适配器,节点24
wasi/0.2.x/node/24.x.x/child-processnode:child_process 客机适配器,通过明确的主机能力24号节点
wasi/0.2.x/node/24.x.x/clusternode:cluster 客机适配器,通过明确的主机能力24号节点
wasi/0.2.x/node/24.x.x/eventsnode:events jco在供应的发射芯上执行入口
wasi/0.2.x/node/24.x.x/modulenode:module,节点24:分类和源地图;拒绝加载
wasi/0.2.x/node/26.x.x/ffinode:ffi 客机适配器,通过明确的主机能力26号节点
wasi/0.2.x/node/26.x.x/ffi/host拒绝默认主机 jco:node/ffi
wasi/0.2.x/node/26.x.x/ffi/host/nodeOpt-in 主机在运行时间的真实性 node:ffi· ; setSuffix() 标出后缀
wasi/0.2.x/node/24.x.x/inspectornode:inspector 客机适配器,通过明确的主机能力24号节点
wasi/0.2.x/node/24.x.x/inspector/promisesnode:inspector/promises,共享一个核心 node:inspector
wasi/0.2.x/node/24.x.x/inspector/host拒绝默认主机 jco:node/inspector
wasi/0.2.x/node/24.x.x/inspector/host/nodeOpt-in 主机在运行时间的真实性 node:inspector
wasi/0.2.x/node/24.x.x/stream 财务报告和审定财务报表 /stream/promises经典 可读流上的节点流 4.7.0, 有节点 24 适配器
wasi/0.2.x/node/24.x.x/stream/consumers可移植 node:stream/consumers,节点24
wasi/0.2.x/node/24.x.x/stream/iter来自节点24.20的可实验流
wasi/0.2.x/node/24.x.x/replnode:repl 横过读行端口;只进行全局评价
wasi/0.2.x/node/24.x.x/ttynode:tty 客机适配器,通过明确的主机能力24号节点
wasi/0.2.x/node/24.x.x/tty/host拒绝默认主机 jco:node/tty
wasi/0.2.x/node/24.x.x/tty/host/nodeOpt-in 主机在运行时间的真实性 node:tty 及其说明
wasi/0.2.x/node/24.x.x/wasinode:wasi 客机适配器, 节点 24; 只构造, 拒绝运行
wasi/0.2.x/node/24.x.x/wasi/host拒绝默认主机 jco:node/wasi
wasi/0.2.x/node/24.x.x/wasi/host/node运行真实的 Opt- in 主机 node:wasi 它的构造器 uvwasi 检查
wasi/0.2.x/node/24.x.x/child-process/host拒绝默认主机 jco:node/child-process
wasi/0.2.x/node/24.x.x/child-process/host/nodeOpt-in 主机在运行时间的真实性 node:child_process
wasi/0.2.x/node/24.x.x/cluster/host拒绝默认主机 jco:node/cluster
wasi/0.2.x/node/24.x.x/cluster/host/nodeOpt-in 主机在运行时间的真实性 node:cluster
wasi/0.2.x/node/24.x.x/console/host拒绝默认主机 jco:node/console
wasi/0.2.x/node/24.x.x/console/host/nodeOpt-in 主机在运行时间的真实性 node:console
wasi/0.2.x/node/24.x.x/dns/promisesnode:dns/promises,共享一个核心 node:dns
wasi/0.2.x/node/24.x.x/dns/host拒绝默认主机 jco:node/dns
wasi/0.2.x/node/24.x.x/dns/host/nodeOpt-in 主机在运行时间的真实性 node:dns
wasi/0.2.x/node/24.x.x/fs/promisesnode:fs/promises,共享一个核心 node:fs
wasi/0.2.x/node/24.x.x/fs/host拒绝默认主机 jco:node/fs
wasi/0.2.x/node/24.x.x/fs/host/nodeOpt-in 主机在运行时间的真实性 node:fs
wasi/0.2.x/node/24.x.x/http/corenode:http 可选择执行部分共享的核心
wasi/0.2.x/node/24.x.x/http/impl/wasi-socketsnode:http 预览 2 套接字
wasi/0.2.x/node/24.x.x/http/impl/wasi-httpnode:http 预览 2 HTTP 执行
wasi/0.2.x/node/24.x.x/http/host拒绝默认主机 jco:node/http
wasi/0.2.x/node/24.x.x/http/host/nodeOpt-in 主机在运行时间的真实性 node:http 财务报告和审定财务报表 node:https
wasi/0.2.x/node/24.x.x/https/corenode:https 可选择执行部分共享的核心
wasi/0.2.x/node/24.x.x/os/host拒绝默认主机 jco:node/os
wasi/0.2.x/node/24.x.x/os/host/nodeOpt-in 主机在运行时间的真实性 node:os
node/path遗产未转换的别名 wasi/0.2.x/node/24.x.x/path

快速启动

@bytecodealliance/jco-std 本节通过出口可以以各种方式使用 包含一些如何快速启动的例子.

Http( 通过Hono适配器)

用于 @bytecodealliance/jco-std 建楼 浩诺 webAssembly 的应用程序, 使用该 @bytecodealliance/jco-std/http/adapters/hono 导出 :

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";

[注] 我们用 @bytecodealliance/jco-std/wasi/0.2.x但是,如果你想使用一个特定的版本,你可以 使用明确版本的导出像 @bytecodealliance/jco-std/wasi/0.2.12。 。 。 .

这个 0.2.x 路径选择用组件化JS验证的最新 WASI 0.2 适配器 jco使用的版本. 它可能改变任何 jco-std 释放。 使用明确的版本 当您的组件必须保留一个更古老的WIT世界时,路径.

节点.js 兼容 API

[尖叫声] Jco的节点.js 组件的内置兼容性是实验性和主题 改为: API、行为和生成的组件接口可能改变 不相容,没有 铸币大释放.

上表列出了可用的适配器. 通常应用代码 保留它 node: 进口和让 jco componentize 选择执行. 见 节点.js 内置兼容性指南 用于设置、版本、能力和兼容性边界.

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)}`;
}

见 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])); // "🌍"

见 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;
}

见 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) };
}

见 node:tty。 。 。 .

node:wasi

import { WASI } from "node:wasi";

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

见 node:wasi。 。 。 .

节点.js 错误全局

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

见 节点.js 错误全局。 。 。 .

node:child_process

import { execFileSync } from "node:child_process";

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

见 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");
}

见 node:fs。 。 。 .

node:os

import os from "node:os";

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

见 node:os。 。 。 .

node:dns

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

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

见 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);

见 node:net。 。 。 .

node:http 财务报告和审定财务报表 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());

见 node:http 财务报告和审定财务报表 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();

见 node:http2。 。 。 .

node:timers

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

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

见 node:timers。 。 。 .

许可证

这个项目根据Apache 2.0许可证获得许可,LLVM例外. 见 自由主义 更多细节.

捐款

除非您另有明确声明,否则有意提交的任何捐款 根据Apache-2.0许可证的定义, 应照此办理,不附加任何条件.

版本与发布记录

@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 是什么?

与JS WebAssembly组件共享功能库

如何安装 @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 和提交记录判断。