refactor(architecture): move regex import rules into the import graph (12-10, 12-08)
Icon vendor, design-system deep import and realtime composition were regular expressions beside graph rules, and the regex missed relative deep imports inside presentation. They are graph rules with fixtures now, with the components/ui facades and page-templates named. package-script-graph.ts stays; the reason is recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f8b6a3613c
commit
7f2a1607f3
@@ -831,6 +831,7 @@ async function runGraphFixtureChecks(): Promise<GraphFixtureResult> {
|
||||
cycleGraph,
|
||||
barrelGraph,
|
||||
crossBoundaryGraph,
|
||||
importBoundaryGraph,
|
||||
] = await Promise.all([
|
||||
analyzeSourceGraph(allowedRoot, "src"),
|
||||
analyzeSourceGraph(resolve(fixtureRoot, "unresolved"), "src"),
|
||||
@@ -838,6 +839,7 @@ async function runGraphFixtureChecks(): Promise<GraphFixtureResult> {
|
||||
analyzeSourceGraph(resolve(fixtureRoot, "cycle"), "src"),
|
||||
analyzeSourceGraph(resolve(fixtureRoot, "barrel"), "src"),
|
||||
analyzeSourceGraph(resolve(fixtureRoot, "cross-boundary"), "src"),
|
||||
analyzeSourceGraph(resolve(fixtureRoot, "import-boundaries"), "src"),
|
||||
]);
|
||||
const allowedFiles = new Set(await listFiles(allowedRoot));
|
||||
const allowedSourceFile = resolve(
|
||||
@@ -903,6 +905,39 @@ async function runGraphFixtureChecks(): Promise<GraphFixtureResult> {
|
||||
target === "src/contexts/customer/telemetry.ts",
|
||||
),
|
||||
},
|
||||
// 12-08 / 12-10: these import rules used to be regular expressions in
|
||||
// check-design-system.ts and realtime-boundaries.ts beside the graph.
|
||||
{
|
||||
name: "design-system deep import is rejected",
|
||||
passed: blockingViolations(importBoundaryGraph).some(
|
||||
({ rule, source }) =>
|
||||
rule === "design-system-is-reached-through-its-index" &&
|
||||
source === "src/presentation/pages/deep-import.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "design-system index and named facades are accepted",
|
||||
passed: !blockingViolations(importBoundaryGraph).some(({ source }) =>
|
||||
["src/presentation/pages/public-import.ts", "src/presentation/components/ui/button.ts"].includes(source),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "direct icon vendor import is rejected",
|
||||
passed: blockingViolations(importBoundaryGraph).some(
|
||||
({ rule, source, target }) =>
|
||||
rule === "icon-vendor-is-facade-only" &&
|
||||
source === "src/presentation/pages/direct-icon.ts" &&
|
||||
target === "lucide-react",
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "unselected realtime runtime composition is rejected",
|
||||
passed: blockingViolations(importBoundaryGraph).some(
|
||||
({ rule, source }) =>
|
||||
rule === "unselected-realtime-runtime-is-not-composed" &&
|
||||
source === "src/bootstrap/compose-realtime.ts",
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "deep adapter import from outside the group is rejected",
|
||||
passed: blockingViolations(barrelGraph).some(
|
||||
|
||||
@@ -97,22 +97,14 @@ const sources = fixtureMode
|
||||
: await listSourceFiles("src");
|
||||
for (const file of sources) {
|
||||
const source = await readFile(file, "utf8");
|
||||
const vendorFacade =
|
||||
file === "src/presentation/design-system/icons/vendors/lucide.tsx";
|
||||
if (!vendorFacade && /from\s+["']lucide-react["']/.test(source)) {
|
||||
failures.push(`direct icon vendor import in ${file}`);
|
||||
}
|
||||
// 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/") &&
|
||||
/presentation\/design-system\/(?!index(?:\.tsx?)?["'])/.test(source)
|
||||
) {
|
||||
failures.push(`design-system deep import in ${file}`);
|
||||
}
|
||||
if (
|
||||
!file.includes("src/presentation/design-system/tokens/") &&
|
||||
/(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i.test(source)
|
||||
@@ -151,5 +143,5 @@ if (failures.length > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
process.stdout.write(
|
||||
`Design system contract: ${report.checkedTokenCount} tokens and vendor boundaries PASS\n`,
|
||||
`Design system contract: ${report.checkedTokenCount} tokens and headless vendor boundary PASS\n`,
|
||||
);
|
||||
|
||||
@@ -13,7 +13,6 @@ const forbiddenOutput = `${forbidden.stdout}${forbidden.stderr}`;
|
||||
const expectedRules = [
|
||||
"NATIVE_REALTIME_API_OUTSIDE_ADAPTER",
|
||||
"PRESENTATION_INTERVAL_OWNER",
|
||||
"UNSELECTED_REALTIME_RUNTIME_COMPOSED",
|
||||
] as const;
|
||||
|
||||
if (
|
||||
|
||||
@@ -1054,7 +1054,6 @@ export const realtimeBoundariesArtifactSchema = z
|
||||
ruleId: z.enum([
|
||||
"NATIVE_REALTIME_API_OUTSIDE_ADAPTER",
|
||||
"PRESENTATION_INTERVAL_OWNER",
|
||||
"UNSELECTED_REALTIME_RUNTIME_COMPOSED",
|
||||
]),
|
||||
file: nonEmptyString,
|
||||
line: z.int().positive(),
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/**
|
||||
* Package-script graph for the CI contract (D-12, 12-10). Kept after checking
|
||||
* whether `--ignore-scripts` on the workflow install and `allowBuilds` in
|
||||
* pnpm-workspace.yaml already close the same risks. They do not:
|
||||
*
|
||||
* - Gate commands run installs themselves (`verify:lockfile`, removal
|
||||
* fixtures). `allowBuilds` limits dependency build scripts under pnpm only;
|
||||
* the root project's own install hooks and npm/yarn installs still run
|
||||
* unless the command says `--ignore-scripts`.
|
||||
* - A gate names a root package script. `--prefix`, `--filter`, `-C`, npm
|
||||
* pre/post hooks and `npm_config_*` scope variables can make that name run a
|
||||
* different manifest's script, which no install flag affects.
|
||||
* - `reachablePackageScripts` is also how the ungated-test check (12-04) finds
|
||||
* which Vitest paths a gate runs.
|
||||
*/
|
||||
type PackageManager = "pnpm" | "npm" | "yarn";
|
||||
|
||||
type ManagerParseResult = Readonly<{
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
// Importing the realtime or Web Push adapter from the composition root is the
|
||||
// graph rule unselected-realtime-runtime-is-not-composed (12-10). This scan
|
||||
// keeps what an import graph cannot see: native API calls and timers.
|
||||
export type RealtimeBoundaryRuleId =
|
||||
| "NATIVE_REALTIME_API_OUTSIDE_ADAPTER"
|
||||
| "PRESENTATION_INTERVAL_OWNER"
|
||||
| "UNSELECTED_REALTIME_RUNTIME_COMPOSED";
|
||||
| "PRESENTATION_INTERVAL_OWNER";
|
||||
|
||||
export type RealtimeBoundaryViolation = Readonly<{
|
||||
ruleId: RealtimeBoundaryRuleId;
|
||||
@@ -17,8 +19,6 @@ const OWNED_NATIVE_ROOTS = [
|
||||
"src/adapters/realtime/",
|
||||
"src/adapters/web-push/",
|
||||
] as const;
|
||||
const REALTIME_ADAPTER_IMPORT =
|
||||
/(?:from\s*|import\s*\()\s*["'][^"']*\/adapters\/(?:realtime|web-push)(?:\/[^"']*)?["']/gu;
|
||||
const NATIVE_REALTIME_PATTERNS = [
|
||||
/\bnew\s+(?:WebSocket|EventSource|Notification)\s*\(/gu,
|
||||
/\bNotification\s*\.\s*requestPermission\s*\(/gu,
|
||||
@@ -62,9 +62,6 @@ function inspectFile(
|
||||
const presentationOwned =
|
||||
logicalFile.startsWith("src/presentation/") ||
|
||||
/^src\/features\/[^/]+\/presentation\//u.test(logicalFile);
|
||||
const compositionBoundary =
|
||||
logicalFile.startsWith("src/bootstrap/") ||
|
||||
/^src\/features\/installed-feature-/u.test(logicalFile);
|
||||
|
||||
const report = (
|
||||
ruleId: RealtimeBoundaryRuleId,
|
||||
@@ -92,11 +89,6 @@ function inspectFile(
|
||||
report("PRESENTATION_INTERVAL_OWNER", match.index);
|
||||
}
|
||||
}
|
||||
if (compositionBoundary) {
|
||||
for (const match of source.matchAll(REALTIME_ADAPTER_IMPORT)) {
|
||||
report("UNSELECTED_REALTIME_RUNTIME_COMPOSED", match.index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function collectSourceFiles(
|
||||
|
||||
Reference in New Issue
Block a user