`check:design-system`이 잡지 못하는 길이 다섯 남았다(1101/12-03, 지금 위반
없음). gradient의 색상각 보간(`linear-gradient(in oklch, …)`)은 UI-02가
`color-mix`만 봐서 지난다. TSX 인라인 `color-mix`도 그렇다. 기능 폴더의 CSS는
아예 읽지 않는다. style sheet에서 `:root`로 토큰을 다시 정의해도, focus ring을
`outline-offset: 0`으로 그려 UI-01의 대비 계산 밖으로 내보내도 지난다. 그리고
primitive의 `className`·`style`이 범위 없이 열려 있어 화면이 primitive 위에
`style={{ color: "red", padding: 13 }}`을 얹어도 막는 것이 없다(04-14).
고른 방법: UI-02 정규식이 gradient의 색 공간까지 보고 TS·TSX 소스에도 돈다.
토큰 파일 밖 CSS는 `src/` 아래 전부를 읽고, 날 색·토큰 재정의·offset 0
focus ring을 거절한다. 04-14는 결정(2026-11-12, 총괄: 공개 props는 두고
검사를 더한다)대로 TSX `style={{ … }}`의 손 색(키워드·`var()` 말고)과 손
간격·글자·반경·층·그림자 값을 거절한다. `className`·`style`의 범위(배치용)를
`docs/styling/design-tokens.md`에 적고, fe-design-system 스킬의 「검사가 안
보는 것」 문장을 새 범위에 맞췄다. 거절 fixture `raw-inline-style.tsx`를
더했다. 버린 대안: primitive 공개 props에서 `style`을 빼기(배럴 표면 BREAKING).
위험·한계: 다운스트림이 기능 CSS나 인라인 style에 날 값을 두었으면 다음
동기화에서 그 줄이 이름과 함께 실패한다. 문자열로 조립한 class와 Tailwind
임의 값은 여전히 보지 않는다.
검증: 규칙 단위 시험, check-design-system 연결 시험(기능 폴더 probe CSS),
`check:design-system:fixture`(FE-GATE-029)는 desktop에서 돌려 PR 본문에 적는다.
Refs: 1101/12-03, 1112/04-14
224 lines
7.5 KiB
TypeScript
224 lines
7.5 KiB
TypeScript
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
|
import { designSystemReportArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
REQUIRED_PRIMITIVE_TOKENS,
|
|
REQUIRED_SEMANTIC_TOKENS,
|
|
SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER,
|
|
} from "../src/presentation/design-system/tokens/token-contract.ts";
|
|
import {
|
|
firstFontFamilyFailures,
|
|
focusContrastFailures,
|
|
hueMixFailures,
|
|
rawSemanticColourFailures,
|
|
focusOffsetFailures,
|
|
inlineStyleFailures,
|
|
rawStyleValueFailures,
|
|
styleSheetColourFailures,
|
|
tokenRedefinitionFailures,
|
|
undeclaredComponentTokenFailures,
|
|
unreadTokenFailures,
|
|
} from "./lib/design-system-rules.ts";
|
|
import { readCustomProperties } from "./lib/oklch-contrast.ts";
|
|
|
|
const fixtureMode = process.argv.includes("--fixture");
|
|
const failures: string[] = [];
|
|
const tokenFiles = {
|
|
primitive: "src/presentation/design-system/tokens/primitive.css",
|
|
semantic: "src/presentation/design-system/tokens/semantic.css",
|
|
component: "src/presentation/design-system/tokens/component.css",
|
|
};
|
|
const tokenLayers: Array<readonly [string, string, readonly string[]]> = [
|
|
["primitive", tokenFiles.primitive, REQUIRED_PRIMITIVE_TOKENS],
|
|
["semantic", tokenFiles.semantic, REQUIRED_SEMANTIC_TOKENS],
|
|
["component", tokenFiles.component, REQUIRED_COMPONENT_TOKENS],
|
|
];
|
|
|
|
for (const [layer, file, tokens] of tokenLayers) {
|
|
const source = await readFile(file, "utf8");
|
|
for (const token of tokens) {
|
|
if (!source.includes(`${token}:`)) {
|
|
failures.push(`${layer} token is missing: ${token}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every style sheet under src/, not only the ones theme.css imports: a
|
|
// feature's own CSS is a style sheet too (1101/12-03).
|
|
const tokenFileSet = new Set<string>(Object.values(tokenFiles));
|
|
const styleFiles = (await readdir("src", { recursive: true }))
|
|
.filter((file) => file.endsWith(".css"))
|
|
.map((file) => path.join("src", file))
|
|
.filter((file) => !tokenFileSet.has(file))
|
|
.sort();
|
|
const cssSources = await Promise.all(
|
|
[...Object.values(tokenFiles), ...styleFiles].map(
|
|
async (file) => ({ file, source: await readFile(file, "utf8") }),
|
|
),
|
|
);
|
|
const definitions = new Set(
|
|
cssSources.flatMap(({ source }) =>
|
|
[...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1]),
|
|
),
|
|
);
|
|
for (const { file, source } of cssSources) {
|
|
for (const match of source.matchAll(/var\((--[a-z0-9-]+)/g)) {
|
|
if (!definitions.has(match[1])) {
|
|
failures.push(`${file} uses undefined token ${match[1]}`);
|
|
}
|
|
}
|
|
failures.push(...hueMixFailures({ file, source }));
|
|
if (!tokenFileSet.has(file)) {
|
|
failures.push(
|
|
...rawStyleValueFailures({ file, source }),
|
|
...styleSheetColourFailures({ file, source }),
|
|
...focusOffsetFailures({ file, source }),
|
|
);
|
|
}
|
|
}
|
|
const tokenNames = new Set(
|
|
cssSources
|
|
.filter(({ file }) => tokenFileSet.has(file))
|
|
.flatMap(({ source }) => [...source.matchAll(/(--[a-z0-9-]+)\s*:/g)].map((match) => match[1])),
|
|
);
|
|
for (const { file, source } of cssSources) {
|
|
if (!tokenFileSet.has(file)) failures.push(...tokenRedefinitionFailures({ file, source }, tokenNames));
|
|
}
|
|
|
|
const semanticSource = await readFile(tokenFiles.semantic, "utf8");
|
|
failures.push(
|
|
...rawSemanticColourFailures({ file: tokenFiles.semantic, source: semanticSource }),
|
|
);
|
|
const darkSource =
|
|
semanticSource.match(/:root\[data-theme="dark"\]\s*\{([\s\S]*?)\n\}/)?.[1] ??
|
|
"";
|
|
for (const token of [
|
|
"--color-surface",
|
|
"--color-surface-muted",
|
|
"--color-surface-elevated",
|
|
"--color-content",
|
|
"--color-content-muted",
|
|
"--color-content-inverse",
|
|
"--color-border",
|
|
"--color-border-strong",
|
|
"--color-action",
|
|
"--color-action-hover",
|
|
"--color-action-pressed",
|
|
"--color-danger",
|
|
"--color-focus",
|
|
"--color-disabled-content",
|
|
"--color-disabled-surface",
|
|
]) {
|
|
if (!darkSource.includes(`${token}:`)) {
|
|
failures.push(`dark theme token is missing: ${token}`);
|
|
}
|
|
}
|
|
const lightProperties = new Map([
|
|
...readCustomProperties(await readFile(tokenFiles.primitive, "utf8")),
|
|
...readCustomProperties(semanticSource.split(':root[data-theme="dark"]')[0]),
|
|
]);
|
|
const darkProperties = new Map([
|
|
...lightProperties,
|
|
...readCustomProperties(darkSource),
|
|
]);
|
|
// Rule texts and reasons: scripts/lib/design-system-rules.ts.
|
|
failures.push(
|
|
...focusContrastFailures("light", lightProperties),
|
|
...focusContrastFailures("dark", darkProperties),
|
|
...unreadTokenFailures(
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
cssSources.filter(({ file }) => file !== tokenFiles.component),
|
|
),
|
|
...unreadTokenFailures(
|
|
REQUIRED_SEMANTIC_TOKENS.filter(
|
|
(token) => !SEMANTIC_TOKENS_WITHOUT_TEMPLATE_READER.includes(token),
|
|
),
|
|
cssSources.filter(({ file }) => file !== tokenFiles.semantic),
|
|
"semantic",
|
|
),
|
|
...undeclaredComponentTokenFailures(
|
|
{ file: tokenFiles.component, source: await readFile(tokenFiles.component, "utf8") },
|
|
REQUIRED_COMPONENT_TOKENS,
|
|
),
|
|
...firstFontFamilyFailures(
|
|
lightProperties.get("--font-sans") ?? "",
|
|
cssSources,
|
|
PRODUCT_LOADED_FONT_FAMILIES,
|
|
),
|
|
);
|
|
|
|
const componentSource = await readFile(tokenFiles.component, "utf8");
|
|
if (!componentSource.includes("@media (forced-colors: active)")) {
|
|
failures.push("forced-colors token fallback is missing");
|
|
}
|
|
|
|
async function listSourceFiles(directory: string): Promise<string[]> {
|
|
const result: string[] = [];
|
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
const target = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) result.push(...(await listSourceFiles(target)));
|
|
else if (/\.(?:ts|tsx|mts|cts)$/.test(entry.name)) result.push(target);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
const sources = fixtureMode
|
|
? await listSourceFiles("tests/fixtures/design-system/forbidden")
|
|
: await listSourceFiles("src");
|
|
for (const file of sources) {
|
|
const source = await readFile(file, "utf8");
|
|
// Icon vendor and design-system deep imports are graph rules in
|
|
// .dependency-cruiser.json (check:architecture), which also sees relative,
|
|
// dynamic and type imports (12-08, 12-10).
|
|
if (
|
|
/from\s+["'](?:react-aria-components|@radix-ui\/[^"']+)["']/.test(source)
|
|
) {
|
|
failures.push(`direct headless vendor import in ${file}`);
|
|
}
|
|
if (
|
|
!file.includes("src/presentation/design-system/tokens/") &&
|
|
/(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i.test(source)
|
|
) {
|
|
failures.push(`raw palette value in ${file}`);
|
|
}
|
|
failures.push(...hueMixFailures({ file, source }), ...inlineStyleFailures({ file, source }));
|
|
if (
|
|
file.includes("tests/fixtures/design-system/forbidden") &&
|
|
source.includes("TOOLTIP_ONLY_REQUIRED_INFORMATION")
|
|
) {
|
|
failures.push(`tooltip-only required information in ${file}`);
|
|
}
|
|
}
|
|
|
|
const report = designSystemReportArtifactSchema.parse({
|
|
schemaVersion: 1,
|
|
mode: fixtureMode ? "negative-fixture" : "source",
|
|
checkedTokenCount:
|
|
REQUIRED_PRIMITIVE_TOKENS.length +
|
|
REQUIRED_SEMANTIC_TOKENS.length +
|
|
REQUIRED_COMPONENT_TOKENS.length,
|
|
failures,
|
|
passed: failures.length === 0,
|
|
});
|
|
await mkdir("artifacts/quality", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: fixtureMode
|
|
? "artifacts/quality/design-system-fixture.json"
|
|
: "artifacts/quality/design-system.json",
|
|
schema: designSystemReportArtifactSchema,
|
|
value: report,
|
|
});
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(`Design system contract failed:\n${failures.join("\n")}\n`);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Design system contract: ${report.checkedTokenCount} tokens and headless vendor boundary PASS\n`,
|
|
);
|