fix(schema): don't use `app/` as `srcDir` if it doesn't exist (#28176)

This commit is contained in:
Daniel Roe 2024-07-16 15:12:31 +01:00 committed by GitHub
parent eac0734a3b
commit 874829434d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 8 deletions

View File

@ -19,7 +19,7 @@ describe('resolveApp', () => {
{
"components": [],
"configs": [],
"dir": "<rootDir>/app",
"dir": "<rootDir>",
"errorComponent": "<repoRoot>/packages/nuxt/src/app/components/nuxt-error-page.vue",
"extensions": [
".js",

View File

@ -118,15 +118,17 @@ export default defineUntypedSchema({
}
const srcDir = resolve(rootDir, 'app')
if (!existsSync(srcDir)) {
return rootDir
}
const srcDirFiles = new Set<string>()
if (existsSync(srcDir)) {
const files = await readdir(srcDir).catch(() => [])
for (const file of files) {
if (file !== 'spa-loading-template.html' && !file.startsWith('router.options')) {
srcDirFiles.add(file)
}
}
}
if (srcDirFiles.size === 0) {
for (const file of ['app.vue', 'App.vue']) {
if (existsSync(resolve(rootDir, file))) {

View File

@ -1,10 +1,14 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import { applyDefaults } from 'untyped'
import { normalize } from 'pathe'
import { NuxtConfigSchema } from '../src'
import type { NuxtOptions } from '../src'
vi.mock('node:fs', () => ({
existsSync: (id: string) => id.endsWith('app'),
}))
describe('nuxt folder structure', () => {
it('should resolve directories for v3 setup correctly', async () => {
const result = await applyDefaults(NuxtConfigSchema, {})