Skip to content

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

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

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/nuxt/src/components/scan.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)

Expand Down