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

Function extract

src/resolution/frameworks/astro.ts:105–160  ·  view source on GitHub ↗
(filePath: string, content: string)

Source from the content-addressed store, hash-verified

103 },
104
105 extract(filePath: string, content: string) {
106 const nodes: Node[] = [];
107 const references: UnresolvedRef[] = [];
108 const now = Date.now();
109
110 // Normalize to forward slashes
111 const normalized = filePath.replace(/\\/g, '/');
112
113 // Astro file-based routing lives under src/pages/ — .astro files are
114 // pages, .ts/.js files are API endpoints. (.md/.mdx pages exist too but
115 // aren't indexed as source.) Underscore-prefixed segments are excluded
116 // from routing by Astro.
117 const pagesMatch = /(?:^|\/)src\/pages\//.exec(normalized);
118 if (pagesMatch && /\.(astro|ts|js|mjs)$/.test(normalized)) {
119 const afterPages = normalized.substring(pagesMatch.index + pagesMatch[0].length);
120 const base = afterPages.split('/').pop() || '';
121
122 // Underscore-prefixed segments are excluded from routing by Astro;
123 // a stray `*.config.*` in a pages dir is never a route.
124 if (
125 !afterPages.split('/').some((segment) => segment.startsWith('_')) &&
126 !/\.config\.[a-z]+$/.test(base)
127 ) {
128 const routePath = filePathToAstroRoute(afterPages);
129 const isPage = normalized.endsWith('.astro');
130 const language = isPage ? 'astro' : 'typescript';
131 const route: Node = {
132 id: `route:${filePath}:${routePath}:1`,
133 kind: 'route',
134 name: routePath,
135 qualifiedName: `${filePath}::route:${routePath}`,
136 filePath,
137 startLine: 1,
138 endLine: 1,
139 startColumn: 0,
140 endColumn: 0,
141 language,
142 updatedAt: now,
143 };
144 nodes.push(route);
145 if (isPage) {
146 references.push(pageComponentRef(route, '.astro', 'astro'));
147 } else {
148 // An endpoint is served by the verbs it exports: `export const GET:
149 // APIRoute = …`, `export async function POST(…)`.
150 for (const m of content.matchAll(ENDPOINT_EXPORT)) {
151 const verb = m[1] ?? m[2]!;
152 const line = lineAt(content, m.index);
153 references.push({ fromNodeId: route.id, referenceName: verb, referenceKind: 'references', line, column: 0, filePath, language, candidates: [verb] });
154 }
155 }
156 }
157 }
158
159 return { nodes, references };
160 },
161};
162

Callers

nothing calls this directly

Calls 5

pageComponentRefFunction · 0.90
lineAtFunction · 0.90
filePathToAstroRouteFunction · 0.85
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected