Skip to content

Commit cfc8de8

Browse files
authored
feat(types): allow rollup plugin to be assigned to plugins option (#176)
1 parent ddf15a0 commit cfc8de8

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/vite/src/node/__tests_dts__/plugin.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* This is a development only file for testing types.
33
*/
4-
import type { Plugin as RollupPlugin } from 'rolldown'
4+
import type { Plugin as RolldownPlugin } from 'rolldown'
55
import type { Equal, ExpectExtends, ExpectTrue } from '@type-challenges/utils'
6-
import type { Plugin, PluginContextExtension } from '../plugin'
6+
import type { Plugin as RollupPlugin } from 'rollup'
7+
import type { Plugin, PluginContextExtension, PluginOption } from '../plugin'
78
import type { ROLLUP_HOOKS } from '../constants'
89
import type {
910
GetHookContextMap,
@@ -26,13 +27,18 @@ type HooksMissingInConstants = Exclude<
2627

2728
export type cases = [
2829
// Ensure environment plugin hooks are superset of rollup plugin hooks
29-
ExpectTrue<ExpectExtends<RollupPlugin, Plugin>>,
30+
ExpectTrue<ExpectExtends<RolldownPlugin, Plugin>>,
3031

3132
// Ensure all Rollup hooks have Vite's plugin context extension
3233
ExpectTrue<Equal<HooksMissingExtension, never>>,
3334

3435
// Ensure the `ROLLUP_HOOKS` constant is up-to-date
3536
ExpectTrue<Equal<HooksMissingInConstants, never>>,
37+
38+
// Ensure all Vite plugins, Rolldown plugins, and Rollup plugins can be assigned to `plugins` option
39+
ExpectTrue<ExpectExtends<PluginOption, RolldownPlugin>>,
40+
ExpectTrue<ExpectExtends<PluginOption, RollupPlugin>>,
41+
ExpectTrue<ExpectExtends<PluginOption, Plugin>>,
3642
]
3743

3844
export {}

packages/vite/src/node/plugin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ type Thenable<T> = T | Promise<T>
344344

345345
export type FalsyPlugin = false | null | undefined
346346

347-
export type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>
347+
export type PluginOption = Thenable<
348+
| Plugin
349+
| { name: string } // for rollup plugin compatibility
350+
| FalsyPlugin
351+
| PluginOption[]
352+
>
348353

349354
export async function resolveEnvironmentPlugins(
350355
environment: PartialEnvironment,

0 commit comments

Comments
 (0)