* 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)
| 1683 | * `src/x.ts` all match the same indexed file. (#825) |
| 1684 | */ |
| 1685 | function normalizeIndexPath(filePath: string, projectPath: string): string { |
| 1686 | let f = filePath.trim(); |
| 1687 | if (!f) return ''; |
| 1688 | if (path.isAbsolute(f)) f = path.relative(projectPath, f); |
| 1689 | // Collapse `.`/`..` segments, then force forward slashes and drop a leading |
| 1690 | // `./` (path.normalize already strips it on POSIX; explicit for Windows). |
| 1691 | f = path.normalize(f).replace(/\\/g, '/').replace(/^\.\//, ''); |
| 1692 | return f; |
| 1693 | } |
| 1694 | |
| 1695 | /** |
| 1696 | * Convert glob pattern to regex |