# @electron/fiddle-core 中文文档

规范地址：https://npmcn.com/package/%40electron/fiddle-core/

版本：2\.2\.2
npm 元数据更新时间：2026-06-29T18:07:57.586Z
中文译文更新时间：2026-11-13T12:01:00.167Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：73.9 kB，22 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=22\.12\.0
- 运行依赖：8 个
- 首次发布：2022-10-06T00:18:12.543Z
- 最新版本发布：2026-06-29T18:07:57.233Z
- 近 30 天下载量：44110（2026-10-14 至 2026-11-12，npm 官方下载统计）
- 已发布版本数：25（近 12 个月 6 个）

## 中文简介

从任何地方跑出小提琴, 任何电子发布

## 安装

```sh
npm install @electron/fiddle-core
```

也可以使用：`pnpm add @electron/fiddle-core`、`yarn add @electron/fiddle-core`、`bun add @electron/fiddle-core`

## README

# @ electron/ 中点

[![Test](https://github.com/electron/fiddle-core/actions/workflows/test.yml/badge.svg)](https://github.com/electron/fiddle-core/actions/workflows/test.yml) [![NPM](https://img.shields.io/npm/v/@electron/fiddle-core.svg?style=flat)](https://npmjs.org/package/@electron/fiddle-core)

从任何地方跑出小提琴, 任何电子发布

## 国 际

```sh
# fiddle-core run ver (gist | repo URL | folder)
# fiddle-core test ver (gist | repo URL | folder)
# fiddle-core bisect ver1 ver2 (gist | repo URL | folder)
#
# Run with Windows MSIX identity (Windows only):
# fiddle-core run:msix ver (gist | repo URL | folder)
# fiddle-core test:msix ver (gist | repo URL | folder)
# fiddle-core start:msix ver (gist | repo URL | folder)
#
# Examples:

$ fiddle-core run 12.0.0 /path/to/fiddle
$ fiddle-core test 12.0.0 642fa8daaebea6044c9079e3f8a46390
$ fiddle-core bisect 8.0.0 13.0.0 https://github.com/my/testcase.git

# Run with Windows MSIX identity (gives Electron a Windows app identity)
$ fiddle-core run:msix 30.0.0 /path/to/fiddle


$ fiddle-core bisect 8.0.0 13.0.0 642fa8daaebea6044c9079e3f8a46390
...
🏁 finished bisecting across 438 versions...
# 219 🟢 passed 11.0.0-nightly.20200611 (test #1)
# 328 🟢 passed 12.0.0-beta.12 (test #2)
# 342 🟢 passed 12.0.0-beta.29 (test #5)
# 346 🟢 passed 12.0.1 (test #7)
# 347 🔴 failed 12.0.2 (test #9)
# 348 🔴 failed 12.0.3 (test #8)
# 349 🔴 failed 12.0.4 (test #6)
# 356 🔴 failed 12.0.11 (test #4)
# 383 🔴 failed 13.0.0-nightly.20210108 (test #3)

🏁 Done bisecting
🟢 passed 12.0.1
🔴 failed 12.0.2
Commits between versions:
↔ https://github.com/electron/electron/compare/v12.0.1...v12.0.2
Done in 28.19s.
```

## API 密码

### 哈罗,世界!

```ts
import { Runner } from '@electron/fiddle-core';

const runner = await Runner.create();
const { status } = await runner.run('13.1.7', '/path/to/fiddle');
console.log(status);
```

### 运行小提琴

```ts
import { Runner } from '@electron/fiddle-core';

const runner = await Runner.create();

// use a specific Electron version to run code from a local folder
const result = await runner.run('13.1.7', '/path/to/fiddle');

// use a specific Electron version to run code from a github gist
const result = await runner.run('14.0.0-beta.17', '642fa8daaebea6044c9079e3f8a46390');

// use a specific Electron version to run code from a git repo
const result = await runner.run('15.0.0-alpha.1', 'https://github.com/my/repo.git');

// use a specific Electron version to run code from iterable filename/content pairs
const files = new Map<string, string>([['main.js', '"use strict";']]);
const result = await runner.run('15.0.0-alpha.1', files);

// bisect a regression test across a range of Electron versions
const result = await runner.bisect('10.0.0', '13.1.7', path_or_gist_or_git_repo);

// run with Windows MSIX identity (Windows only)
// This registers Electron as a sparse MSIX package, giving it a Windows app identity
const result = await runner.run('30.0.0', fiddle, { runWithIdentity: true });

// see also `Runner.spawn()` in Advanced Use
```

### 使用 Windows MSIX 身份运行

在 Windows 上,您可以用一个 [零星的MSIX软件包](https://learn.microsoft.com/en-us/windows/msix/overview) 身份证明 这给了Electron一个Windows应用身份,这是某些Windows特性所需要的.

```ts
import { Runner } from '@electron/fiddle-core';

const runner = await Runner.create();

// Run fiddle with Windows MSIX identity
const result = await runner.run('30.0.0', fiddle, {
  runWithIdentity: true,
});
```

何时 `runWithIdentity` 实值 `true`小提琴手会:

1.  在电子安装目录中生成 AppxManifest.xml
2.  用 Electron 注册为稀有的 MSIX 软件包 `Add-AppxPackage`
3.  通过已注册的别名运行电子

### 管理电子装置

```ts
import { Installer, ProgressObject } from '@electron/fiddle-core';

const installer = new Installer();
installer.on('state-changed', ({version, state}) => {
  console.log(`Version "${version}" state changed: "${state}"`);
});

// download a version of electron
await installer.ensureDownloaded('12.0.15');
// expect(installer.state('12.0.5').toBe('downloaded');

// download a version with callback
const callback = (progress: ProgressObject) => {
  const percent = progress.percent * 100;
  console.log(`Current download progress %: ${percent.toFixed(2)}`);
};
await installer.ensureDownloaded('12.0.15', {
  progressCallback: callback,
});

// download a version with a specific mirror
const npmMirrors = {
  electronMirror: 'https://npmmirror.com/mirrors/electron/',
  electronNightlyMirror: 'https://npmmirror.com/mirrors/electron-nightly/',
},

await installer.ensureDownloaded('12.0.15', {
  mirror: npmMirrors,
});

// remove a download
await installer.remove('12.0.15');
// expect(installer.state('12.0.15').toBe('not-downloaded');

// install a specific version for the runner to use
const exec = await installer.install('11.4.10');

// Installing with callback and custom mirrors
await installer.install('11.4.10', {
  progressCallback: callback,
  mirror: npmMirrors,
});
// expect(installer.state('11.4.10').toBe('installed');
// expect(fs.accessSync(exec, fs.constants.X_OK)).toBe(true);
```

### 版本数

```ts
import { ElectronVersions } from '@electron/fiddle-core';

// - querying specific versions
const elves = await ElectronVersions.create();
// expect(elves.isVersion('12.0.0')).toBe(true);
// expect(elves.isVersion('12.99.99')).toBe(false);
const { versions } = elves;
// expect(versions).find((ver) => ver.version === '12.0.0').not.toBeNull();
// expect(versions[versions.length - 1]).toStrictEqual(elves.latest);

// - supported major versions
const { supportedMajors } = elves;
// expect(supportedMajors.length).toBe(4);

// - querying prerelease branches
const { supportedMajors, prereleaseMajors } = elves;
const newestSupported = Math.max(...supportedMajors);
const oldestPrerelease = Math.min(...prereleaseMajors);
// expect(newestSupported + 1).toBe(oldestPrerelease);

// - get all releases in a range
let range = releases.inRange('12.0.0', '12.0.15');
// expect(range.length).toBe(16);
// expect(range.shift().version).toBe('12.0.0');
// expect(range.pop().version).toBe('12.0.15');

// - get all 10-x-y releases
range = releases.inMajor(10);
// expect(range.length).toBe(101);
// expect(range.shift().version).toBe('10.0.0-nightly.20200209');
// expect(range.pop().version).toBe('10.4.7');
```

## 高级使用

### 进程 。 子孙

```ts
import { Runner } from '@electron/fiddle-core';

// third argument is same as node.spawn()'s opts
const child = await runner.spawn('12.0.1', fiddle, nodeSpawnOpts);

// see also `Runner.run()` and `Runner.bisect()` above
```

### 使用本地结构

```ts
import { Runner } from '@electron/fiddle-core';

const runner = await Runner.create();
const result = await runner.run('/path/to/electron/build', fiddle);
```

### 使用自定义路径

```ts
import { Paths, Runner } from '@electron/fiddle-core';

const paths: Paths = {
  // where to store zipfiles of downloaded electron versions
  electronDownloads: '/tmp/my/electron-downloads',

  // where to install an electron version to be used by the Runner
  electronInstall: '/tmp/my/electron-install',

  // where to save temporary copies of fiddles
  fiddles: '/tmp/my/fiddles',

  // where to save releases fetched from online
  versionsCache: '/tmp/my/releases.json',
});

const runner = await Runner.create({ paths });
```

### 手动创建小提琴对象

跑者会为你做这个工作,但如果你想要更好的控制 在小提琴物体的生命周期里 你可以自己当场批判:

```ts
import { FiddleFactory } from '@electron/fiddle-core';

const factory = new FiddleFactory();

// load a fiddle from a local directory
const fiddle = await factory.from('/path/to/fiddle'));

// ...or from a gist
const fiddle = await factory.from('642fa8daaebea6044c9079e3f8a46390'));

// ...or from a git repo
const fiddle = await factory.from('https://github.com/my/testcase.git'));

// ...or from an iterable of key / value entries
const fiddle = await factory.from([
  ['main.js', '"use strict";'],
]);
```

## 常见问题

### @electron/fiddle-core 是什么？

从任何地方跑出小提琴, 任何电子发布

### 如何安装 @electron/fiddle-core？

在项目目录运行 npm install @electron/fiddle-core，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 fiddle-core，可以用 npx fiddle-core 直接运行。

### @electron/fiddle-core 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/electron\_\_fiddle-core 是否存在。

### @electron/fiddle-core 支持 ESM 还是 CommonJS？

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

### @electron/fiddle-core 需要什么版本的 Node\.js？

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

### @electron/fiddle-core 可以商用吗？

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

### @electron/fiddle-core 的下载量有多少？

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

### @electron/fiddle-core 还在维护吗？

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

