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

Function nextRouteForFile

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

Source from the content-addressed store, hash-verified

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