fix(kit): add missing nuxt hooks types (#971)

This commit is contained in:
Xin Du (Clark) 2021-10-18 09:14:22 +01:00 committed by GitHub
parent 90eacb6f75
commit 6cfe98941d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,4 @@
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import type { HookCallback } from 'hookable'
import type { Compiler, Configuration, Stats } from 'webpack' import type { Compiler, Configuration, Stats } from 'webpack'
import type { TSConfig } from 'pkg-types' import type { TSConfig } from 'pkg-types'
import type { NuxtConfig, NuxtOptions } from '..' import type { NuxtConfig, NuxtOptions } from '..'
@ -30,10 +29,11 @@ type RenderResult = {
// https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html // https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html
export type TSReference = { types: string } | { path: string } export type TSReference = { types: string } | { path: string }
export interface NuxtHooks extends Record<string, HookCallback> { export interface NuxtHooks {
// nuxt3 // nuxt3
'app:resolve': (app: NuxtApp) => HookResult 'app:resolve': (app: NuxtApp) => HookResult
'app:templates': (app: NuxtApp) => HookResult 'app:templates': (app: NuxtApp) => HookResult
'app:templatesGenerated': (app: NuxtApp) => HookResult
'builder:generateApp': () => HookResult 'builder:generateApp': () => HookResult
// @nuxt/builder // @nuxt/builder
@ -54,6 +54,7 @@ export interface NuxtHooks extends Record<string, HookCallback> {
// @nuxt/nitro // @nuxt/nitro
'nitro:document': (template: { src: string, contents: string }) => HookResult 'nitro:document': (template: { src: string, contents: string }) => HookResult
'nitro:context': (context: any) => HookResult
// @nuxt/cli // @nuxt/cli
'cli:buildError': (error: unknown) => HookResult 'cli:buildError': (error: unknown) => HookResult
@ -131,6 +132,11 @@ export interface NuxtHooks extends Record<string, HookCallback> {
'export:extendRoutes': ({ routes }: { routes: any[] }) => HookResult 'export:extendRoutes': ({ routes }: { routes: any[] }) => HookResult
'export:routeFailed': ({ route, errors }: { route: any, errors: any[] }) => HookResult 'export:routeFailed': ({ route, errors }: { route: any, errors: any[] }) => HookResult
'export:done': (generator: Generator, { errors }: { errors: any[] }) => HookResult 'export:done': (generator: Generator, { errors }: { errors: any[] }) => HookResult
// vite
'vite:extend': (viteBuildContext: { nuxt: Nuxt, config: any }) => HookResult
'vite:extendConfig': (viteInlineConfig: any, env: { isClient: boolean, isServer: boolean }) => HookResult
'vite:serverCreated': (viteServer: any) => HookResult
} }
export type NuxtHookName = keyof NuxtHooks export type NuxtHookName = keyof NuxtHooks

View File

@ -51,7 +51,7 @@ declare module '@nuxt/kit' {
interface NuxtOptions { interface NuxtOptions {
components: boolean | Options | Options['dirs'] components: boolean | Options | Options['dirs']
} }
interface NuxtOptionsHooks { interface NuxtHooks {
'components:dirs'?: componentsDirHook 'components:dirs'?: componentsDirHook
'components:extend'?: componentsExtendHook 'components:extend'?: componentsExtendHook
components?: { components?: {