# @ethereum-sourcify/compilers 中文文档

规范地址：https://npmcn.com/package/%40ethereum-sourcify/compilers/

版本：1\.4\.0
npm 元数据更新时间：2026-11-03T07:42:04.720Z
中文译文更新时间：2026-11-13T23:40:29.633Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：229 kB，51 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：v26\.10\.0
- 运行依赖：3 个
- 首次发布：2025-03-04T11:38:47.808Z
- 最新版本发布：2026-11-03T07:42:04.503Z
- 近 30 天下载量：24962（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 17 个）

## 中文简介

环绕多个编译器来下载正确的版本并用共同的界面来引用编译.

## 安装

```sh
npm install @ethereum-sourcify/compilers
```

也可以使用：`pnpm add @ethereum-sourcify/compilers`、`yarn add @ethereum-sourcify/compilers`、`bun add @ethereum-sourcify/compilers`

## README

# 编译器

环绕多个编译器来下载正确的版本并用共同的界面来引用编译.

## 安装

```
npm i @ethereum-sourcify/compilers
```

## 使用量

```ts
import {
  SolidityOutput,
  ISolidityCompiler,
  JsonInput,
} from '@ethereum-sourcify/lib-sourcify';
import { useSolidityCompiler } from '@ethereum-sourcify/compilers';

class SolcLocal implements ISolidityCompiler {
  constructor(
    private solcRepoPath: string,
    private solJsonRepoPath: string,
    private timeoutMs?: number,
  ) {}

  async compile(
    version: string,
    solcJsonInput: JsonInput,
    forceEmscripten: boolean = false,
  ): Promise<SolidityOutput> {
    return await useSolidityCompiler(
      this.solcRepoPath,
      this.solJsonRepoPath,
      version,
      solcJsonInput,
      forceEmscripten,
      this.timeoutMs,
    );
  }
}
```

这个 `SolcLocal` 类可以用作 `solidityCompiler` 参数 `SolidityCheckedContract`。 。 。 . Vyper遵循同样的模式.

## 太阳

[太阳](https://github.com/paradigmxyz/solar) 以与Solc相同的标准JSON输入和输出来编译固态. `useSolarCompiler(solarRepoPath, version, solarJsonInput, timeoutMs?)` 取一个相容的 `SOLC_WRAPPER=1 solar --version` 例如,指纹 `0.8.38+commit.e7a91fc7.solar.0.3.0`。该版本命名了“太阳”发行和建造承诺.

-   要发布, 函数下载 `solar-<target>.tar.gz` 从 GitHub 中释放并检查二进制报告请求的承诺.
-   一个不是释放物的建筑,比如 `0.3.0-dev`,来自 Sourcufy hosts 的拷贝,例如"创建 v1. 9.0 捆绑的太阳". 仅为 Linux x64 提供主机复制件 。 文件名是缓存名称, `solar-<target>-v<solar version>+commit.<commit>`。 。 。 .
-   要用另一块,放进去 `solarRepoPath` 以该名称为例 `solar-x86_64-unknown-linux-musl-v0.3.0-dev+commit.d9f23fbe`。 。 。 .

## 编译超时

最后的论点是: `useSolidityCompiler`, (中文(简体) ), `useVyperCompiler`, (中文(简体) ), `useSolarCompiler` 财务报告和审定财务报表 `useFeCompiler` 是一个以毫秒计的可选的墙点超时编译。 当电话响了,它就否认一个错误 `code` 实值 `COMPILER_TIMEOUT` (以 `COMPILER_TIMEOUT_CODE` 从 `@ethereum-sourcify/compilers-types`) (中文(简体) ). 如果省略,则适用45分的默认.

它涵盖了编译器运行的所有三种方式,每种方式都需要不同的机制来阻止:

-   本地语言 `solc`编号 :`vyper`编号 :`solar` 二进制为子进程运行, 使用 `SIGKILL`
-   `fe build` 同步运行通过 `spawnSync`,它本身执行超时
-   soljson (Emscripten) 的构造 `solc` 运行在工人线程中的进程中 —— 没有要杀死的进程, 因此线程被终止

## 常见问题

### @ethereum-sourcify/compilers 是什么？

环绕多个编译器来下载正确的版本并用共同的界面来引用编译\.

### 如何安装 @ethereum-sourcify/compilers？

在项目目录运行 npm install @ethereum-sourcify/compilers，或使用 pnpm add / yarn add / bun add。

### @ethereum-sourcify/compilers 支持 TypeScript 吗？

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

### @ethereum-sourcify/compilers 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @ethereum-sourcify/compilers 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js v26\.10\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @ethereum-sourcify/compilers 可以商用吗？

@ethereum-sourcify/compilers 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @ethereum-sourcify/compilers 的下载量有多少？

根据 npm 官方下载统计，@ethereum-sourcify/compilers 在 2026/10/14 – 2026/11/12 这 30 天内被下载 24,962 次，日均约 832 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @ethereum-sourcify/compilers 还在维护吗？

最新版本 1\.4\.0 发布于 2026/11/03（10 天前）；至今共发布 31 个版本，其中过去 12 个月发布了 17 个；首次发布于 2025/03/04。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

