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

fix(types): explicitly set Vite hooks' this to void #9885

Merged
merged 1 commit into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/vite/src/node/plugin.ts
Expand Up @@ -55,7 +55,10 @@ export interface Plugin extends RollupPlugin {
/**
* Apply the plugin only for serve or build, or on certain conditions.
*/
apply?: 'serve' | 'build' | ((config: UserConfig, env: ConfigEnv) => boolean)
apply?:
| 'serve'
| 'build'
| ((this: void, config: UserConfig, env: ConfigEnv) => boolean)
/**
* Modify vite config before it's resolved. The hook can either mutate the
* passed-in config directly, or return a partial config object that will be
Expand All @@ -66,14 +69,17 @@ export interface Plugin extends RollupPlugin {
*/
config?: ObjectHook<
(
this: void,
config: UserConfig,
env: ConfigEnv
) => UserConfig | null | void | Promise<UserConfig | null | void>
>
/**
* Use this hook to read and store the final resolved vite config.
*/
configResolved?: ObjectHook<(config: ResolvedConfig) => void | Promise<void>>
configResolved?: ObjectHook<
(this: void, config: ResolvedConfig) => void | Promise<void>
>
/**
* Configure the vite server. The hook receives the {@link ViteDevServer}
* instance. This can also be used to store a reference to the server
Expand Down Expand Up @@ -126,6 +132,7 @@ export interface Plugin extends RollupPlugin {
*/
handleHotUpdate?: ObjectHook<
(
this: void,
ctx: HmrContext
) => Array<ModuleNode> | void | Promise<Array<ModuleNode> | void>
>
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/html.ts
Expand Up @@ -846,6 +846,7 @@ export interface IndexHtmlTransformContext {
}

export type IndexHtmlTransformHook = (
this: void,
html: string,
ctx: IndexHtmlTransformContext
) => IndexHtmlTransformResult | void | Promise<IndexHtmlTransformResult | void>
Expand Down
11 changes: 7 additions & 4 deletions packages/vite/src/node/preview.ts
Expand Up @@ -62,10 +62,13 @@ export interface PreviewServer {
printUrls(): void
}

export type PreviewServerHook = (server: {
middlewares: Connect.Server
httpServer: http.Server
}) => (() => void) | void | Promise<(() => void) | void>
export type PreviewServerHook = (
this: void,
server: {
middlewares: Connect.Server
httpServer: http.Server
}
) => (() => void) | void | Promise<(() => void) | void>

/**
* Starts the Vite server in preview mode, to simulate a production deployment
Expand Down
1 change: 1 addition & 0 deletions packages/vite/src/node/server/index.ts
Expand Up @@ -151,6 +151,7 @@ export interface FileSystemServeOptions {
}

export type ServerHook = (
this: void,
server: ViteDevServer
) => (() => void) | void | Promise<(() => void) | void>

Expand Down