mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): scan component dirs case-sensitively (#20995)
This commit is contained in:
parent
6d8c119a26
commit
3ed0d0ffc1
@ -1,7 +1,8 @@
|
||||
import { readdir } from 'node:fs/promises'
|
||||
import { basename, dirname, extname, join, relative } from 'pathe'
|
||||
import { globby } from 'globby'
|
||||
import { pascalCase, splitByCase } from 'scule'
|
||||
import { isIgnored } from '@nuxt/kit'
|
||||
import { isIgnored, useNuxt } from '@nuxt/kit'
|
||||
// eslint-disable-next-line vue/prefer-import-from-vue
|
||||
import { hyphenate } from '@vue/shared'
|
||||
import { withTrailingSlash } from 'ufo'
|
||||
@ -30,6 +31,24 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
|
||||
const resolvedNames = new Map<string, string>()
|
||||
|
||||
const files = (await globby(dir.pattern!, { cwd: dir.path, ignore: dir.ignore })).sort()
|
||||
|
||||
// Check if the directory exists (globby will otherwise read it case insensitively on MacOS)
|
||||
if (files.length) {
|
||||
const siblings = await readdir(dirname(dir.path)).catch(() => [] as string[])
|
||||
|
||||
const directory = basename(dir.path)
|
||||
if (!siblings.includes(directory)) {
|
||||
const caseCorrected = siblings.find(sibling => sibling.toLowerCase() === directory.toLowerCase())
|
||||
if (caseCorrected) {
|
||||
const nuxt = useNuxt()
|
||||
const original = relative(nuxt.options.srcDir, dir.path)
|
||||
const corrected = relative(nuxt.options.srcDir, join(dirname(dir.path), caseCorrected))
|
||||
console.warn(`[nuxt] Components not scanned from \`~/${corrected}\`. Did you mean to name the directory \`~/${original}\` instead?`)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const _file of files) {
|
||||
const filePath = join(dir.path, _file)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user