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

Commit

Permalink
fix(nitro): update nitro internal hook name (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 16, 2021
1 parent 4095f96 commit 77e489a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/kit/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface NuxtHooks {
'builder:watch': (event: WatchEvent, path: string) => HookResult

// @nuxt/nitro
'nitro:template': (template: { src: string, contents: string }) => HookResult
'nitro:document': (template: { src: string, contents: string }) => HookResult

// @nuxt/cli
'cli:buildError': (error: unknown) => HookResult
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function build (nitroContext: NitroContext) {
const htmlTemplate = { src: htmlSrc, contents: '', dst: '', compiled: '' }
htmlTemplate.dst = htmlTemplate.src.replace(/.html$/, '.js').replace('app.', 'document.')
htmlTemplate.contents = await readFile(htmlTemplate.src, 'utf-8')
await nitroContext._internal.hooks.callHook('nitro:template:document', htmlTemplate)
await nitroContext._internal.hooks.callHook('nitro:document', htmlTemplate)
htmlTemplate.compiled = 'module.exports = ' + serializeTemplate(htmlTemplate.contents)
await writeFile(htmlTemplate.dst, htmlTemplate.compiled)

Expand Down
6 changes: 3 additions & 3 deletions packages/nitro/src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export default function nuxt2CompatModule () {
// Connect hooks
nuxt.addHooks(nitroContext.nuxtHooks)
nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close'))
nitroContext._internal.hooks.hook('nitro:document', template => nuxt.callHook('nitro:document', template))

nuxt.addHooks(nitroDevContext.nuxtHooks)
nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close'))
nitroDevContext._internal.hooks.hook('nitro:document', template => nuxt.callHook('nitro:document', template))
nitroDevContext._internal.hooks.hook('renderLoading',
(req, res) => nuxt.callHook('server:nuxt:renderLoading', req, res))

nitroContext._internal.hooks.hook('nitro:template', template => nuxt.callHook('nitro:template', template))

// Expose process.env.NITRO_PRESET
nuxt.options.env.NITRO_PRESET = nitroContext.preset

Expand All @@ -54,7 +54,7 @@ export default function nuxt2CompatModule () {
})

// Add missing template variables (which normally renderer would create)
nitroContext._internal.hooks.hook('nitro:template:document', (htmlTemplate) => {
nitroContext._internal.hooks.hook('nitro:document', (htmlTemplate) => {
if (!htmlTemplate.contents.includes('BODY_SCRIPTS_PREPEND')) {
const fullTemplate = ['{{ BODY_SCRIPTS_PREPEND }}', '{{ APP }}', '{{ BODY_SCRIPTS }}'].join('\n ')
htmlTemplate.contents = htmlTemplate.contents.replace('{{ APP }}', fullTemplate)
Expand Down
2 changes: 1 addition & 1 deletion packages/nitro/src/presets/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if ('serviceWorker' in navigator) {
}
},
hooks: {
'nitro:template:document' (tmpl) {
'nitro:document' (tmpl) {
tmpl.compiled = tmpl.compiled.replace('</body>', script + '</body>')
},
async 'nitro:compiled' ({ output }: NitroContext) {
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt3/src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export function initNitro (nuxt: Nuxt) {
// @ts-ignore
nuxt.hooks.addHooks(nitroContext.nuxtHooks)
nuxt.hook('close', () => nitroContext._internal.hooks.callHook('close'))
nitroContext._internal.hooks.hook('nitro:document', template => nuxt.callHook('nitro:document', template))

// @ts-ignore
nuxt.hooks.addHooks(nitroDevContext.nuxtHooks)
nuxt.hook('close', () => nitroDevContext._internal.hooks.callHook('close'))
nitroDevContext._internal.hooks.hook('nitro:document', template => nuxt.callHook('nitro:document', template))

// Add nitro client plugin (to inject $fetch helper)
nuxt.hook('app:resolve', (app) => {
Expand All @@ -26,8 +28,6 @@ export function initNitro (nuxt: Nuxt) {
// Expose process.env.NITRO_PRESET
nuxt.options.env.NITRO_PRESET = nitroContext.preset

nitroContext._internal.hooks.hook('nitro:template', template => nuxt.callHook('nitro:template', template))

// Wait for all modules to be ready
nuxt.hook('modules:done', async () => {
// Extend nitro with modules
Expand Down

0 comments on commit 77e489a

Please sign in to comment.