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

Function routePathForFile

src/resolution/frameworks/expo-router.ts:62–82  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

60
61/** Files under `app/` that define a screen (not a layout, not test, not html). */
62export function routePathForFile(filePath: string): string | null {
63 const dir = APP_DIR.exec(filePath);
64 if (!dir) return null;
65 const rel = filePath.slice(dir.index + dir[0].length);
66 const ext = ROUTE_EXT.exec(rel);
67 if (!ext) return null;
68 const bare = rel.slice(0, ext.index);
69 if (bare.endsWith('.d') || /\.(?:test|spec|stories)$/.test(bare)) return null;
70 const segs = bare.split('/');
71 if (segs.includes('__tests__') || segs.includes('__mocks__')) return null;
72 const base = segs[segs.length - 1]!;
73 // `hello+api.ts` is an endpoint (`apiRoutePathForFile`), not a screen.
74 if (base.endsWith('+api')) return null;
75 // `_layout` (and any other `_`-prefixed file) is not navigable. `+not-found`
76 // is a real screen; the other `+` files (`+html`, `+native-intent`) are not.
77 if (base.startsWith('_')) return null;
78 if (base.startsWith('+') && base !== '+not-found') return null;
79 const kept = segs.filter((s) => !(s.startsWith('(') && s.endsWith(')')));
80 if (kept[kept.length - 1] === 'index') kept.pop();
81 return '/' + kept.join('/');
82}
83
84/**
85 * An API route's path — `app/blog/og-image/[post]+api.ts` is

Callers 4

isScreenRouteFunction · 0.85
normalizeHrefPathFunction · 0.85
extractFunction · 0.85

Calls 2

execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected