Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

refactor(kit)!: remove support for module container #9010

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/7.migration/20.module-authors.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ By using [vue-demi](https://github.com/vueuse/vue-demi) they should be compatibl

## Module Migration

When Nuxt 3 users add your module, a compatible module container layer from `@nuxt/kit` is **automatically injected**, so as long as your code is following the guidelines below, it should continue working as-is.
When Nuxt 3 users add your module, you will not have access to the module container (`this.*`) so you will need to use utilities from `@nuxt/kit` to access the container functionality.

### Test with `@nuxt/bridge`

Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Module
export * from './module/container'
export * from './module/define'
export * from './module/install'

Expand Down
100 changes: 0 additions & 100 deletions packages/kit/src/module/container.ts

This file was deleted.

8 changes: 1 addition & 7 deletions packages/kit/src/module/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@ import type { Nuxt, NuxtModule } from '@nuxt/schema'
import { useNuxt } from '../context'
import { resolveModule, requireModule, importModule } from '../internal/cjs'
import { resolveAlias } from '../resolve'
import { useModuleContainer } from './container'

/** Installs a module on a Nuxt instance. */
export async function installModule (moduleToInstall: string | NuxtModule, _inlineOptions?: any, _nuxt?: Nuxt) {
const nuxt = useNuxt()
const { nuxtModule, inlineOptions } = await normalizeModule(moduleToInstall, _inlineOptions)

// Call module
await nuxtModule.call(
// Provide this context for backwards compatibility with Nuxt 2
useModuleContainer() as any,
inlineOptions,
nuxt
)
await nuxtModule(inlineOptions, nuxt)

nuxt.options._installedModules = nuxt.options._installedModules || []
nuxt.options._installedModules.push({
Expand Down
43 changes: 1 addition & 42 deletions packages/schema/src/types/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NuxtHooks } from './hooks'
import type { Nuxt, NuxtPluginTemplate, NuxtTemplate } from "./nuxt"
import type { Nuxt } from "./nuxt"
import type { NuxtCompatibility } from './compatibility'

export interface ModuleMeta {
Expand Down Expand Up @@ -41,44 +41,3 @@ export interface NuxtModule<T extends ModuleOptions = ModuleOptions> {
getOptions?: (inlineOptions?: T, nuxt?: Nuxt) => Promise<T>
getMeta?: () => Promise<ModuleMeta>
}

/**
* Legacy ModuleContainer for backwards compatibility with Nuxt 2 module format.
*/
export interface ModuleContainer {
nuxt: Nuxt
options: Nuxt['options']

/** @deprecated */
ready(): Promise<any>

/** @deprecated */
addVendor(): void

/** Renders given template using lodash template during build into the project buildDir (`.nuxt`).*/
addTemplate(template: string | NuxtTemplate): NuxtTemplate

/** Registers a custom plugin. */
addPlugin(template: NuxtPluginTemplate): NuxtPluginTemplate

/** Registers a custom layout. If its name is 'error' it will override the default error layout. */
addLayout(tmpl: NuxtTemplate, name: string): any

/** Sets the layout that will render Nuxt errors. It should already have been added via addLayout or addTemplate. */
addErrorLayout(dst: string): void

/** Adds a new server middleware to the end of the server middleware array. */
addServerMiddleware(arg1: any): void

/** Allows extending webpack build config by chaining `options.build.extend` function. */
extendBuild(fn: Function): void

/** Allows extending routes by chaining `options.router.extendRoutes` function. */
extendRoutes(fn: Function): void

/** Registers a module. */
requireModule(installOptions: any, opts: any): Promise<void>

/** Registers a module. */
addModule(installOptions: any, opts: any): Promise<void>
}