Skip to content

fix(build): exclude config files from production DTS rollup#10358

Open
ma-cote wants to merge 6 commits intoTanStack:mainfrom
ma-cote:fix/exclude-config-files-from-prod-dts
Open

fix(build): exclude config files from production DTS rollup#10358
ma-cote wants to merge 6 commits intoTanStack:mainfrom
ma-cote:fix/exclude-config-files-from-prod-dts

Conversation

@ma-cote
Copy link
Copy Markdown

@ma-cote ma-cote commented Mar 30, 2026

Closes #10294

Summary

  • Add "include": ["src"] and "exclude": ["src/__tests__"] to 16 tsconfig.prod.json files that were missing it
  • Prevents vite.config.ts and tsup.config.ts from being swept into the experimentalDts rollup
  • Fixes @types/node type pollution that overrides DOM's setTimeout return type from number to NodeJS.Timeout for all consumers

Root cause

Commit 67cf8b6 switched from dts: true to experimentalDts: true in scripts/getTsupConfig.js. The experimental DTS bundler respects tsconfig.json's include array, which contains *.config.* for IDE support. Since tsconfig.prod.json didn't override include, build config files leaked into the published types. 4 packages (query-core, react-query, preact-query, solid-query) already had the fix — this PR brings the remaining 16 in line.

Test plan

  • Built @tanstack/react-query-devtools — confirmed _tsup-dts-rollup.d.ts no longer contains import { UserConfig } from 'vite' or import { Options } from 'tsup'

Summary by CodeRabbit

  • Bug Fixes

    • Prevented type pollution in production type definitions by excluding configuration files from build outputs.
  • Chores

    • Standardized production build configs across packages to include source files and exclude test folders.
    • Added a declaration verification step to test workflows and a verification tool that scans built type files for forbidden references.

The `experimentalDts` option in tsup respects the tsconfig `include`
array to determine which files are in scope for DTS generation. Each
package's `tsconfig.json` includes `*.config.*` for IDE support, and
`tsconfig.prod.json` inherited this without overriding it. This caused
`vite.config.ts` and `tsup.config.ts` to be swept into the DTS rollup,
leaking `import { UserConfig } from 'vite'` into published types. Since
vite references `@types/node`, this globally overrides the DOM
`setTimeout` return type from `number` to `NodeJS.Timeout` for all
consumers.

Add `"include": ["src"]` (and `"exclude": ["src/__tests__"]` where
applicable) to all `tsconfig.prod.json` files that were missing it,
matching the pattern already used by query-core, react-query,
preact-query, and solid-query.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Production TypeScript configs across many packages now explicitly include src and exclude src/__tests__; a changeset was added to avoid DTS type pollution; CI/test scripts were extended to run a new DTS verification script that scans built .d.ts files for forbidden references.

Changes

Cohort / File(s) Summary
TypeScript Production Configs
packages/angular-query-experimental/tsconfig.prod.json, packages/angular-query-persist-client/tsconfig.prod.json, packages/eslint-plugin-query/tsconfig.prod.json, packages/preact-query-devtools/tsconfig.prod.json, packages/preact-query-persist-client/tsconfig.prod.json, packages/query-async-storage-persister/tsconfig.prod.json, packages/query-broadcast-client-experimental/tsconfig.prod.json, packages/query-devtools/tsconfig.prod.json, packages/query-persist-client-core/tsconfig.prod.json, packages/query-sync-storage-persister/tsconfig.prod.json, packages/react-query-devtools/tsconfig.prod.json, packages/react-query-next-experimental/tsconfig.prod.json, packages/react-query-persist-client/tsconfig.prod.json, packages/solid-query-devtools/tsconfig.prod.json, packages/solid-query-persist-client/tsconfig.prod.json, packages/vue-query/tsconfig.prod.json
Added top-level include: ["src"] and exclude: ["src/__tests__"] to explicitly restrict production compilation inputs and omit test files.
Changeset
.changeset/fix-dts-type-pollution.md
New changeset (fix(build)) documenting exclusion of config files from DTS rollup to avoid @types/node type pollution.
Package scripts
package.json
Added test:build:dts script (node scripts/verify-dts-imports.ts) and appended && pnpm run test:build:dts to test:pr and test:ci so DTS verification runs in PR/CI flows.
DTS verification script
scripts/verify-dts-imports.ts
New script that globs built declaration files (packages/*/build/**/*.d.ts, packages/*/build/**/*.d.cts), scans lines for forbidden build-tool imports and /// <reference types="node" />, and fails with a detailed report if any matches are found.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant CI as CI / Runner
participant NX as NX tasks
participant Script as verify-dts-imports.ts
participant FS as Built .d.ts files
CI->>NX: run test:pr / test:ci (nx targets)
NX-->>CI: nx targets complete
CI->>Script: pnpm run test:build:dts
Script->>FS: glob packages//build/**/.d.ts, packages//build/**/.d.cts
FS-->>Script: list of .d.ts/.d.cts files
Script->>Script: read files, scan lines for forbidden patterns
alt forbidden patterns found
Script-->>CI: print report + exit 1
else none found
Script-->>CI: print success + exit 0
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through builds and trimmed the mess,

Kept only src and nudged out the rest,
I sniffed each d.ts for naughty lines,
Bounced type-pollution from the vines,
Now CI hums clean — carrots for success. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and accurately summarizes the main change: excluding config files from the production DTS rollup.
Description check ✅ Passed The description covers all required template sections with clear explanations of changes, root cause, and verification steps.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/react-query-next-experimental/tsconfig.prod.json (1)

8-8: Consider adding "exclude": ["src/__tests__"] for consistency.

While this package doesn't currently have a src/__tests__ directory (making the omission functionally harmless), all other packages in this PR include both "include": ["src"] and "exclude": ["src/__tests__"]. Adding the exclude clause would maintain pattern consistency across the monorepo and future-proof the config if tests are added later.

📋 Proposed change for consistency
   },
-  "include": ["src"]
+  "include": ["src"],
+  "exclude": ["src/__tests__"]
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-query-next-experimental/tsconfig.prod.json` at line 8, The
tsconfig.prod.json currently only has "include": ["src"]; add an "exclude":
["src/__tests__"] entry to match other packages and future-proof the config
(update the JSON in tsconfig.prod.json so it contains both the existing
"include" key and a new "exclude": ["src/__tests__"] key).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react-query-next-experimental/tsconfig.prod.json`:
- Line 8: The tsconfig.prod.json currently only has "include": ["src"]; add an
"exclude": ["src/__tests__"] entry to match other packages and future-proof the
config (update the JSON in tsconfig.prod.json so it contains both the existing
"include" key and a new "exclude": ["src/__tests__"] key).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 99366368-c38c-4134-8e96-0a0556c89575

📥 Commits

Reviewing files that changed from the base of the PR and between 7e5fe21 and 2983d9f.

📒 Files selected for processing (16)
  • packages/angular-query-experimental/tsconfig.prod.json
  • packages/angular-query-persist-client/tsconfig.prod.json
  • packages/eslint-plugin-query/tsconfig.prod.json
  • packages/preact-query-devtools/tsconfig.prod.json
  • packages/preact-query-persist-client/tsconfig.prod.json
  • packages/query-async-storage-persister/tsconfig.prod.json
  • packages/query-broadcast-client-experimental/tsconfig.prod.json
  • packages/query-devtools/tsconfig.prod.json
  • packages/query-persist-client-core/tsconfig.prod.json
  • packages/query-sync-storage-persister/tsconfig.prod.json
  • packages/react-query-devtools/tsconfig.prod.json
  • packages/react-query-next-experimental/tsconfig.prod.json
  • packages/react-query-persist-client/tsconfig.prod.json
  • packages/solid-query-devtools/tsconfig.prod.json
  • packages/solid-query-persist-client/tsconfig.prod.json
  • packages/vue-query/tsconfig.prod.json

ma-cote added 2 commits March 30, 2026 14:21
…iles

Adds scripts/verify-dts-imports.ts that scans all published .d.ts files
for forbidden imports from build tools (vite, tsup, vitest) and
`/// <reference types="node" />`. Wired into test:pr and test:ci to
run after the build completes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/verify-dts-imports.ts`:
- Line 13: The script currently continues when the glob search (const files =
await glob([...]) in verify-dts-imports.ts) returns zero results, which yields a
misleading "Verified 0 .d.ts files..." message; update the code to treat zero
matches as a hard failure by checking if files.length === 0 after the glob call,
logging a clear error that no .d.ts/.d.cts files were found (include the glob
patterns or context), and exit the process with a non-zero status (or throw an
error) so CI fails when no declaration files are discovered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 50759ed7-b704-407c-91c4-0db08e3b6c74

📥 Commits

Reviewing files that changed from the base of the PR and between 58feb9e and caad915.

📒 Files selected for processing (2)
  • package.json
  • scripts/verify-dts-imports.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/verify-dts-imports.ts`:
- Around line 51-53: Update the success message in the console.log that
currently reads "Verified ${files.length} .d.ts files — no build tool type leaks
found." to accurately reflect the scanned file types (both .d.ts and .d.cts).
Modify the message in the same module where the console.log is emitted (keeping
the ${files.length} interpolation) to say something like "Verified
${files.length} declaration files (.d.ts and .d.cts) — no build tool type leaks
found." so it matches the scan behavior initiated earlier in the script.
- Around line 11-13: The success console message currently printed after running
the glob (see the files variable populated by
glob(['packages/*/build/**/*.d.ts', 'packages/*/build/**/*.d.cts'])) mentions
only .d.ts files; update that log (the success message near where files.length
is used) to accurately state both file types — e.g., "Verified ${files.length}
.d.ts and .d.cts files — no build tool type leaks found." — reference the files
variable and the glob call to locate the spot to change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a08e432-b04f-44a6-ab34-3ade703df5e4

📥 Commits

Reviewing files that changed from the base of the PR and between caad915 and 84b16af.

📒 Files selected for processing (1)
  • scripts/verify-dts-imports.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment