Fix tsconfig include/exclude glob resolution when tsconfig is not in project root#455
Merged
Fix tsconfig include/exclude glob resolution when tsconfig is not in project root#455
Conversation
TypeScript resolves include/exclude/files patterns relative to the tsconfig file location, but unplugin-dts passes them to createFilter() which resolves globs relative to plugin root. When tsconfig is not in the project root, this mismatch can exclude valid sources and break dts generation. Convert tsconfig globs to root-relative patterns before creating the filter. Update vue-vite example to use a solution tsconfig with references.
qmhc
approved these changes
Dec 19, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When
tsconfigPathpoints to atsconfig.jsonlocated outside the project root (e.g.tsconfig/tsconfig.app.json),unplugin-dtsmay fail to collect the right source files. This commonly surfaces as lots ofTS2307(“Cannot find module…”) during type generation, missing declarations, or downstream bundling failures.The root cause is a base-directory mismatch:
include/exclude/filespatterns relative to the tsconfig file directory.unplugin-dtsbuilds a Rollup-style filter viacreateFilter(..., { resolve: root }), which resolves globs relative to the pluginroot.If we pass tsconfig-relative globs directly into a filter that resolves relative to
root, the filter can exclude valid project files, leading to an incomplete program and broken declaration output.What changed
packages/unplugin-dts/src/core/runtime.ts, adjustcomputeGlobs()to convert tsconfig-provided patterns from tsconfig-dir relative to root relative before passing them tocreateFilter.relativeRoot = relative(root, dirname(configPath))relativeRootand normalize the resultValidation
examples/vue-viteto use a root solutiontsconfig.jsonwithreferencespointing totsconfig/tsconfig.app.json(no behavior change intended).pnpm -C examples/vue-vite buildpnpm -C examples/vue-vite tscpnpm -C packages/unplugin-dts test(Vitest)