Files
clean-architecture-frontend…/scripts/lib/classify-vite-bundle.ts
DongHyeonkaandClaude Opus 5.5 9c8a5f417a fix(bootstrap): show the boot error shell when the app graph fails to evaluate (09-03)
A module that threw while evaluating stopped main.tsx before boot() ran, so the
static loading shell stayed up. The entry now imports the app (boot.tsx)
dynamically and renders the shell on rejection; the shell reads boot messages
without the feature catalog. The preload helper gets its own chunk so lazy
chunks do not import the per-build entry, and the bundle budget counts the
entry's dynamic imports as initial JS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:54:40 +09:00

54 lines
1.7 KiB
TypeScript

type ViteManifestEntry = Readonly<{
file: string;
isEntry?: boolean;
imports?: readonly string[];
dynamicImports?: readonly string[];
}>;
/**
* Static imports of an entry are part of initial JavaScript, and so are the
* chunks the entry itself imports dynamically: main.tsx only imports the
* application graph that way so it can report a graph that fails to evaluate
* (09-03). Every remaining JavaScript output is governed by the lazy-chunk
* budget.
*/
export function classifyViteJavascript(
manifest: Readonly<Record<string, ViteManifestEntry>>,
) {
const initialFiles = new Set<string>();
const visitedKeys = new Set<string>();
const pendingKeys = Object.entries(manifest)
.filter(([, entry]) => entry.isEntry)
.map(([key]) => key);
const missingImports: string[] = [];
while (pendingKeys.length > 0) {
const key = pendingKeys.pop();
if (key === undefined) break;
if (visitedKeys.has(key)) continue;
visitedKeys.add(key);
const entry = manifest[key];
if (!entry) {
missingImports.push(key);
continue;
}
if (entry.file.endsWith(".js")) initialFiles.add(entry.file);
pendingKeys.push(...(entry.imports ?? []));
if (entry.isEntry) pendingKeys.push(...(entry.dynamicImports ?? []));
}
const allJavaScript = new Set(
Object.values(manifest)
.map((entry) => entry.file)
.filter((file) => file.endsWith(".js")),
);
const lazyFiles = [...allJavaScript].filter(
(file) => !initialFiles.has(file),
);
return Object.freeze({
initialFiles: Object.freeze([...initialFiles].sort()),
lazyFiles: Object.freeze(lazyFiles.sort()),
missingImports: Object.freeze(missingImports.sort()),
});
}