fix(javascript): trace wrapped Electron IPC paths in large bundles (#1874)

Co-authored-by: David <17119984+fengdwx@users.noreply.github.com>
This commit is contained in:
DavidandDavid authored and GitHub committed 2026-10-12 09:28:59 +08:00
1 parent d93fbda390
commit 87b9793c53
46 files changed
+3213 -355

No files matched your search

@@ -1,4 +1,5 @@
import * as t from "@babel/types";
import { javascriptBootstrapAt } from "./javascriptBootstrap.js";
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
@@ -77,6 +78,61 @@ export const inspectBundlerRegistration = (
);
};
/** Recover standalone Webpack tables whose factories are called by a local loader. */
export const inspectBundlerBootstrap = (
source: string,
call: t.CallExpression,
accumulator: AnalysisAccumulator,
): void => {
const bootstrap = javascriptBootstrapAt(call);
if (bootstrap === undefined) return;
const runtime = `webpack-bootstrap@${String(call.start ?? 0)}`;
const recovered = recoverBundlerModules(
source,
bootstrap.table,
runtime,
accumulator,
);
const entries: string[] = [];
let unknownEntries = 0;
traverseJavaScriptAst(bootstrap.body, {
enter: (node, _parent, ancestors) => {
if (
!t.isCallExpression(node) ||
ancestors().some((node) => t.isFunction(node)) ||
!t.isIdentifier(node.callee, { name: bootstrap.loaderName })
)
return;
const value = argumentValue(node.arguments[0]);
if (value === undefined) unknownEntries++;
else entries.push(value);
},
});
const registration: JavaScriptBundlerRegistration = {
bundler: "webpack",
runtime,
chunk_keys: [`bootstrap@${String(call.start ?? 0)}`],
unknown_chunk_keys: 0,
runtime_require_name: bootstrap.loaderName,
runtime_module_cache_status: "not-observed",
entry_module_keys: uniqueValues(entries).values,
unknown_entry_module_keys: unknownEntries,
async_chunk_keys: recovered.asyncChunkKeys,
unknown_async_chunk_keys: recovered.unknownAsyncChunkKeys,
modules: recovered.modules.sort((left, right) =>
compareUnicodeCodePoints(left.module_key, right.module_key),
),
location: range(call),
};
accumulator.unknownFindings +=
unknownEntries + recovered.unknownAsyncChunkKeys;
addFindingOnce(
accumulator,
`registration\0${registrationKey(registration)}`,
() => accumulator.registrations.push(registration),
);
};
/** Inspect esbuild helper wrappers and recover their literal module tables. */
export const inspectEsbuildWrapper = (
source: string,