-
Notifications
You must be signed in to change notification settings - Fork 326
fix: constrain root tsconfig project scope #1273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
|
Comment on lines
+35
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dist entries should already be excluded. you can add .claude, .worktrees, .nextjs-ref, etc. to exclude if you want? otherwise, i'd rather it includes everything in the repo and excludes stuff that isn't part of the repo. there is also no need for a test file for this. |
||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: With an explicit Not a blocker — the extra excludes are harmless as defense-in-depth — but if you want to tidy this up later, the |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description mentions
.refs/as a directory that existed and caused issues during formatting. It's gitignored (or at least not committed), but if someone has it locally,includealready keeps it out. If you wanted to be thorough, you could add a.refs/assertion here too — but it's a truly optional polish since the directory isn't in the repo.