MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveComponent

Function resolveComponent

src/resolution/frameworks/vue.ts:343–373  ·  view source on GitHub ↗

* Resolve a Vue component reference to its .vue file

(
  name: string,
  fromFile: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

341 * Resolve a Vue component reference to its .vue file
342 */
343function resolveComponent(
344 name: string,
345 fromFile: string,
346 context: ResolutionContext
347): string | null {
348 // Collect ALL basename matches first. The previous version returned the
349 // FIRST `Button.vue` found anywhere in the tree (its same-directory pass
350 // below was unreachable), so a multi-app monorepo with one `Button.vue`
351 // per app resolved to an arbitrary one (#764).
352 const matches: string[] = [];
353 for (const file of context.getAllFiles()) {
354 if (!file.endsWith('.vue')) continue;
355 const fileName = file.split(/[/\\]/).pop() || '';
356 if (fileName.replace(/\.vue$/, '') === name) matches.push(file);
357 }
358 if (matches.length === 0) return null;
359
360 const componentIn = (file: string): string | null => {
361 const nodes = context.getNodesInFile(file);
362 const component = nodes.find((n) => n.kind === 'component' && n.name === name);
363 return component ? component.id : null;
364 };
365
366 // The referencing file's folder, or one below it, first for specificity
367 const sameDir = inReferencingFolder(fromFile, matches, (f) => f);
368 if (sameDir.length > 0) return componentIn(sameDir[0]!);
369
370 // No positional signal: only an UNAMBIGUOUS basename may resolve;
371 // ambiguity falls through to the name-matcher's proximity scoring.
372 return matches.length === 1 ? componentIn(matches[0]!) : null;
373}
374
375/**
376 * Convert a file path to a Nuxt route path

Callers 1

resolveFunction · 0.70

Calls 4

inReferencingFolderFunction · 0.90
pushMethod · 0.80
componentInFunction · 0.70
getAllFilesMethod · 0.65

Tested by

no test coverage detected