diff --git a/tests/root-tsconfig.test.ts b/tests/root-tsconfig.test.ts new file mode 100644 index 000000000..c0e532075 --- /dev/null +++ b/tests/root-tsconfig.test.ts @@ -0,0 +1,40 @@ +import path from "node:path"; +import ts from "typescript"; +import { describe, expect, it } from "vite-plus/test"; + +const repoRoot = path.resolve(import.meta.dirname, ".."); +const rootTsconfig = path.join(repoRoot, "tsconfig.json"); + +function loadRootTsconfigFileNames(): string[] { + const config = ts.readConfigFile(rootTsconfig, (fileName) => ts.sys.readFile(fileName)); + if (config.error) { + throw new Error(ts.flattenDiagnosticMessageText(config.error.messageText, "\n")); + } + + const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, repoRoot); + if (parsed.errors.length > 0) { + throw new Error( + parsed.errors + .map((error) => ts.flattenDiagnosticMessageText(error.messageText, "\n")) + .join("\n"), + ); + } + + return parsed.fileNames.map((fileName) => + path.relative(repoRoot, fileName).replaceAll(path.sep, "/"), + ); +} + +describe("root tsconfig scope", () => { + it("keeps independent app files and package build output outside the root project", () => { + const fileNames = loadRootTsconfigFileNames(); + + expect(fileNames).toContain("packages/vinext/src/index.ts"); + expect(fileNames).toContain("tests/root-tsconfig.test.ts"); + expect(fileNames).toContain("vite.config.ts"); + expect(fileNames.some((fileName) => fileName.startsWith("apps/"))).toBe(false); + expect(fileNames.some((fileName) => fileName.startsWith("packages/vinext/dist/"))).toBe(false); + expect(fileNames.some((fileName) => fileName.startsWith(".claude/"))).toBe(false); + expect(fileNames.some((fileName) => fileName.startsWith(".worktrees/"))).toBe(false); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 9c8b4ae82..2879f6869 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,5 +14,13 @@ "vinext/shims/*": ["./packages/vinext/src/shims/*"] } }, + "include": [ + "*.ts", + "*.tsx", + "packages/vinext/src/**/*.ts", + "packages/vinext/src/**/*.tsx", + "tests/**/*.ts", + "tests/**/*.tsx" + ], "exclude": ["node_modules", "dist", "fixtures", "tests/fixtures", "benchmarks", "examples"] }