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

Function nextProxyFor

src/resolution/frameworks/next-proxy.ts:73–92  ·  view source on GitHub ↗
(context: ResolutionContext, dir: string, root: string)

Source from the content-addressed store, hash-verified

71 * ordinary module, so a lone one counts unless the app pins an older Next.
72 */
73export function nextProxyFor(context: ResolutionContext, dir: string, root: string): NextProxy | null {
74 const find = (base: string): string | undefined =>
75 PROXY_EXTENSIONS.map((ext) => `${dir}${base}.${ext}`).find((file) => context.fileExists(file));
76 const middleware = find('middleware');
77 const proxy = middleware ? undefined : find('proxy');
78 const file = middleware ?? (proxy && !pinsNextBefore16(context, root) ? proxy : undefined);
79 if (!file) return null;
80
81 const nodes = context.getNodesInFile(file);
82 const named = nodes.find((n) => ENTRY_KINDS.has(n.kind) && n.isExported && n.name === (middleware ? 'middleware' : 'proxy'));
83 if (named) return { file, entry: named };
84
85 const safe = stripCommentsForRegex(context.readFile(file) ?? '', 'typescript');
86 const local =
87 /\bexport\s+default\s+(?:async\s+)?function\s*\*?\s*([A-Za-z_$][\w$]*)/.exec(safe)?.[1] ??
88 /\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*;?\s*$/m.exec(safe)?.[1] ??
89 /\bexport\s*\{[^}]*?\b([A-Za-z_$][\w$]*)\s+as\s+(?:default|middleware|proxy)\b[^}]*\}(?!\s*from\b)/.exec(safe)?.[1];
90 const entry = (local ? nodes.find((n) => ENTRY_KINDS.has(n.kind) && n.name === local) : undefined) ?? nodes.find((n) => n.kind === 'file');
91 return entry ? { file, entry } : null;
92}
93
94// =============================================================================
95// config.matcher

Callers 1

nextProxyEdgesFunction · 0.90

Calls 7

stripCommentsForRegexFunction · 0.90
pinsNextBefore16Function · 0.85
hasMethod · 0.80
findFunction · 0.70
getNodesInFileMethod · 0.65
readFileMethod · 0.65
execMethod · 0.65

Tested by

no test coverage detected