Skip to content

Commit

Permalink
fix(nuxt): mock hookable methods on nuxt 2 (#23502)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored and manniL committed Dec 11, 2023
1 parent 0fbaf70 commit 7b17f92
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/kit/src/loader/nuxt.ts
Expand Up @@ -54,6 +54,19 @@ export async function loadNuxt (opts: LoadNuxtOptions): Promise<Nuxt> {
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
}

Expand Down

0 comments on commit 7b17f92

Please sign in to comment.