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

Export @vitejs/plugin-legacy options interface #14931

Closed
4 tasks done
IlyaSemenov opened this issue Nov 10, 2023 · 1 comment · Fixed by #14933
Closed
4 tasks done

Export @vitejs/plugin-legacy options interface #14931

IlyaSemenov opened this issue Nov 10, 2023 · 1 comment · Fixed by #14933
Labels
contribution welcome enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) plugin: legacy

Comments

@IlyaSemenov
Copy link
Contributor

IlyaSemenov commented Nov 10, 2023

Description

As a developer building a wrapper library around @vitejs/plugin-legacy (nuxt-vite-legacy), I need to re-export the type @vitejs/plugin-legacy uses to accept user options, because I need to allow a user to configure @vitejs/plugin-legacy through nuxt-vite-legacy.

Currently, @vitejs/plugin-legacy only exports this:

export { cspHashes, viteLegacyPlugin as default, detectPolyfills };

I need it to also export interface Options from packages/plugin-legacy/src/types.ts:

export interface Options {
/**
* default: 'defaults'
*/
targets?: string | string[] | { [key: string]: string }

Without that, I have to copy/paste the type into my project, which is not only sub-optimal but also plain wrong. My library supports @vitejs/plugin-legacy@^4.0 (that is 4.0 and 4.1 at the moment), and the actual version may vary depending on user's project. If I copy/paste the options type from 4.1, this gives false expectations (advertise unsupported renderModernChunks) to users using 4.0, and if I copy/paste the type from 4.0, this will not expose renderModernChunks to users that have upgraded to 4.1.

Suggested solution

In packages/plugin-legacy/src/index.ts we could do:

export type { Options } from "./types"

Alternative

No response

Additional context

If it were the application code, I could derive the type with:

import legacy from "@vitejs/plugin-legacy"
type Options = Exclude<Parameters<typeof legacy>[0], undefined>

However, that only works for the library itself, this doesn't allow to re-export the type for library users.

Validations

@sapphi-red
Copy link
Member

I think we can have it. A PR is welcome.

IlyaSemenov added a commit to IlyaSemenov/vite that referenced this issue Nov 10, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) plugin: legacy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants