fix(nuxt): scan component dirs case-sensitively (#20995)

This commit is contained in:
Daniel Roe 2023-05-22 11:04:02 +01:00 committed by GitHub
parent 6d8c119a26
commit 3ed0d0ffc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,8 @@
import { readdir } from 'node:fs/promises'
import { basename, dirname, extname, join, relative } from 'pathe' import { basename, dirname, extname, join, relative } from 'pathe'
import { globby } from 'globby' import { globby } from 'globby'
import { pascalCase, splitByCase } from 'scule' 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 // eslint-disable-next-line vue/prefer-import-from-vue
import { hyphenate } from '@vue/shared' import { hyphenate } from '@vue/shared'
import { withTrailingSlash } from 'ufo' import { withTrailingSlash } from 'ufo'
@ -30,6 +31,24 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
const resolvedNames = new Map<string, string>() const resolvedNames = new Map<string, string>()
const files = (await globby(dir.pattern!, { cwd: dir.path, ignore: dir.ignore })).sort() 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) { for (const _file of files) {
const filePath = join(dir.path, _file) const filePath = join(dir.path, _file)