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