From 2ec62617ced873fef97c73a6d7aa1271911ccfd5 Mon Sep 17 00:00:00 2001 From: Shogo Kawahara Date: Mon, 19 Apr 2021 16:33:13 +0900 Subject: [PATCH] feat(types): add declarations for `ModuleContainer` utils (#9164) --- packages/types/config/module.d.ts | 39 +++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/types/config/module.d.ts b/packages/types/config/module.d.ts index fb97c8f1de..c60245b6bf 100644 --- a/packages/types/config/module.d.ts +++ b/packages/types/config/module.d.ts @@ -6,6 +6,8 @@ import { Configuration as WebpackConfiguration } from 'webpack' import { NuxtOptionsLoaders } from './build' +import { NuxtRouteConfig } from './router' +import { NuxtOptionsServerMiddleware } from './server-middleware' import { NuxtOptions } from '.' interface ExtendFunctionContext { @@ -17,10 +19,43 @@ interface ExtendFunctionContext { loaders: NuxtOptionsLoaders } -type ExtendFunction = (config: WebpackConfiguration, ctx: ExtendFunctionContext) => void +export interface ModuleTemplateConfig { + src: string, + fileName?: string + filename?: string + options?: Record + [key: string]: any +} + +export interface ModulePluginTemplateConfig extends ModuleTemplateConfig { + ssr?: boolean + mode?: 'all' | 'client' | 'server' +} + +export interface ModuleTemplateDest { + src: string + dst: string + options?: Record +} + +export type ModuleTemplate = ModuleTemplateConfig | string +export type ModulePluginTemplate = ModulePluginTemplateConfig | string + +type ExtendRoutesFunction = (routes: NuxtRouteConfig[], resolve: (...pathSegments: string[]) => string) => void +type ExtendBuildFunction = (config: WebpackConfiguration, ctx: ExtendFunctionContext) => void interface ModuleThis { - extendBuild(fn: ExtendFunction): void + addTemplate(template: ModuleTemplate): ModuleTemplateDest + addPlugin(template: ModulePluginTemplate): void + addLayout(template: ModuleTemplate, name?: string): void + addErrorLayout (dst: string): void + addServerMiddleware (middleware: NuxtOptionsServerMiddleware): void + extendBuild(fn: ExtendBuildFunction): void + extendRoutes(fn: ExtendRoutesFunction): void + // eslint-disable-next-line no-use-before-define + requireModule (moduleOpts: NuxtOptionsModule, paths?: string[]): Promise + // eslint-disable-next-line no-use-before-define + addModule (moduleOpts: NuxtOptionsModule, paths?: string[]): Promise options: NuxtOptions nuxt: any // TBD [key: string]: any // TBD