fix(nuxi): restart nuxt when distDir is unlinked (#19131)

This commit is contained in:
Julien Huang 2023-02-20 11:56:17 +01:00 committed by GitHub
parent b3ce9566a1
commit eaeb4f089d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,6 +66,8 @@ export default defineNuxtCommand({
})
let currentNuxt: Nuxt
let distWatcher: chokidar.FSWatcher
const showURL = () => {
listener.showURL({
// TODO: Normalize URL with trailing slash within schema
@ -82,11 +84,20 @@ export default defineNuxtCommand({
if (currentNuxt) {
await currentNuxt.close()
}
if (distWatcher) {
await distWatcher.close()
}
currentNuxt = await loadNuxt({ rootDir, dev: true, ready: false })
if (!isRestart) {
showURL()
}
distWatcher = chokidar.watch(resolve(currentNuxt.options.buildDir, 'dist'), { ignoreInitial: true, depth: 0 })
distWatcher.on('unlinkDir', () => {
dLoad(true, '.nuxt/dist directory has been removed')
})
// Write manifest and also check if we need cache invalidation
if (!isRestart) {
const previousManifest = await loadNuxtManifest(currentNuxt.options.buildDir)