* Resolve an Astro component reference using name-based lookup
( name: string, fromFile: string, context: ResolutionContext )
| 173 | * Resolve an Astro component reference using name-based lookup |
| 174 | */ |
| 175 | function resolveComponent( |
| 176 | name: string, |
| 177 | fromFile: string, |
| 178 | context: ResolutionContext |
| 179 | ): string | null { |
| 180 | // Look for component nodes by name |
| 181 | const candidates = context.getNodesByName(name); |
| 182 | const components = candidates.filter((n) => n.kind === 'component'); |
| 183 | |
| 184 | if (components.length === 0) return null; |
| 185 | |
| 186 | // Prefer the referencing file's folder, or one below it |
| 187 | const sameDir = inReferencingFolder(fromFile, components, (n) => n.filePath); |
| 188 | if (sameDir.length > 0) return sameDir[0]!.id; |
| 189 | |
| 190 | // No positional signal: only an UNAMBIGUOUS name may resolve — picking |
| 191 | // components[0] would choose an arbitrary same-named component in a |
| 192 | // multi-app monorepo (#764). Ambiguity falls through to the name-matcher, |
| 193 | // whose proximity scoring decides. |
| 194 | return components.length === 1 ? components[0]!.id : null; |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * Convert a path under src/pages/ to an Astro route path. |
no test coverage detected