fix(nuxt): warn when ignoring duplicate island/server component (#22709)

This commit is contained in:
Julien Huang 2023-08-23 17:23:17 +02:00 committed by GitHub
parent e058a10525
commit aa37de48f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -95,10 +95,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
const componentName = resolveComponentName(fileName, prefixParts)
if (resolvedNames.has(componentName + suffix) || resolvedNames.has(componentName)) {
console.warn(`[nuxt] Two component files resolving to the same name \`${componentName}\`:\n` +
`\n - ${filePath}` +
`\n - ${resolvedNames.get(componentName)}`
)
warnAboutDuplicateComponent(componentName, filePath, resolvedNames.get(componentName) || resolvedNames.get(componentName + suffix)!)
continue
}
resolvedNames.set(componentName + suffix, filePath)
@ -136,10 +133,14 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
continue
}
// Ignore component if component is already defined (with same mode)
if (!components.some(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))) {
components.push(component)
const existingComponent = components.find(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))
if (existingComponent) {
// Ignore component if component is already defined (with same mode)
warnAboutDuplicateComponent(componentName, filePath, existingComponent.filePath)
continue
}
components.push(component)
}
scannedPaths.push(dir.path)
}
@ -174,3 +175,10 @@ export function resolveComponentName (fileName: string, prefixParts: string[]) {
return pascalCase(componentNameParts) + pascalCase(fileNameParts)
}
function warnAboutDuplicateComponent (componentName: string, filePath: string, duplicatePath: string) {
console.warn(`[nuxt] Two component files resolving to the same name \`${componentName}\`:\n` +
`\n - ${filePath}` +
`\n - ${duplicatePath}`
)
}