mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): mock hookable methods on nuxt 2 (#23502)
This commit is contained in:
parent
770d4c67f7
commit
1e3d989ad9
@ -54,6 +54,19 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
|
|||||||
envConfig: opts.dotenv // TODO: Backward format conversion
|
envConfig: opts.dotenv // TODO: Backward format conversion
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Mock new hookable methods
|
||||||
|
nuxt.removeHook ||= nuxt.clearHook.bind(nuxt)
|
||||||
|
nuxt.removeAllHooks ||= nuxt.clearHooks.bind(nuxt)
|
||||||
|
nuxt.hookOnce ||= (name: string, fn: (...args: any[]) => any, ...hookArgs: any[]) => {
|
||||||
|
const unsub = nuxt.hook(name, (...args: any[]) => {
|
||||||
|
unsub()
|
||||||
|
return fn(...args)
|
||||||
|
}, ...hookArgs)
|
||||||
|
return unsub
|
||||||
|
}
|
||||||
|
// https://github.com/nuxt/nuxt/tree/main/packages/kit/src/module/define.ts#L111-L113
|
||||||
|
nuxt.hooks ||= nuxt
|
||||||
|
|
||||||
return nuxt as Nuxt
|
return nuxt as Nuxt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user