(filePath: string)
| 81 | |
| 82 | /** What a file is to the router, or null for a file that is not a route. */ |
| 83 | export 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 | |
| 110 | function languageForFile(filePath: string): Language { |
| 111 | if (filePath.endsWith('.tsx')) return 'tsx'; |
no test coverage detected