Skip to content

Fix tsconfig include/exclude glob resolution when tsconfig is not in project root#455

Merged
qmhc merged 2 commits intoqmhc:mainfrom
jdz321:main
Dec 19, 2025
Merged

Fix tsconfig include/exclude glob resolution when tsconfig is not in project root#455
qmhc merged 2 commits intoqmhc:mainfrom
jdz321:main

Conversation

@jdz321
Copy link
Contributor

@jdz321 jdz321 commented Dec 16, 2025

Background

When tsconfigPath points to a tsconfig.json located outside the project root (e.g. tsconfig/tsconfig.app.json), unplugin-dts may fail to collect the right source files. This commonly surfaces as lots of TS2307 (“Cannot find module…”) during type generation, missing declarations, or downstream bundling failures.

The root cause is a base-directory mismatch:

  • TypeScript resolves include / exclude / files patterns relative to the tsconfig file directory.
  • unplugin-dts builds a Rollup-style filter via createFilter(..., { resolve: root }), which resolves globs relative to the plugin root.

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

  • In packages/unplugin-dts/src/core/runtime.ts, adjust computeGlobs() to convert tsconfig-provided patterns from tsconfig-dir relative to root relative before passing them to createFilter.
    • Compute relativeRoot = relative(root, dirname(configPath))
    • For non-absolute patterns, prefix with relativeRoot and normalize the result

Validation

  • Updated examples/vue-vite to use a root solution tsconfig.json with references pointing to tsconfig/tsconfig.app.json (no behavior change intended).
  • Verified:
    • pnpm -C examples/vue-vite build
    • pnpm -C examples/vue-vite tsc
    • pnpm -C packages/unplugin-dts test (Vitest)

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 qmhc merged commit 8df62f1 into qmhc:main Dec 19, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants