문제: 초기 JS 측정(scripts/scale/measure-feature-shape-growth.ts)과
VITE_PRODUCT_FEATURES=none 빌드 테스트
(tests/unit/product-feature-selection-build.test.ts)가 임시 폴더에 복사할
빌드 입력 8개를 따로 적는다. vite.config.ts가 새 로컬 파일을 import하면
두 목록이 함께 낡고, 한쪽만 고치면 원인을 말하지 않는 "Could not resolve"로
실패한다(7f9a515, 799ab7f가 두 곳을 같이 고쳤다).
고른 방법: scripts/lib/vite-build-inputs.ts에 VITE_BUILD_INPUTS 하나를 두고
두 파일이 import한다. 측정 스크립트가 테스트 파일을 import하지 않는다.
새 tests/unit/vite-build-inputs.test.ts가 (1) 두 소비자에 자기 목록이
없고 이 모듈을 쓰는지, (2) vite.config.ts가 상대 경로로 닿는 모든 파일이
목록 안에 있는지 본다. (2)는 새 로컬 import를 목록에 넣지 않으면 빌드
전에 그 파일 이름으로 실패한다.
버린 대안: 목록을 vite.config.ts에서 export — 설정 파일을 빌드 도구 밖에서
import하면 플러그인 초기화가 따라온다.
위험·한계: import 그래프는 정규식으로 따라간다. 동적 import나 alias로
읽는 파일은 보지 못한다(지금은 없다). scripts/lib/removal-fixture.ts의
복사 목록은 저장소 전체 사본용이라 목적이 달라 합치지 않았다. 측정
스크립트는 참조 기능과 함께 지워지므로(test:sample-removal), (1)은 있는
소비자만 본다. 템플릿에서 그 파일이 없어지면
tests/unit/feature-shape-growth.test.ts가 import에서 실패한다.
검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/vite-build-inputs.test.ts
tests/unit/product-feature-selection-build.test.ts
tests/unit/feature-shape-growth.test.ts
corepack pnpm ci:gate FE-GATE-020 (참조 기능을 지운 사본의 test:all)
Refs: 1105/15-03
73 lines
2.8 KiB
TypeScript
73 lines
2.8 KiB
TypeScript
import { existsSync, readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
/**
|
|
* 1105/15-03. Two copies of the list of files `vite build` reads from the
|
|
* root (the initial JavaScript measurement and the
|
|
* `VITE_PRODUCT_FEATURES=none` build test) had to change together each time
|
|
* vite.config.ts imported a new local file (7f9a515, 799ab7f), and a missed
|
|
* copy failed with an unexplained "Could not resolve". There is one list
|
|
* now, and it has to cover what vite.config.ts imports.
|
|
*/
|
|
const LIST_MODULE = "scripts/lib/vite-build-inputs.ts";
|
|
// The measurement goes with the reference feature it copies
|
|
// (test:sample-removal), so a project without that feature checks the build
|
|
// test alone. In the template, tests/unit/feature-shape-growth.test.ts
|
|
// imports the measurement and fails if the file is gone.
|
|
const CONSUMERS = [
|
|
"scripts/scale/measure-feature-shape-growth.ts",
|
|
"tests/unit/product-feature-selection-build.test.ts",
|
|
].filter((file) => existsSync(file));
|
|
|
|
const LOCAL_IMPORT =
|
|
/\bfrom\s+["'](\.{1,2}\/[^"']+)["']|\bimport\s+["'](\.{1,2}\/[^"']+)["']/gu;
|
|
|
|
/** Every repository file vite.config.ts reaches through relative imports. */
|
|
function localImportGraph(entry: string): string[] {
|
|
const seen = new Set<string>();
|
|
const pending = [entry];
|
|
while (pending.length > 0) {
|
|
const file = pending.pop()!;
|
|
if (seen.has(file)) continue;
|
|
seen.add(file);
|
|
const source = readFileSync(file, "utf8");
|
|
for (const match of source.matchAll(LOCAL_IMPORT)) {
|
|
const specifier = match[1] ?? match[2]!;
|
|
const resolved = path
|
|
.relative(process.cwd(), path.resolve(path.dirname(file), specifier))
|
|
.split(path.sep)
|
|
.join("/");
|
|
if (existsSync(resolved)) pending.push(resolved);
|
|
}
|
|
}
|
|
return [...seen];
|
|
}
|
|
|
|
describe("vite build inputs (1105/15-03)", () => {
|
|
it("defines the list in one module that both builds import", () => {
|
|
for (const consumer of CONSUMERS) {
|
|
const source = readFileSync(consumer, "utf8");
|
|
expect(source, consumer).not.toMatch(/\bconst BUILD_INPUTS\s*=/u);
|
|
expect(source, consumer).toMatch(/\bVITE_BUILD_INPUTS\b/u);
|
|
expect(source, consumer).toContain("vite-build-inputs.ts");
|
|
}
|
|
});
|
|
|
|
it("covers every local file vite.config.ts imports", async () => {
|
|
// Imported here, not at the top, so the first test still reports the
|
|
// copies when the module is missing.
|
|
const { VITE_BUILD_INPUTS } = await import("../../scripts/lib/vite-build-inputs.ts");
|
|
const covered = (file: string) =>
|
|
VITE_BUILD_INPUTS.some((input) => file === input || file.startsWith(`${input}/`));
|
|
|
|
const missing = localImportGraph("vite.config.ts").filter((file) => !covered(file));
|
|
|
|
expect(
|
|
missing,
|
|
`vite.config.ts reads files ${LIST_MODULE} does not copy; add them there`,
|
|
).toEqual([]);
|
|
});
|
|
});
|