feat: improve Plugin option types

This commit is contained in:
patak-dev 2024-05-21 10:39:01 +02:00
parent 63de43a5cd
commit 21225c9fdf
2 changed files with 17 additions and 17 deletions

View File

@ -52,7 +52,13 @@ export type {
DevEnvironmentOptions,
ResolvedDevEnvironmentOptions,
} from './config'
export type { PluginOption } from './plugin'
export type {
EnvironmentPlugin,
Plugin,
EnvironmentPluginOptionArray,
PluginOption,
HookHandler,
} from './plugin'
export type { FilterPattern } from './utils'
export type { CorsOptions, CorsOrigin, CommonServerOptions } from './http'
export type {
@ -96,7 +102,6 @@ export type {
SSROptions,
SSRTarget,
} from './ssr'
export type { EnvironmentPlugin, Plugin, HookHandler } from './plugin'
export type {
Logger,
LogOptions,

View File

@ -310,7 +310,7 @@ export interface Plugin<A = any> extends EnvironmentPlugin<A> {
*/
environmentPlugins?: (
environment: PluginEnvironment,
) => PluginOption[] | undefined
) => EnvironmentPluginOptionArray
/**
* @deprecated
@ -331,23 +331,18 @@ export type PluginWithRequiredHook<K extends keyof Plugin> = Plugin & {
[P in K]: NonNullable<Plugin[P]>
}
export type MaybeEnvironmentPlugin =
| EnvironmentPlugin
| false
| null
| undefined
type Thenable<T> = T | Promise<T>
type FalsyPlugin = false | null | undefined
export type EnvironmentPluginOption =
| MaybeEnvironmentPlugin
| EnvironmentPluginOption[]
| Promise<MaybeEnvironmentPlugin | EnvironmentPluginOption[]>
export type EnvironmentPluginOption = Thenable<
EnvironmentPlugin | FalsyPlugin | EnvironmentPluginOption[]
>
export type MaybePlugin = Plugin | false | null | undefined
export type EnvironmentPluginOptionArray = Thenable<
EnvironmentPluginOption[] | FalsyPlugin
>
export type PluginOption =
| MaybePlugin
| PluginOption[]
| Promise<MaybePlugin | PluginOption[]>
export type PluginOption = Thenable<Plugin | FalsyPlugin | PluginOption[]>
export async function resolveEnvironmentPlugins(
environment: PluginEnvironment,