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

Function nextRouteForFile

src/resolution/frameworks/nextjs.ts:83–108  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

81
82/** What a file is to the router, or null for a file that is not a route. */
83export function nextRouteForFile(filePath: string): NextRouteFile | null {
84 if (/(?:^|\/)(?:__tests__|__mocks__|node_modules)\//.test(filePath)) return null;
85 const app = /^((?:[^/]+\/)*?)(?:src\/)?app\/(.+)$/.exec(filePath);
86 if (app) {
87 const m = /^(.*?)(?:^|\/)(page|route)\.(?:tsx|ts|jsx|js|mjs|cjs|mdx?)$/.exec(app[2]!);
88 if (!m) return null;
89 const segs = m[1]!.split('/').filter(Boolean);
90 // Parallel and intercepting routes are a picture of their own; not modelled.
91 if (segs.some((s) => s.startsWith('@') || /^\(\.{1,3}\)/.test(s))) return null;
92 const kept = segs.filter((s) => !(s.startsWith('(') && s.endsWith(')'))).map(nextSegment);
93 return { kind: m[2] === 'page' ? 'page' : 'handler', path: '/' + kept.join('/'), root: app[1]! };
94 }
95 const pages = /^((?:[^/]+\/)*?)(?:src\/)?pages\/(.+)$/.exec(filePath);
96 if (pages) {
97 const rel = pages[2]!;
98 const ext = /\.(?:tsx|ts|jsx|js|mjs|cjs|mdx?)$/.exec(rel);
99 if (!ext) return null;
100 const bare = rel.slice(0, ext.index);
101 const segs = bare.split('/');
102 const base = segs[segs.length - 1]!;
103 if (base.startsWith('_') || /\.(?:test|spec|stories|config|d)$/.test(bare)) return null;
104 if (segs[segs.length - 1] === 'index') segs.pop();
105 return { kind: segs[0] === 'api' ? 'api' : 'page', path: '/' + segs.map(nextSegment).join('/'), root: pages[1]! };
106 }
107 return null;
108}
109
110function languageForFile(filePath: string): Language {
111 if (filePath.endsWith('.tsx')) return 'tsx';

Callers 8

hasSynthesisPatternFunction · 0.90
nextProxyEdgesFunction · 0.90
requestTriggerFunction · 0.90
projectKindFunction · 0.90
nextjs.test.tsFile · 0.90
tablePageFunction · 0.85
detectFunction · 0.85
extractFunction · 0.85

Calls 3

mapMethod · 0.80
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected