mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): warn when ignoring duplicate island/server component (#22709)
This commit is contained in:
parent
e058a10525
commit
aa37de48f7
@ -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}`
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user