Skip to content

Commit

Permalink
feat(types): add declarations for ModuleContainer utils (#9164)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawahara authored Apr 19, 2021
1 parent 88ea02c commit 2ec6261
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions packages/types/config/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<string, any>
[key: string]: any
}

export interface ModulePluginTemplateConfig extends ModuleTemplateConfig {
ssr?: boolean
mode?: 'all' | 'client' | 'server'
}

export interface ModuleTemplateDest {
src: string
dst: string
options?: Record<string, any>
}

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<any>
// eslint-disable-next-line no-use-before-define
addModule (moduleOpts: NuxtOptionsModule, paths?: string[]): Promise<any>
options: NuxtOptions
nuxt: any // TBD
[key: string]: any // TBD
Expand Down

0 comments on commit 2ec6261

Please sign in to comment.