GitHub

@@ -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>>()

21212222

const componentFiles = globSync(['**/*.vue'], {

2323

cwd: componentDir,

2424

absolute: true

2525

})

262627-

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')

104104105105

for (const file of appFiles) {

106106

try {

@@ -124,7 +124,7 @@ async function detectUsedComponents(

124124

}

125125126126

// Build dependency graph of components

127-

const dependencyGraph = await buildComponentDependencyGraph(componentDir, prefix)

127+

const dependencyGraph = await buildComponentDependencyGraph(componentDir, componentPattern)

128128129129

// Resolve all dependencies for detected components

130130

const allComponents = new Set<string>()

Read the original on github.com ↗