Skip to content

Commit 5a5ac45

Browse files
committed
fix(module): detect lazy components when using experimental.componentDetection
1 parent d07d4f7 commit 5a5ac45

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/templates.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ import * as themeContent from './theme/content'
1616
/**
1717
* Build a dependency graph of components by scanning their source files
1818
*/
19-
async function buildComponentDependencyGraph(componentDir: string, prefix: string): Promise<Map<string, Set<string>>> {
19+
async function buildComponentDependencyGraph(componentDir: string, componentPattern: RegExp): Promise<Map<string, Set<string>>> {
2020
const dependencyGraph = new Map<string, Set<string>>()
2121

2222
const componentFiles = globSync(['**/*.vue'], {
2323
cwd: componentDir,
2424
absolute: true
2525
})
2626

27-
const componentPattern = new RegExp(`<${prefix}([A-Z][a-zA-Z]+)|\\b${prefix}([A-Z][a-zA-Z]+)\\b`, 'g')
28-
2927
for (const componentFile of componentFiles) {
3028
try {
3129
const content = await readFile(componentFile, 'utf-8')
@@ -100,7 +98,9 @@ async function detectUsedComponents(
10098
// Pattern to match:
10199
// - <UButton in templates
102100
// - UButton in script (imports, usage)
103-
const componentPattern = new RegExp(`<${prefix}([A-Z][a-zA-Z]+)|\\b${prefix}([A-Z][a-zA-Z]+)\\b`, 'g')
101+
// - <LazyUButton (lazy components)
102+
// - LazyUButton in script
103+
const componentPattern = new RegExp(`<(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)|\\b(?:Lazy)?${prefix}([A-Z][a-zA-Z]+)\\b`, 'g')
104104

105105
for (const file of appFiles) {
106106
try {
@@ -124,7 +124,7 @@ async function detectUsedComponents(
124124
}
125125

126126
// Build dependency graph of components
127-
const dependencyGraph = await buildComponentDependencyGraph(componentDir, prefix)
127+
const dependencyGraph = await buildComponentDependencyGraph(componentDir, componentPattern)
128128

129129
// Resolve all dependencies for detected components
130130
const allComponents = new Set<string>()

0 commit comments

Comments
 (0)