Repository navigation
fix(javascript): recognize Electron APIs through renamed bindings - #1391
Conversation
Electron recognition matched callee spellings, so a bundler rename such as
esbuild's `import { ipcMain as ipcMain2 } from "electron"`, or a destructured
`const { contextBridge: bridge } = require("electron")`, hid every IPC
handler, BrowserWindow, contextBridge and utility process behind it.
Resolve each call and construction root lexically to its Electron import or
require origin, and classify the callee under that export's name. Shadowed
locals keep their own meaning.
On Hermes Desktop v0.21.6, whose main process is one esbuild ESM bundle,
recognized main IPC handlers rise from 1 to 204, BrowserWindow constructions
from 0 to 11, and paired renderer transmissions from 1 to 201.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: This fix works for me on Linux. Renamed Electron imports now show up. A real app with no renames came out the same. Your test passes on Node 22, 24 and 26. I tested head Your testI ran
I also put your test file on top of A real appI used a copy of the Beyond All Reason launcher (launcher code MIT; Flathub package GPL-2.0-or-later). It ships plain CommonJS. Every Electron import keeps its own name, so the bug shape is not in it. I ran it on Node 22. The head gave the same graph as 6.3.0. Node ids, summary and stats all match. So there is no regression here. Small fixturesFirst, your own trigger from the PR body. On 6.3.0 it finds 0 main handlers. On the head it finds 1, paired with the Next, a hand-made bundle in the esbuild style. It renames
The traps held. An One extra case worked too. One thing stays the same, as your PR says. A plain local object named I also built a real bundle with rolldown 1.2.12. It kept the Electron names and renamed the locals to Not run
Thanks, marnixpluim. Test setup
🤖 Generated with Claude Code (Opus 5.5) 🦊 |
…aliases fix(javascript): recognize Electron APIs through renamed bindings
|
The binding origin matters more than the bundle’s renamed local, and this change captures that, @marnixpluim. Resolving |
Requested by Marnix · project thread
Summary
REA recognizes Electron APIs by the callee's spelling, such as
ipcMain.handleornew BrowserWindow. Bundlers rename imports when names collide, so a bundled main process callsipcMain2.handle(...)andnew BrowserWindow2(...), and REA reports none of them. This change resolves each call or construction root to its Electron import orrequireorigin and matches the callee under the export's name.No issue is linked. This was found while analyzing the packaged Hermes Desktop v0.21.6 (NousResearch/hermes-agent, MIT), whose main process is one esbuild ESM bundle.
Problem and expected behavior
Smallest trigger, a directory with
package.json({ "name": "app", "main": "main.mjs" }) and:Expected: one main-process handler for
app:read, paired with the preload'sinvoke. On7aa4d768,electron_summary.ipcreportsmain_handlers: 0andunpaired_literal_renderer_transmissions: 1; with this change,main_handlers: 1andpaired_renderer_transmissions: 1. RenamedBrowserWindow,contextBridgeandutilityProcessbindings are missed the same way.Invariant: whether a call is an Electron API depends on where its binding comes from, not on the name a bundler gave it.
Change and scope
classifyParsedJavaScriptElectronBindingsmaps each call ornewroot bound toelectron,electron/main,electron/renderer,electron/commonorelectron/utilityunder another name to its export path. It reads import andrequireorigins directly, including destructuredrequireresults, rather than running general value evaluation, which is costly on large bundles.electronCalleeNamerespells a renamed root as its export before the existing matchers run; roots already spelled as their export are untouched.ipcMain2is not Electron's.Not included: Electron objects passed in as function arguments or re-exported from another module, and channels built from template literals. These need more than local binding origins.
Contract and boundary impact
src/domain/javascript), when static findings are collected.docs/public/product-catalog.json), package, or installation impact: none.Evidence and regression coverage
Tests added or updated:
tests/composition/javascript-applications/electronApplicationAnalysis.test.ts, "maps Electron boundaries through bundler-renamed bindings": an ESM main with renamedBrowserWindow,ipcMain(also viaelectron/main) andutilityProcessimports and a shadowingipcMain2parameter, plus a CommonJS preload destructuring renamedcontextBridgeandipcRenderer. It expects one window, one bridge with two members, two paired handlers, one utility process, and no handler for the shadowed channel.Base reproduction or other evidence: on
7aa4d768the new test finds no window, bridge, handler or utility process. On the Hermes Desktop v0.21.6 Linuxapp.asar, with the member-mutation fix in both runs, since without it the app's React vendor chunk alone has no result after 300 s:electron_summarybrowser_windowsipc.main_handlersipc.paired_renderer_transmissionsipc.unpaired_literal_renderer_transmissionsThe 11 windows and 204 handlers match the bundle's Electron-bound
new BrowserWindowN(...)andipcMainN.handle/on(...)calls one for one. The one window and 13 handlers still missed receiveBrowserWindoworipcMainas a function parameter.User-visible CLI/MCP output (if applicable): the summary changes as in the table; no field is added or removed.
Remaining proof gaps: the cases under Not included.
For evidence-bearing changes:
Validation performed
npx oxfmt --checkon the changed files: all formattednpx oxlinton the changed files: no new warnings;javascriptSemanticAnalysis.tswas already over the line limit and grows from 907 to 974 linesnode scripts/verify-module-boundaries.mjs: passed, 1,313 source filesnpx tsc --noEmit: exit 0npx vitest run tests/composition/javascript-applications/electronApplicationAnalysis.test.ts src/domain/javascript: 38 files, 689 tests passednpm run test:prepare, thennpx vitest run; root, Linux x64, Node 22.22): 6,246 tests passed, 114 skipped, 1 failed. The failure isanalysisSelectorCli.test.ts"rejects missing and conflicting selectors before opening a target": it starts the CLI 12 times, hit its 30 s timeout under the parallel run, and passes alone in 27.6 s. It covers CLI argument parsing, which these changes don't touch.Compatibility, safety, and release
Review checklist
type(scope): outcome.🤖 Generated with Claude Code
https://claude.ai/code/session_01XPY2GmufMNGQKoEgRUx1pd