baoyu-electron-extract
Extracts resources and JavaScript from any installed Electron app (`.asar` bundle), restoring original sources from `.js.map` files when available or formatting minified code with Prettier otherwise. Use when user wants to "extract Electron app", "decompile Electron", "get the source code of <app>", "inspect app.asar", "看 Electron 应用源码", "提取 .asar", or asks how a desktop Electron app is built. Skips `node_modules` and supports both macOS and Windows.
1How It Works & Mechanism
Unpacking is not implemented in-house; instead, it dynamically fetches the third-party package @electron/asar via npx at runtime to extract files. Arguments are passed as an array to spawn without shell string concatenation.
const args = ["-y", "@electron/asar", "extract", asarPath, dest];
Restoring the original source tree requires .js.map files to embed sourcesContent; if this condition is not met, it falls back to formatting minified code with Prettier—this defines the actual boundary of its claimed 'decompile' capability.
only works when the `.js.map` embeds `sourcesContent`
JS/CSS files without usable source maps are batch-formatted in place using npx prettier --write to make minified code readable.
const args = ["-y", "prettier", "--write", ...batch];
Cross-platform app discovery: macOS enumerates /Applications and ~/Applications, while Windows traverses roots such as LOCALAPPDATA and PROGRAMFILES; multiple matches trigger an error exit requiring the user to specify an absolute path.
const roots = ["/Applications", join(homedir(), "Applications")];
Hard disk-write guardrails: Refuses to write output to the root directory, directly to the user home, or to the current working directory; existing non-empty output directories require --force to write.
const forbidden = [root, home, cwd];
node_modules and webpack/runtime noise are entirely skipped across unpacking statistics, source-map restoration, and Prettier formatting.
return s.includes("node_modules/") || s.startsWith("webpack/runtime/");
The sources[] in the source-map determines disk write paths; the implementation first resolves against the map's directory and normalizes readable paths under restored/, falling back to hashes only when a path cannot be reduced to a safe path.
Use `restored/__unknown/<hash>.<ext>` only when the source name is empty or cannot be reduced to a safe file path.
Artifacts consist of a file tree and a machine-readable report: defaults to ~/Downloads/<AppName>-electron-extract/, containing extract-report.json (counts, warnings), with support for a single-line summary via --json.
join(outputDir, "extract-report.json"),
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | npx(Node 自带)/ bun |
| package | @electron/asar(运行时 npx 拉取,未锁版本) |
| package | prettier(运行时 npx 拉取,未锁版本) |
| cli | bun(首选运行时;无 bun 时由 npx -y bun 兜底) |
4Recommended Governance & Evidence
- scripts/: Execute local script or command: bun {baseDir}/scripts/main.ts (or npx -y bun …) — invocation method specified in SKILL.md
- 网络端点: Declared external network access: registry.npmjs.org: on first run, npx -y fetches @electron/asar and prettier (no package.json in this directory)
- 本地工作目录: File I/O and artifact output: defaults to ~/Downloads/<AppName>-electron-extract/: extracted/, extracted.unpacked/, r
5Second-Pass Verification
- [ok] 解包委托 @electron/asar(非自研) — main.ts:404 逐字为 `const args = ["-y", "@electron/asar", "extract", asarPath, dest];`,spawn 以 argv 数组调用,无 shell 拼接。
- [ok] npx 拉取未锁版本第三方包(供应链面) — 本目录无 package.json / lockfile,main.ts 内两处 npx 调用分别拉 @electron/asar 与 prettier;SKILL.md Notes 自述 'resolved on-the-fly via `npx -y`',与代码一致。
- [ok] source map 还原能力边界(需内嵌 sourcesContent) — SKILL.md 明写只在 `.js.map` 内嵌 sourcesContent 时可用,未内嵌则跳过并记 warnings;无夸大表述。
- [ok] 写盘护栏(/、home、cwd 拒绝;非空目录需 --force) — main.ts assertSafeOutputDir 用 `const forbidden = [root, home, cwd];`;SKILL.md Safety 段文字与代码一致。
- [ok] 平台支持范围(仅 macOS/Windows 自动发现) — main.ts:310-313 对非 darwin/win32 平台直接抛错要求 --asar;SKILL.md 同述,无夸大。
- [ok] 外部依赖清单是否完整 — 全目录扫描 URL/API/凭证 token 零命中;唯二第三方包为 @electron/asar 与 prettier(均经 npx),运行时 bun/npx 为宿主运行时而非依赖。
- [ok] 元数据(license/stars/commit) — git rev-parse HEAD=1567581c26ec29f4216c6e6835415bf30343b0e3;仓库根 LICENSE 首行 'MIT License'、'Copyright (c) 2026 Jim Liu';GitHub API 返回 MIT / 25926 stars / 2026-09-10T15:13:43Z。
- [discrepancy] 『decompile』措辞与实际能力是否相符 — 出题/触发词里的『decompile Electron』并不等于反编译:实际是解包 + 用构建产物自带的 source map 还原 + Prettier 美化(SKILL.md 自己写明前提是 sourcesContent 存在)。判级与结论不受影响,但详情页应写清这不是字节码/压缩代码的结构化反编译。
6Verdict & Scenarios
3d2a2257d7155c7c…