# @bytecodealliance/jco-std 中文文档

规范地址：https://npmcn.com/package/%40bytecodealliance/jco-std/

版本：0\.10\.0
npm 元数据更新时间：2026-10-28T12:50:04.876Z
中文译文更新时间：2026-11-08T21:49:23.874Z
软件包许可：\(Apache-2\.0 WITH LLVM-exception\)

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40bytecodealliance/jco-std
原文对照：https://npmcn.com/package/%40bytecodealliance/jco-std/?lang=original
项目主页：https://github.com/bytecodealliance/jco#readme
源码仓库：https://github.com/bytecodealliance/jco

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：3.5 MB，1356 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：9 个
- peer 依赖：@bytecodealliance/preview2-shim ^0\.31\.0
- 首次发布：2025-11-07T09:07:44.384Z
- 最新版本发布：2026-10-28T12:50:04.410Z
- 近 30 天下载量：171058（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：17（近 12 个月 14 个）

## 中文简介

与JS WebAssembly组件共享功能库

## 安装

```sh
npm install @bytecodealliance/jco-std
```

也可以使用：`pnpm add @bytecodealliance/jco-std`、`yarn add @bytecodealliance/jco-std`、`bun add @bytecodealliance/jco-std`

## README

# `@bytecodealliance/jco-std`

这个 [`@bytecodealliance/jco`](https://www.npmjs.com/package/@bytecodealliance/jco) 子项目包含共享功能和 用于在 Javascript 中构建 Web Assembly 组件的可重复使用的库.

[Web大会组件](https://component-model.bytecodealliance.org/) 是使用组件模型的网络大会二进制, 用于互操作的WebAssembly库、应用程序和环境的不断发展的架构.

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

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

# 适配器

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

## HTTP 密码

| 导出 | 说明 |
| --- | --- |
| `http/adapters/hono` | 启用更容易的构建 [浩诺](https://hono.dev/) HTTP 服务器 |

## 节点JS API(实验)

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

| 导出 | 说明 |
| --- | --- |
| `wasi/0.2.x/node/24.x.x/assert` | `node:assert` 适配器, WASI p2 上的节点 24 |
| `wasi/0.2.x/node/24.x.x/console` | `node:console` 宾客适配器,以取代明确的主机能力 |
| `wasi/0.2.x/node/24.x.x/errors` | 节点 24 全球错误构建器和共享编码错误行为 |
| `wasi/0.2.x/node/24.x.x/dns` | `node:dns` 宾客适配器,以取代明确的主机能力 |
| `wasi/0.2.x/node/24.x.x/fs` | `node:fs` 财务报告和审定财务报表 `node:fs/promises` 超过明确的东道方能力 |
| `wasi/0.2.x/node/24.x.x/http` | `node:http` API 有直接的 WASI 套接字 和 WASI HTTP 执行 |
| `wasi/0.2.x/node/24.x.x/http2` | `node:http2` API 有直接和清晰文本 WASI 套接字执行 |
| `wasi/0.2.x/node/24.x.x/https` | `node:https` API 共享 `node:http` 核心和执行 |
| `wasi/0.2.x/node/24.x.x/net` | `node:net` 预览 |
| `wasi/0.2.x/node/24.x.x/net/core` | `node:net` 核心在注入的 WASI 预览 2 套接字 |
| `wasi/0.2.x/node/24.x.x/os` | `node:os` 宾客适配器,以取代明确的主机能力 |
| `wasi/0.2.x/node/24.x.x/path` | `node: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/domain` | `node:domain`,在上游贬值:每个用途 |
| `wasi/0.2.x/node/24.x.x/async-hooks` | `node:async_hooks` 客机适配器,节点 24,仅同步瞄准镜 |
| `wasi/0.2.x/node/24.x.x/diagnostics-channel` | `node:diagnostics_channel` 客机适配器,节点24 |
| `wasi/0.2.x/node/24.x.x/child-process` | `node:child_process` 客机适配器,通过明确的主机能力24号节点 |
| `wasi/0.2.x/node/24.x.x/cluster` | `node:cluster` 客机适配器,通过明确的主机能力24号节点 |
| `wasi/0.2.x/node/24.x.x/events` | `node:events` jco在供应的发射芯上执行入口 |
| `wasi/0.2.x/node/24.x.x/module` | `node:module`,节点24:分类和源地图;拒绝加载 |
| `wasi/0.2.x/node/26.x.x/ffi` | `node: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/node` | Opt-in 主机在运行时间的真实性 `node:ffi`· ; `setSuffix()` 标出后缀 |
| `wasi/0.2.x/node/24.x.x/inspector` | `node:inspector` 客机适配器,通过明确的主机能力24号节点 |
| `wasi/0.2.x/node/24.x.x/inspector/promises` | `node: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/node` | Opt-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/repl` | `node:repl` 横过读行端口;只进行全局评价 |
| `wasi/0.2.x/node/24.x.x/tty` | `node: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/node` | Opt-in 主机在运行时间的真实性 `node:tty` 及其说明 |
| `wasi/0.2.x/node/24.x.x/wasi` | `node: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/node` | Opt-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/node` | Opt-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/node` | Opt-in 主机在运行时间的真实性 `node:console` |
| `wasi/0.2.x/node/24.x.x/dns/promises` | `node: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/node` | Opt-in 主机在运行时间的真实性 `node:dns` |
| `wasi/0.2.x/node/24.x.x/fs/promises` | `node: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/node` | Opt-in 主机在运行时间的真实性 `node:fs` |
| `wasi/0.2.x/node/24.x.x/http/core` | `node:http` 可选择执行部分共享的核心 |
| `wasi/0.2.x/node/24.x.x/http/impl/wasi-sockets` | `node:http` 预览 2 套接字 |
| `wasi/0.2.x/node/24.x.x/http/impl/wasi-http` | `node: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/node` | Opt-in 主机在运行时间的真实性 `node:http` 财务报告和审定财务报表 `node:https` |
| `wasi/0.2.x/node/24.x.x/https/core` | `node:https` 可选择执行部分共享的核心 |
| `wasi/0.2.x/node/24.x.x/os/host` | 拒绝默认主机 `jco:node/os` |
| `wasi/0.2.x/node/24.x.x/os/host/node` | Opt-in 主机在运行时间的真实性 `node:os` |
| `node/path` | 遗产未转换的别名 `wasi/0.2.x/node/24.x.x/path` |

# 快速启动

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

## Http( 通过Hono适配器)

用于 `@bytecodealliance/jco-std` 建楼 [浩诺](https://hono.dev/) webAssembly 的应用程序, 使用该 `@bytecodealliance/jco-std/http/adapters/hono` 导出 :

```ts
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 内置兼容性指南](https://bytecodealliance.github.io/jco/interop/nodejs-builtins.html) 用于设置、版本、能力和兼容性边界.

### `node:path`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/path.html)。 。 。 .

### `node:string_decoder`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/string-decoder.html)。 。 。 .

### `node:repl`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/repl.html)。 。 。 .

### `node:tty`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/tty.html)。 。 。 .

### `node:wasi`

```js
import { WASI } from "node:wasi";

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

见 [`node:wasi`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/wasi.html)。 。 。 .

### 节点.js 错误全局

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

见 [节点.js 错误全局](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/errors.html)。 。 。 .

### `node:child_process`

```js
import { execFileSync } from "node:child_process";

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

见 [`node:child_process`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/child-process.html)。 。 。 .

### `node:fs`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/fs.html)。 。 。 .

### `node:os`

```js
import os from "node:os";

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

见 [`node:os`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/os.html)。 。 。 .

### `node:dns`

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

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

见 [`node:dns`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/dns.html)。 。 。 .

### `node:net`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/net.html)。 。 。 .

### `node:http` 财务报告和审定财务报表 `node:https`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/http.html) 财务报告和审定财务报表 [`node:https`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/https.html)。 。 。 .

### `node:http2`

```js
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`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/http2.html)。 。 。 .

### `node:timers`

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

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

见 [`node:timers`](https://bytecodealliance.github.io/jco/interop/nodejs-builtins/supported-modules/timers.html)。 。 。 .

# 许可证

这个项目根据Apache 2.0许可证获得许可,LLVM例外. 见 [自由主义](https://npmcn.com/package/%40bytecodealliance/jco-std/LICENSE) 更多细节.

### 捐款

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

## 常见问题

### @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 和提交记录判断。

