Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from May 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 22 additions & 5 deletions packages/vite/src/vite.ts
@@ -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'
Expand Down Expand Up @@ -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))
danielroe marked this conversation as resolved.
Show resolved Hide resolved

for (const dir of allowDirs) {
allowDirs = allowDirs.filter(d => !d.startsWith(dir) || d === dir)
}

const ctx: ViteBuildContext = {
nuxt,
entry,
Expand Down Expand Up @@ -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,
Expand Down