fix(kit): check if nuxt is restarting before updating templates (#19830)

This commit is contained in:
Daniel Roe 2023-03-23 00:24:18 +00:00 committed by GitHub
parent c6f928d786
commit 824d296c7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@ import { existsSync } from 'node:fs'
import { basename, parse, resolve } from 'pathe'
import hash from 'hash-sum'
import type { NuxtTemplate, ResolvedNuxtTemplate } from '@nuxt/schema'
import { useNuxt } from './context'
import { useNuxt, tryUseNuxt } from './context'
/**
* Renders given template using lodash template during build into the project buildDir
@ -77,6 +77,6 @@ export function normalizeTemplate (template: NuxtTemplate<any> | string): Resolv
*
* You can pass a filter within the options to selectively regenerate a subset of templates.
*/
export function updateTemplates (options?: { filter?: (template: ResolvedNuxtTemplate<any>) => boolean }) {
return useNuxt().hooks.callHook('builder:generateApp', options)
export async function updateTemplates (options?: { filter?: (template: ResolvedNuxtTemplate<any>) => boolean }) {
return await tryUseNuxt()?.hooks.callHook('builder:generateApp', options)
}