fix(vite): expand fs.allow dirs to include app files (#20755)

This commit is contained in:
Daniel Roe 2023-05-10 13:45:49 +01:00 committed by GitHub
parent cbcd254cd4
commit 8cca5cc9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { existsSync } from 'node:fs'
import * as vite from 'vite'
import { join, resolve } from 'pathe'
import { dirname, join, resolve } from 'pathe'
import type { Nuxt, ViteConfig } from '@nuxt/schema'
import { addVitePlugin, isIgnored, logger, resolvePath } from '@nuxt/kit'
import replace from '@rollup/plugin-replace'
@ -27,6 +28,25 @@ export async function bundle (nuxt: Nuxt) {
const useAsyncEntry = nuxt.options.experimental.asyncEntry ||
(nuxt.options.vite.devBundler === 'vite-node' && nuxt.options.dev)
const entry = await resolvePath(resolve(nuxt.options.appDir, useAsyncEntry ? 'entry.async' : 'entry'))
let allowDirs = [
nuxt.options.appDir,
nuxt.options.workspaceDir,
...nuxt.options._layers.map(l => l.config.rootDir),
...Object.values(nuxt.apps).flatMap(app => [
...app.components.map(c => dirname(c.filePath)),
...app.plugins.map(p => dirname(p.src)),
...app.middleware.map(m => dirname(m.path)),
...Object.values(app.layouts || {}).map(l => dirname(l.file)),
dirname(nuxt.apps.default.rootComponent!),
dirname(nuxt.apps.default.errorComponent!)
])
].filter(d => d && existsSync(d))
for (const dir of allowDirs) {
allowDirs = allowDirs.filter(d => !d.startsWith(dir) || d === dir)
}
const ctx: ViteBuildContext = {
nuxt,
entry,
@ -88,10 +108,7 @@ export async function bundle (nuxt: Nuxt) {
server: {
watch: { ignored: isIgnored },
fs: {
allow: [
nuxt.options.appDir,
...nuxt.options._layers.map(l => l.config.rootDir)
]
allow: [...new Set(allowDirs)]
}
}
} satisfies ViteConfig,