fix(kit): avoid adding already installed modules to internal _installedModules (#18647)

This commit is contained in:
pooya parsa 2023-01-31 17:44:19 +01:00 committed by GitHub
parent d1a79a95a6
commit 637b88304e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -41,8 +41,7 @@ export function defineNuxtModule<OptionsT extends ModuleOptions> (definition: Mo
if (uniqueKey) { if (uniqueKey) {
nuxt.options._requiredModules = nuxt.options._requiredModules || {} nuxt.options._requiredModules = nuxt.options._requiredModules || {}
if (nuxt.options._requiredModules[uniqueKey]) { if (nuxt.options._requiredModules[uniqueKey]) {
// TODO: Notify user if inline options is provided since will be ignored! return false
return
} }
nuxt.options._requiredModules[uniqueKey] = true nuxt.options._requiredModules[uniqueKey] = true
} }

View File

@ -9,7 +9,10 @@ export async function installModule (moduleToInstall: string | NuxtModule, _inli
const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions) const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions)
// Call module // Call module
await nuxtModule(inlineOptions, nuxt) const res = await nuxtModule(inlineOptions, nuxt)
if (res === false /* setup aborted */) {
return
}
if (typeof moduleToInstall === 'string') { if (typeof moduleToInstall === 'string') {
nuxt.options.build.transpile.push(moduleToInstall) nuxt.options.build.transpile.push(moduleToInstall)

View File

@ -36,8 +36,9 @@ export interface ModuleDefinition<T extends ModuleOptions = ModuleOptions> {
} }
/** Nuxt modules are always a simple function. */ /** Nuxt modules are always a simple function. */
type Awaitable<T> = T | Promise<T>
export interface NuxtModule<T extends ModuleOptions = ModuleOptions> { export interface NuxtModule<T extends ModuleOptions = ModuleOptions> {
(this: void, inlineOptions: T, nuxt: Nuxt): void | Promise<void> (this: void, inlineOptions: T, nuxt: Nuxt): Awaitable<void | false>
getOptions?: (inlineOptions?: T, nuxt?: Nuxt) => Promise<T> getOptions?: (inlineOptions?: T, nuxt?: Nuxt) => Promise<T>
getMeta?: () => Promise<ModuleMeta> getMeta?: () => Promise<ModuleMeta>
} }