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

Function routePathForFile

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

Source from the content-addressed store, hash-verified

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