Skip to content
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

Feature: Support ${configDir} template variable in tsconfig.json (added in typescript 5.5) #346

Open
2 tasks done
chandu opened this issue Jun 29, 2024 · 0 comments
Open
2 tasks done

Comments

@chandu
Copy link

chandu commented Jun 29, 2024

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

  • Read the FAQ.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
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

No branches or pull requests

1 participant