* Normalize a user-supplied file path to the project-relative, forward-slash * form CodeGraph stores in the index. Accepts an absolute path, a `./`-prefixed * path, or Windows back-slashes; an empty string when the input is blank. Used * by `codegraph affected` so `./src/x.ts`, `/abs/repo/src/x.t
(filePath: string, projectPath: string)
| 2177 | * `src/x.ts` all match the same indexed file. (#825) |
| 2178 | */ |
| 2179 | function normalizeIndexPath(filePath: string, projectPath: string): string { |
| 2180 | let f = filePath.trim(); |
| 2181 | if (!f) return ''; |
| 2182 | if (path.isAbsolute(f)) f = path.relative(projectPath, f); |
| 2183 | // Collapse `.`/`..` segments, then force forward slashes and drop a leading |
| 2184 | // `./` (path.normalize already strips it on POSIX; explicit for Windows). |
| 2185 | f = path.normalize(f).replace(/\\/g, '/').replace(/^\.\//, ''); |
| 2186 | return f; |
| 2187 | } |
| 2188 | |
| 2189 | /** |
| 2190 | * Convert glob pattern to regex |