fix(javascript): analyze first-party sources before dependencies (#9341)

* fix(javascript): analyze first-party sources before dependencies

Every source in one application analysis charges the same parent result
budget, and sources were offered in lexical inventory order. On an Electron
app.asar, node_modules/ sorts before an electron-vite out-*/ directory, so
dependency files spent the budget and every first-party main, preload, and
renderer file had its semantic analysis not started and its application
projection rejected. The summary then reported zero windows, preloads, and
bridges while electron_semantics still said "recovered".

Offer application JavaScript before JavaScript under node_modules; reported
files keep inventory order. Count Electron boundary facts only from files
whose projection was admitted, and report electron_semantics "partial" (with
a limitation naming the count) when an Electron-loading source was not fully
examined or reported.

Fixes #9321

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(javascript): treat limited Electron examination as partial coverage

A static pass can stop early at the Electron wrapper expansion budget or
another resource limit without failing the worker. Such a source carries no
analysis or projection failure, so its retained IPC or bridge facts still
reported electron_semantics "recovered". Read the owned examination status
and count a limited Electron-loading source as incomplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-09 19:42:19 +08:00
1 parent 31b6db72c6
commit 512bcf5cdb
7 files changed
+418 -44

No files matched your search

@@ -97,7 +97,9 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
const selectedFileCount =
fileSet.files.length - (fileSet.source_selection?.unselected_files ?? 0);
let selectedFileIndex = 0;
for (const file of fileSet.files) {
for (const file of fileSet.source_selection === undefined
? javaScriptAnalysisOrder(fileSet.files)
: fileSet.files) {
let analysisStarted = false;
try {
await setImmediate();
@@ -308,12 +310,49 @@ export const analyzeAndAdoptJavaScriptArtifactFiles = async (
);
}
}
restoreInventoryOrder(fileSet.files, state.files);
return {
analysis: finalizeArtifactAnalysis(state, preloadLimitations),
interruption,
};
};
/** A source inside an installed dependency package, not the application. */
const dependencySourcePath = (path: string): boolean =>
path.split("/").slice(0, -1).includes("node_modules");
/**
* Every source in one analysis charges the same parent result budget, so the
* order sources are offered decides which ones keep semantic and application
* facts when that budget runs out. Inventory order is lexical, which lets a
* large `node_modules` tree spend the budget before first-party entrypoints,
* preloads, and Electron windows are examined. Offer application JavaScript
* first and dependency JavaScript last; metadata files keep their position.
*/
export const javaScriptAnalysisOrder = (
files: readonly JavaScriptArtifactFile[],
): JavaScriptArtifactFile[] => {
const application: JavaScriptArtifactFile[] = [];
const dependencies: JavaScriptArtifactFile[] = [];
for (const file of files) {
if (file.kind === "javascript" && dependencySourcePath(file.path))
dependencies.push(file);
else application.push(file);
}
return [...application, ...dependencies];
};
/** Analysis order is an admission policy; reported files keep inventory order. */
const restoreInventoryOrder = (
inventory: readonly JavaScriptArtifactFile[],
analyzed: AnalyzedJavaScriptArtifactFile[],
): void => {
const positions = new Map(inventory.map((file, index) => [file, index]));
const position = ({ file }: AnalyzedJavaScriptArtifactFile): number =>
positions.get(file) ?? inventory.length;
analyzed.sort((left, right) => position(left) - position(right));
};
const finalizeArtifactAnalysis = (
state: MutableArtifactAnalysis,
preloadLimitations: readonly string[],