소유자 결정(2026-11-07, design-docs repo-structure/README.md 3.4절)으로 템플릿 샘플을 지운다. 샘플이 맡던 시험 대상은 앞 커밋들이 옮겼다. 참조 기능과 예제 화면, 두 context, 그 시험, e2e 3개, 수동 접근성 기록 7개, 런타임 프로필 키, test:reference-feature(명령, 산출물, 게이트 참조), 커버리지 정책 행을 지웠다. removable-template-features 목록은 비우고 장치는 남겼다: test:sample-removal은 인자가 없으면 목록을 하나씩 지우고, 비면 SKIP을 출력하고 보고서에 건너뛴 사례를 남긴다. 기능 스위치 시험과 홈 시작 링크 스위치 시험은 시험 전용 fixture 기능으로 옮겼다. browser soak은 생성 기능을 넣은 빌드에서 돈다. 문서의 샘플 경로를 고쳤다. 날짜가 붙은 설계·리뷰 기록의 본문은 그대로 두었다. 레지스트리 기준선(update:registry-baseline, OWNER DongHyeonka), CI 계약 기준선과 workflow, 초기 JS 기록(194,354B, 17파일, 첫 기능 6,327B, 기능 539B, context 4B)을 다시 받았다. 위험: 레지스트리 행 삭제는 breaking이다. 샘플을 고쳐 쓰는 다운스트림은 수정/삭제 충돌을 만난다. 성능 lab의 기능 라우트 측정은 템플릿에 공개 기능 라우트가 없어 measured:false다. TEMPLATE_FIXTURE 출처는 플랫폼 코드에 남았다. 검증(desktop): check:types, lint, check:architecture, check:registries, check:ci, verify:documentation, test:unit, test:component, test:contract, test:integration, test:recipes, test:coverage(Risk coverage PASS 378/378, 문턱 68개), test:e2e 183, test:a11y, test:visual, test:storybook, test:browser-capabilities, test:feature-scaffold PASS(76 checks), test:sample-removal SKIP, build, check:bundle.
127 lines
5.3 KiB
TypeScript
127 lines
5.3 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { cp, mkdtemp, rename, rm } from "node:fs/promises";
|
|
import { existsSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
import { localBuildEnvironment } from "./build-environment.ts";
|
|
import { linkFixtureNodeModules } from "./fixture-node-modules.ts";
|
|
import { REMOVAL_FIXTURE_COPY_TARGETS } from "./removal-fixture.ts";
|
|
|
|
/**
|
|
* 2026-11-07. The template ships no feature. What needs one in a real build
|
|
* runs on the feature `create:feature` writes, added to a copy of the
|
|
* repository: the browser checks that one feature works end to end (route,
|
|
* form, save, a save whose result is lost; tests/e2e/generated-feature.spec.ts
|
|
* and the chunk recovery spec, whose fixture builds take `addGeneratedFeature`
|
|
* as their edit) and the browser soak's failing-backend visits
|
|
* (scripts/scale/browser-soak.ts, `buildWithGeneratedFeature`). A change of
|
|
* the generator's output fails there. The `--keyed` write slice is the widest
|
|
* one the command makes.
|
|
*/
|
|
export const GENERATED_FEATURE_ID = "order-feature";
|
|
|
|
export type GeneratedRoute = Readonly<{
|
|
routeId: string;
|
|
path: string;
|
|
chunkId: string;
|
|
/** The lazy page's module id (`routeRuntimeContracts`), the name of its chunk. */
|
|
moduleId: string;
|
|
}>;
|
|
|
|
export type GeneratedFeature = Readonly<{
|
|
list: GeneratedRoute;
|
|
detail: GeneratedRoute;
|
|
create: GeneratedRoute;
|
|
/** The feature's ko-KR and en-US catalogs. */
|
|
messages: Readonly<Record<"ko-KR" | "en-US", Readonly<Record<string, string>>>>;
|
|
/** The collection the operations call: API_BASE_URL of the build plus the path. */
|
|
api: string;
|
|
}>;
|
|
|
|
function node(root: string, args: readonly string[]): string {
|
|
const result = spawnSync(process.execPath, args, { cwd: root, encoding: "utf8" });
|
|
if (result.status !== 0) {
|
|
throw new Error(`node ${args.join(" ")} failed in ${root}:\n${result.stdout}\n${result.stderr}`);
|
|
}
|
|
return result.stdout;
|
|
}
|
|
|
|
/** The edit of a fixture build: `corepack pnpm create:feature order-feature --with-create --keyed`. */
|
|
export async function addGeneratedFeature(root: string): Promise<void> {
|
|
node(root, ["scripts/generate-product-feature-index.ts"]);
|
|
node(root, ["scripts/create-feature.ts", GENERATED_FEATURE_ID, "--with-create", "--keyed"]);
|
|
}
|
|
|
|
/**
|
|
* What the specs need to drive the feature, read from the copy the command
|
|
* wrote it into (node runs that TypeScript as it is): the three routes, the
|
|
* words and where its API is.
|
|
*/
|
|
export function generatedFeature(root: string): GeneratedFeature {
|
|
const feature = path.join(root, "src/features", GENERATED_FEATURE_ID);
|
|
const module = (file: string) => JSON.stringify(pathToFileURL(path.join(feature, file)).href);
|
|
const source = `
|
|
const { ORDER_FEATURE_CONTRACT } = await import(${module("contracts/order-feature-contract.ts")});
|
|
const { ORDER_MESSAGE_CATALOGS } = await import(${module("contracts/order-message-catalog.ts")});
|
|
const { ORDER_LIST_ITEMS_CONTRACT } = await import(${module("contracts/order-contract-contribution.ts")});
|
|
const { API_BASE_URL } = JSON.parse(await (await import("node:fs/promises")).readFile("config/runtime/local.json", "utf8"));
|
|
const route = (id) => ({
|
|
routeId: id,
|
|
path: ORDER_FEATURE_CONTRACT.routes[id].path,
|
|
chunkId: ORDER_FEATURE_CONTRACT.routes[id].chunkId,
|
|
moduleId: ORDER_FEATURE_CONTRACT.routeRuntimeContracts[id].moduleId,
|
|
});
|
|
process.stdout.write(JSON.stringify({
|
|
list: route("ORDER_LIST"),
|
|
detail: route("ORDER_DETAIL"),
|
|
create: route("ORDER_CREATE"),
|
|
messages: ORDER_MESSAGE_CATALOGS,
|
|
api: new URL(ORDER_LIST_ITEMS_CONTRACT.contract.pathTemplate.slice(1), API_BASE_URL).href,
|
|
}));
|
|
`;
|
|
return JSON.parse(node(root, ["--input-type=module", "-e", source])) as GeneratedFeature;
|
|
}
|
|
|
|
/** A route's path with its one parameter filled in. */
|
|
export function routePath(route: GeneratedRoute, id?: string): string {
|
|
return id === undefined ? route.path : route.path.replace(/:[A-Za-z][A-Za-z0-9_]*/u, id);
|
|
}
|
|
|
|
/**
|
|
* A production build of a copy of the repository with the generated feature,
|
|
* in the local configuration. `remove` deletes the copy.
|
|
*/
|
|
export async function buildWithGeneratedFeature(prefix: string): Promise<
|
|
Readonly<{ dist: string; feature: GeneratedFeature; remove(): Promise<void> }>
|
|
> {
|
|
const root = await mkdtemp(path.join(tmpdir(), `${prefix}-`));
|
|
const remove = () => rm(root, { recursive: true, force: true });
|
|
try {
|
|
for (const entry of REMOVAL_FIXTURE_COPY_TARGETS) {
|
|
if (!existsSync(entry)) continue;
|
|
await cp(entry, path.join(root, entry), {
|
|
recursive: true,
|
|
filter: (source) => !source.includes(`${path.sep}.generated`),
|
|
});
|
|
}
|
|
await linkFixtureNodeModules(root);
|
|
await addGeneratedFeature(root);
|
|
const build = spawnSync(process.execPath, ["scripts/build-frontend.ts"], {
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
env: localBuildEnvironment(),
|
|
});
|
|
if (build.status !== 0) {
|
|
throw new Error(`scripts/build-frontend.ts failed in ${root}:\n${build.stdout}\n${build.stderr}`);
|
|
}
|
|
const dist = path.join(root, "dist-generated-feature");
|
|
await rename(path.join(root, "dist"), dist);
|
|
return Object.freeze({ dist, feature: generatedFeature(root), remove });
|
|
} catch (error) {
|
|
await remove();
|
|
throw error;
|
|
}
|
|
}
|