From 6cfe98941db77172c0dc14890a86bc7c47b27070 Mon Sep 17 00:00:00 2001 From: "Xin Du (Clark)" Date: Mon, 18 Oct 2021 09:14:22 +0100 Subject: [PATCH] fix(kit): add missing nuxt hooks types (#971) --- packages/kit/src/types/hooks.ts | 10 ++++++++-- packages/nuxt3/src/components/types.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/types/hooks.ts b/packages/kit/src/types/hooks.ts index 4efee1a169..c0f0ffacff 100644 --- a/packages/kit/src/types/hooks.ts +++ b/packages/kit/src/types/hooks.ts @@ -1,5 +1,4 @@ import type { IncomingMessage, ServerResponse } from 'http' -import type { HookCallback } from 'hookable' import type { Compiler, Configuration, Stats } from 'webpack' import type { TSConfig } from 'pkg-types' import type { NuxtConfig, NuxtOptions } from '..' @@ -30,10 +29,11 @@ type RenderResult = { // https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html export type TSReference = { types: string } | { path: string } -export interface NuxtHooks extends Record { +export interface NuxtHooks { // nuxt3 'app:resolve': (app: NuxtApp) => HookResult 'app:templates': (app: NuxtApp) => HookResult + 'app:templatesGenerated': (app: NuxtApp) => HookResult 'builder:generateApp': () => HookResult // @nuxt/builder @@ -54,6 +54,7 @@ export interface NuxtHooks extends Record { // @nuxt/nitro 'nitro:document': (template: { src: string, contents: string }) => HookResult + 'nitro:context': (context: any) => HookResult // @nuxt/cli 'cli:buildError': (error: unknown) => HookResult @@ -131,6 +132,11 @@ export interface NuxtHooks extends Record { 'export:extendRoutes': ({ routes }: { routes: any[] }) => HookResult 'export:routeFailed': ({ route, errors }: { route: any, 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 diff --git a/packages/nuxt3/src/components/types.ts b/packages/nuxt3/src/components/types.ts index 752722583d..3df238ed90 100644 --- a/packages/nuxt3/src/components/types.ts +++ b/packages/nuxt3/src/components/types.ts @@ -51,7 +51,7 @@ declare module '@nuxt/kit' { interface NuxtOptions { components: boolean | Options | Options['dirs'] } - interface NuxtOptionsHooks { + interface NuxtHooks { 'components:dirs'?: componentsDirHook 'components:extend'?: componentsExtendHook components?: {