vite-plugin-dts
vite-plugin-dts copied to clipboard
Feature: Support ${configDir} template variable in tsconfig.json (added in typescript 5.5)
Description
As a developer using vite-plugin-dts I want to be able to use the ${configDir}
template variable in tsconfig.json (added in typescript 5.5 - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-5.html#the-configdir-template-variable-for-configuration-files ), specially when using a shared tsconfig in monorepo.
In it's current version, vite-plugin-dts is not generating any type defintiion files, when ${configDir} is used in the include
property of tsconfig.json
files.
The repo @ https://github.com/chandu/vite-dts-config-dir-test demonstrates the issue. Clone the repo and then issue the following commands:
pnpm i
pnpm run build
// Prints Dts File Exists: true
pnpm run build-config-dir
// Prints Dts File Exists: false, this script is running the build using the tsconfig that has the ${configDir} reference
Suggested solution
The issue happens to be because the newly introduced configDir
template variable nuances are not used/leveared by the @vue/language-core
package.
Where the configFileSpecs is assigned: https://github.com/microsoft/TypeScript/blob/main/src/compiler/commandLineParser.ts#L2945
Where the updated configFileSpecs is not leveraged: https://github.com/vuejs/language-tools/blob/7d44d8e844ef4f51407e57ce39e5570c9c9b6ece/packages/language-core/lib/utils/ts.ts#L84
Where the createParsedCommandLine
function of @vue/language-core
is called:
https://github.com/qmhc/vite-plugin-dts/blob/main/src/plugin.ts#L261
I am not sure what is the right fix/solution.
One possible way is to modify the @vue/language-core
to also return 'configFileSpecs' populated on the config
object at https://github.com/vuejs/language-tools/blob/7d44d8e844ef4f51407e57ce39e5570c9c9b6ece/packages/language-core/lib/utils/ts.ts#L84 and the propagate that to the vite-plugin-dts
where the include/exclude could be rightly used when calling the createFilter
, ut would span updating more than one package.
or
use the tsconfig file/content to parse the file, get the configFileSpecs
and use the validatedIncludeSpecs
and validatedExcludeSpecs
to create the filter at https://github.com/qmhc/vite-plugin-dts/blob/main/src/plugin.ts#L323
I am sure there could be better solutions, but this is what I could think of with limited insights into the typescript tsconfig parsing.
Alternative
For now, I am passing the resolved/hardcoded include/exlcude as the dts plugin options.
Additional context
No response
Validations
- [X] Read the FAQ.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.