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

Expose the RenderedChunk typing for plugin authors to more easily consume #11324

Closed
4 tasks done
Codex- opened this issue Dec 12, 2022 · 2 comments · Fixed by #11511
Closed
4 tasks done

Expose the RenderedChunk typing for plugin authors to more easily consume #11324

Codex- opened this issue Dec 12, 2022 · 2 comments · Fixed by #11511

Comments

@Codex-
Copy link
Contributor

Codex- commented Dec 12, 2022

Description

I've been working on adding some functionality via a plugin to inject generated CSS via JS per file, and have found that the viteMetadata prop on the OutputChunk type (presumably now a RenderedChunk is perfect for leveraging to do this, however it feels a bit dodgy to access it with any.

https://github.com/vitejs/vite/blob/main/packages/vite/src/node/index.ts#L144

declare module 'rollup' {
  export interface RenderedChunk {
    viteMetadata: ChunkMetadata
  }
}

Suggested solution

Is this type meant to be used? Is it stable? Is it meant to be exported already?

Alternative

No response

Additional context

No response

Validations

@bluwy
Copy link
Member

bluwy commented Dec 28, 2022

Yes the viteMetadata API is public so you can use it. We could re-export RenderedChunk but that's only one of Rollup's types and we can get more request to re-export more of Rollup's types, which isn't scalable. You could do something like:

type ToFn<T> = T extends (...args: any[]) => any ? T : never
type RenderedChunk = Parameters<ToFn<Plugin['renderChunk']>>[1]

to access it for now though.

However I noticed another issue with this (which maybe is also the core issue you're mentioning) that is the viteMetadata type is still not exposed this way. I've fixed it at #11511

@Codex-
Copy link
Contributor Author

Codex- commented Dec 28, 2022

Fantastic, thanks for raising that PR, that's exactly what I'm after :)

@github-actions github-actions bot locked and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants