fix(release): route 청크를 청크 이름이 아니라 페이지 소스 파일로 찾는다
문제: build manifest 작성과 release 검사 둘은 route 청크를 Vite manifest
`entry.name === moduleId`로 찾았다. 청크 이름이 선언 없이 계약이 되어,
vite.config.ts가 route 청크에 이름을 붙이면(tech-log 방식) 빌드가 이유 없는
`Missing built route chunk: <routeId>`로 멈췄다.
고친 것: `scripts/lib/build-manifest-outputs.ts`의 `findRouteChunk` 하나가 dynamic
entry 중 소스 파일(manifest 키 또는 `src`) 이름이 route runtime의
`moduleId`인 것을 찾는다. 셋(build manifest, verify-release, local release
evidence)이 그것을 쓴다. 새 파일을 두지 않은 것은 release 후보
archive의 검증기 소스 목록(`config/ci/gates.json` member 집합)을 바꾸지
않기 위해서다. 못 찾으면 규칙("moduleId는 그 라우트가 import하는
페이지 파일 이름")을, 둘이면 두 소스 경로를 적는다.
위험·한계: moduleId가 페이지 파일 이름이라는 규약은 그대로다(생성기와
`route-runtime.tsx`가 이미 그렇게 쓴다).
검증: desktop `node scripts/run-vitest.ts run tests/unit/route-chunks.test.ts`
통과(다른 청크 이름, 없음, 중복, 계약 없음, 세 사용처).
Refs: 0929/13-03
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
buildDate,
|
||||
} from "./lib/build-environment.ts";
|
||||
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
||||
import { CANONICAL_VITE_MANIFEST_PATH } from "./lib/build-manifest-outputs.ts";
|
||||
import { CANONICAL_VITE_MANIFEST_PATH, findRouteChunk } from "./lib/build-manifest-outputs.ts";
|
||||
import { runOutputPath } from "./lib/run-isolation.ts";
|
||||
|
||||
assertCiBuildEnvironment(process.env);
|
||||
@@ -68,14 +68,13 @@ const routeChunks: Record<string, string> = {};
|
||||
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
||||
ROUTE_RUNTIME_CONTRACT;
|
||||
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
||||
const runtime = runtimeContracts[definition.routeId];
|
||||
const asset = Object.values(viteManifestObject).find(
|
||||
(entry) => entry.name === runtime?.moduleId && entry.isDynamicEntry,
|
||||
const chunk = findRouteChunk(
|
||||
viteManifestObject,
|
||||
definition.routeId,
|
||||
runtimeContracts[definition.routeId]?.moduleId,
|
||||
);
|
||||
if (!runtime || !asset?.file) {
|
||||
throw new Error(`Missing built route chunk: ${definition.routeId}`);
|
||||
}
|
||||
routeChunks[definition.chunkId] = asset.file;
|
||||
if ("error" in chunk) throw new Error(chunk.error);
|
||||
routeChunks[definition.chunkId] = chunk.file;
|
||||
}
|
||||
const runtimeConfigJsonSchema = z.toJSONSchema(runtimeConfigV2ArtifactSchema);
|
||||
|
||||
|
||||
@@ -186,3 +186,52 @@ export async function verifyBuildManifestOutputs(
|
||||
}
|
||||
return mismatches;
|
||||
}
|
||||
|
||||
/**
|
||||
* 0929/13-03. The built chunk of a route's lazy page, for the build manifest
|
||||
* and the two release checks that compare its `routeChunks`. A route runtime's
|
||||
* `moduleId` is the file name of the page it imports
|
||||
* (`src/presentation/routes/route-runtime.tsx`, a generated feature's
|
||||
* `<id>-route-runtime.ts`), so the chunk is the dynamic entry whose source
|
||||
* file — the Vite manifest key — has that name. The chunk's own `name` used to
|
||||
* be matched instead, so a chunk-naming change in vite.config.ts stopped the
|
||||
* build with a reason-less `Missing built route chunk`.
|
||||
*/
|
||||
export type RouteChunkLookup = Readonly<{ file: string }> | Readonly<{ error: string }>;
|
||||
|
||||
const SOURCE_EXTENSION = /\.(?:tsx|ts|jsx|js)$/u;
|
||||
|
||||
export function findRouteChunk(
|
||||
manifest: Readonly<Record<string, unknown>>,
|
||||
routeId: string,
|
||||
moduleId: string | undefined,
|
||||
): RouteChunkLookup {
|
||||
if (moduleId === undefined) {
|
||||
return { error: `Missing built route chunk: ${routeId} has no route runtime contract (ROUTE_RUNTIME_CONTRACT)` };
|
||||
}
|
||||
const matches: { source: string; file: string }[] = [];
|
||||
for (const [key, entry] of Object.entries(manifest)) {
|
||||
if (!isManifestRecord(entry) || entry["isDynamicEntry"] !== true || typeof entry["file"] !== "string") continue;
|
||||
const source = typeof entry["src"] === "string" ? entry["src"] : key;
|
||||
if (path.posix.basename(source).replace(SOURCE_EXTENSION, "") === moduleId) {
|
||||
matches.push({ source, file: entry["file"] });
|
||||
}
|
||||
}
|
||||
if (matches.length === 1) return { file: matches[0]!.file };
|
||||
if (matches.length === 0) {
|
||||
return {
|
||||
error:
|
||||
`Missing built route chunk: ${routeId}: no lazily imported module in the Vite manifest has the source ` +
|
||||
`file ${moduleId}.tsx (or .ts). A route runtime's moduleId must be the file name of the page it imports.`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
error:
|
||||
`Ambiguous built route chunk: ${routeId}: the lazily imported modules ` +
|
||||
`${matches.map(({ source }) => source).join(", ")} are all named ${moduleId}.`,
|
||||
};
|
||||
}
|
||||
|
||||
function isManifestRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
} from "../contracts/release-artifacts.ts";
|
||||
import {
|
||||
CANONICAL_VITE_MANIFEST_PATH,
|
||||
findRouteChunk,
|
||||
verifyBuildManifestOutputs,
|
||||
} from "./build-manifest-outputs.ts";
|
||||
import { assertMatchesJsonSchema } from "./json-schema.ts";
|
||||
@@ -1255,14 +1256,12 @@ async function verifyReleaseOutputs(
|
||||
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
||||
ROUTE_RUNTIME_CONTRACT;
|
||||
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
||||
const runtime = runtimeContracts[definition.routeId];
|
||||
const viteEntry = Object.values(viteManifest).find(
|
||||
(entry) =>
|
||||
isRecord(entry) &&
|
||||
entry.name === runtime?.moduleId &&
|
||||
entry.isDynamicEntry === true,
|
||||
const chunk = findRouteChunk(
|
||||
viteManifest,
|
||||
definition.routeId,
|
||||
runtimeContracts[definition.routeId]?.moduleId,
|
||||
);
|
||||
const file = isRecord(viteEntry) ? viteEntry.file : null;
|
||||
const file = "error" in chunk ? null : chunk.file;
|
||||
if (
|
||||
typeof file !== "string" ||
|
||||
release.routeChunks[definition.chunkId] !== file ||
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
import { assertMatchesJsonSchema } from "./lib/json-schema.ts";
|
||||
import {
|
||||
CANONICAL_VITE_MANIFEST_PATH,
|
||||
findRouteChunk,
|
||||
verifyBuildManifestOutputs,
|
||||
} from "./lib/build-manifest-outputs.ts";
|
||||
import { verifyReleaseRuntimeCoherence } from "./lib/release-runtime-coherence.ts";
|
||||
@@ -168,12 +169,13 @@ for (const chunkId of actualChunkIds) {
|
||||
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
||||
ROUTE_RUNTIME_CONTRACT;
|
||||
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
||||
const runtime = runtimeContracts[definition.routeId];
|
||||
const viteEntry = Object.values(viteManifestObject).find(
|
||||
(entry) => entry.name === runtime?.moduleId && entry.isDynamicEntry,
|
||||
const viteEntry = findRouteChunk(
|
||||
viteManifestObject,
|
||||
definition.routeId,
|
||||
runtimeContracts[definition.routeId]?.moduleId,
|
||||
);
|
||||
const routeAsset = release.routeChunks[definition.chunkId];
|
||||
if (!runtime || !viteEntry || routeAsset !== viteEntry.file) {
|
||||
if ("error" in viteEntry || routeAsset !== viteEntry.file) {
|
||||
artifactMismatches.push(`routeChunk:mismatch:${definition.chunkId}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { findRouteChunk } from "../../scripts/lib/build-manifest-outputs.ts";
|
||||
|
||||
// 0929/13-03. The route chunk was found by the chunk's `name`, so naming route
|
||||
// chunks in vite.config.ts (the way tech-log did) stopped the build with
|
||||
// `Missing built route chunk: APP_HOME` and no reason. It is found by the
|
||||
// page's source file now, which is what the route runtime's moduleId names.
|
||||
describe("route chunk lookup (0929/13-03)", () => {
|
||||
const manifest = {
|
||||
"index.html": { file: "assets/index-a.js", isEntry: true },
|
||||
"src/presentation/pages/home-page.tsx": {
|
||||
file: "assets/route-home-page-b.js",
|
||||
name: "route-home-page",
|
||||
src: "src/presentation/pages/home-page.tsx",
|
||||
isDynamicEntry: true,
|
||||
},
|
||||
"src/features/order-feature/presentation/order-feature-list-page.tsx": {
|
||||
file: "assets/order-feature-list-page-c.js",
|
||||
name: "order-feature-list-page",
|
||||
isDynamicEntry: true,
|
||||
},
|
||||
"_home-page-shared.js": { file: "assets/home-page-d.js", name: "home-page" },
|
||||
};
|
||||
|
||||
it("finds the chunk by the page's source file even when the chunk has another name", () => {
|
||||
expect(findRouteChunk(manifest, "APP_HOME", "home-page")).toEqual({ file: "assets/route-home-page-b.js" });
|
||||
expect(findRouteChunk(manifest, "ORDER_FEATURE_LIST", "order-feature-list-page")).toEqual({
|
||||
file: "assets/order-feature-list-page-c.js",
|
||||
});
|
||||
});
|
||||
|
||||
it("names the reason and the rule when no lazily imported page has that file name", () => {
|
||||
const lookup = findRouteChunk(manifest, "NOT_FOUND", "not-found-page");
|
||||
expect(lookup).toEqual({
|
||||
error:
|
||||
"Missing built route chunk: NOT_FOUND: no lazily imported module in the Vite manifest has the source " +
|
||||
"file not-found-page.tsx (or .ts). A route runtime's moduleId must be the file name of the page it imports.",
|
||||
});
|
||||
});
|
||||
|
||||
it("refuses two lazily imported pages with the same file name", () => {
|
||||
const lookup = findRouteChunk(
|
||||
{ ...manifest, "src/other/home-page.tsx": { file: "assets/home-page-e.js", isDynamicEntry: true } },
|
||||
"APP_HOME",
|
||||
"home-page",
|
||||
);
|
||||
expect(lookup).toEqual({
|
||||
error:
|
||||
"Ambiguous built route chunk: APP_HOME: the lazily imported modules " +
|
||||
"src/presentation/pages/home-page.tsx, src/other/home-page.tsx are all named home-page.",
|
||||
});
|
||||
});
|
||||
|
||||
it("names a route without a runtime contract", () => {
|
||||
expect(findRouteChunk(manifest, "GHOST", undefined)).toEqual({
|
||||
error: "Missing built route chunk: GHOST has no route runtime contract (ROUTE_RUNTIME_CONTRACT)",
|
||||
});
|
||||
});
|
||||
|
||||
it("is the one lookup the manifest writer and both release checks use", async () => {
|
||||
for (const file of [
|
||||
"scripts/generate-build-manifest.ts",
|
||||
"scripts/verify-release.ts",
|
||||
"scripts/lib/local-release-evidence.ts",
|
||||
]) {
|
||||
const source = await readFile(file, "utf8");
|
||||
expect(source, file).toContain("findRouteChunk(");
|
||||
expect(source, file).not.toMatch(/\.name === runtime\?\.moduleId/u);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user