@ethereum-sourcify/compilers

中文文档
1.4.0发布于 2026/11/03MITTypeScriptESM + CJS近 30 天下载 2.5万

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

中文使用文档
文档目录4 节
  1. 安装
  2. 使用量
  3. 太阳
  4. 编译超时

编译器

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

安装

npm i @ethereum-sourcify/compilers

使用量

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遵循同样的模式.

太阳

太阳 以与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 共发布 31 个版本,首次发布于 2025/03/04;过去 12 个月发布了 17 个版本。

版本发布日期距今
1.4.0latest2026/11/0310 天前
1.3.22026/10/2123 天前
1.3.12026/10/051 个月前
1.3.02026/09/012 个月前
1.2.02026/08/202 个月前
1.1.52026/07/064 个月前

关于 @ethereum-sourcify/compilers 的常见问题

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