import { readdirSync, readFileSync } from "node:fs"; import path from "node:path"; import { describe, expect, it } from "vitest"; const DESIGN_SYSTEM = "src/presentation/design-system"; function sourceFiles(directory: string): string[] { return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => { const file = path.posix.join(directory, entry.name); if (entry.isDirectory()) return sourceFiles(file); return /\.tsx?$/u.test(entry.name) && !/\.stories\.tsx?$/u.test(entry.name) ? [file] : []; }); } /** * vite.config.ts 가 design-system 모듈을 side effect 없음으로 선언한다(템플릿 1101/08-08). * 그 아래에서는 `import "x"` 처럼 효과만을 위한 import 가 모듈과 같이 빌드에서 사라진다. * 그런 import 가 생기면 선언이 틀린 것이다. */ describe("design-system modules declared free of side effects", () => { it("hold no import kept only for its effect", () => { const files = sourceFiles(DESIGN_SYSTEM); expect(files.length).toBeGreaterThan(0); const effectOnly = files.filter((file) => /^\s*import\s+["'][^"']+["']/mu.test(readFileSync(file, "utf8")), ); expect(effectOnly).toEqual([]); }); });