mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +00:00
feat(nuxt): warn when user components' names begin with Lazy
(#27838)
This commit is contained in:
parent
3310a1ab5c
commit
9c0f8503da
@ -43,7 +43,7 @@ export const loaderPlugin = createUnplugin((options: LoaderOptions) => {
|
||||
const s = new MagicString(code)
|
||||
|
||||
// replace `_resolveComponent("...")` to direct import
|
||||
s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy)?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, name: string) => {
|
||||
s.replace(/(?<=[ (])_?resolveComponent\(\s*["'](lazy-|Lazy(?=[A-Z]))?([^'"]*)["'][^)]*\)/g, (full: string, lazy: string, name: string) => {
|
||||
const component = findComponent(components, name, options.mode)
|
||||
if (component) {
|
||||
// @ts-expect-error TODO: refactor to nuxi
|
||||
|
@ -96,6 +96,10 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
|
||||
const componentNameSegments = resolveComponentNameSegments(fileName.replace(/["']/g, ''), prefixParts)
|
||||
const pascalName = pascalCase(componentNameSegments)
|
||||
|
||||
if (LAZY_COMPONENT_NAME_REGEX.test(pascalName)) {
|
||||
logger.warn(`The component \`${pascalName}\` (in \`${filePath}\`) is using the reserved "Lazy" prefix used for dynamic imports, which may cause it to break at runtime.`)
|
||||
}
|
||||
|
||||
if (resolvedNames.has(pascalName + suffix) || resolvedNames.has(pascalName)) {
|
||||
warnAboutDuplicateComponent(pascalName, filePath, resolvedNames.get(pascalName) || resolvedNames.get(pascalName + suffix)!)
|
||||
continue
|
||||
@ -166,3 +170,5 @@ function warnAboutDuplicateComponent (componentName: string, filePath: string, d
|
||||
`\n - ${duplicatePath}`,
|
||||
)
|
||||
}
|
||||
|
||||
const LAZY_COMPONENT_NAME_REGEX = /^Lazy(?=[A-Z])/
|
||||
|
Loading…
Reference in New Issue
Block a user