MCPcopy
hub / github.com/npmx-dev/npmx.dev / parseComponentsDeclaration

Function parseComponentsDeclaration

test/unit/a11y-component-coverage.spec.ts:94–116  ·  view source on GitHub ↗

* Parse .nuxt/components.d.ts to get the mapping from component names to file paths. * This uses Nuxt's actual component resolution, so we don't have to guess the naming convention. * * Returns a Map of component name -> array of file paths (relative to app/components/)

(dtsPath: string)

Source from the content-addressed store, hash-verified

92 * Returns a Map of component name -> array of file paths (relative to app/components/)
93 */
94function parseComponentsDeclaration(dtsPath: string): Map<string, string[]> {
95 const content = fs.readFileSync(dtsPath, 'utf-8')
96 const componentMap = new Map<string, string[]>()
97
98 // Match lines like:
99 // export const ComponentName: typeof import("../app/components/Path/File.vue").default
100 const exportRegex =
101 /export const (\w+): typeof import\("\.\.\/app\/components\/([^"]+\.vue)"\)\.default/g
102
103 let match
104 while ((match = exportRegex.exec(content)) !== null) {
105 const componentName = match[1]!
106 const filePath = normalizeComponentPath(match[2]!)
107
108 const existing = componentMap.get(componentName) || []
109 if (!existing.includes(filePath)) {
110 existing.push(filePath)
111 }
112 componentMap.set(componentName, existing)
113 }
114
115 return componentMap
116}
117
118/**
119 * Extract tested component names from the test file.

Callers 1

Calls 3

normalizeComponentPathFunction · 0.85
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected