Skip to content

refactor!: plugin container API options#5294

Merged
patak-cat merged 1 commit intomainfrom
refactor-plugin-container-methods
Oct 27, 2021
Merged

refactor!: plugin container API options#5294
patak-cat merged 1 commit intomainfrom
refactor-plugin-container-methods

Conversation

@patak-cat
Copy link
Member

Description

This refactor is a complement to #5253

Vite exposes in the JS API through the server, access to the pluginContainer so users can externally call resolveId, transform, and load.

We have discussed this change with most players in the ecosystem and looks like no one is using this API. VitePress, SvelteKit, Astro, vite-plugin-ssr, vite-edge, are on board. So I think that even if this is a breaking change, we can include it in the next minor. These functions are not documented. The only reference is that the pluginContainer is public here https://vitejs.dev/guide/api-javascript.html#vitedevserver.

The current interface is

export interface PluginContainer {
  options: InputOptions
  buildStart(options: InputOptions): Promise<void>
  resolveId(
    id: string,
    importer?: string,
    skip?: Set<Plugin>,
    ssr?: boolean
  ): Promise<PartialResolvedId | null>
  transform(
    code: string,
    id: string,
    inMap?: SourceDescription['map'],
    ssr?: boolean
  ): Promise<SourceDescription | null>
  load(id: string, ssr?: boolean): Promise<LoadResult | null>
  close(): Promise<void>
}

This PR aligns the API with the plugin hooks, so we are able to introduce or deprecate options without breaking changes in the future. I left the names as they currently were in the API.

export interface PluginContainer {
  options: InputOptions
  buildStart(options: InputOptions): Promise<void>
  resolveId(
    id: string,
    importer?: string,
    options?: { skip?: Set<Plugin>, ssr?: boolean }
  ): Promise<PartialResolvedId | null>
  transform(
    code: string,
    id: string,
    options?: { inMap?: SourceDescription['map'], ssr?: boolean }
  ): Promise<SourceDescription | null>
  load(
    id: string, 
    options?: { ssr?: boolean }
  ): Promise<LoadResult | null>
  close(): Promise<void>
}

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@patak-cat patak-cat requested a review from antfu October 14, 2021 11:54
@patak-cat patak-cat added this to the 2.7 milestone Oct 14, 2021
@patak-cat patak-cat added the p2-nice-to-have Not breaking anything but nice to have (priority) label Oct 14, 2021
@patak-cat
Copy link
Member Author

I didn't find a single use case of this API in the ecosystem. So it looks that this PR is safe to merge.

@patak-cat patak-cat merged commit 5143f1a into main Oct 27, 2021
@patak-cat patak-cat deleted the refactor-plugin-container-methods branch October 27, 2021 12:33
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants