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

feat: Add a way to get the TypeScript program instance #326

Open
2 tasks done
maxpatiiuk opened this issue May 3, 2024 · 0 comments
Open
2 tasks done

feat: Add a way to get the TypeScript program instance #326

maxpatiiuk opened this issue May 3, 2024 · 0 comments

Comments

@maxpatiiuk
Copy link

maxpatiiuk commented May 3, 2024

Description

Given that type-checking the codebase with TypeScript is an expensive operation, having to do so twice during the build operation would be wasteful.

The vite-plugin-dts internally creates an instance of TypeScript program, as well as host and service. It would be really great if we could reuse the same instances for other work we may need to do during the build outside the vite-plugin-dts.

For example, custom-elements-manifest accepts TypeScript source files instances (or if you don't provide them, it will create them for you) - being able to provide it the same instances that vite-plugin-dts used would let me speed up the build and ensure more consistency.

Suggested solution

  1. Make vite-plugin-dts expose the program instance it creates internally (host and service would be nice too, but not essential). For example, if we could provide a callback to vite-plugin-dts as a config option, and it would call that callback with TypeScript program instance as an argument, that would be great.

    plugins: [
      vitePluginDts({
        afterTypeScriptProgramCreate: (program) => console.log(program),
      })
    ],
  2. Let us provide the TypeScript program instance to vite-plugin-dts or intercept it's creation so that we can have a reference to it

Alternative

I see that the plugin provides the program instance to the resolvers transform callback. My current hacky workaround is to add one dummy resolver that will get the reference to the program instance.

The other option, that is not ideal, is for me to overwrite vue-tsc's createProgram() method to spy on when vitePluginDts calls it to get a reference to the program. However, this solution would be very fragile.

Additional context

Thank you for the great work on this plugin!

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