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

Function normalizeIndexPath

src/bin/codegraph.ts:2130–2138  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2128 * `src/x.ts` all match the same indexed file. (#825)
2129 */
2130function normalizeIndexPath(filePath: string, projectPath: string): string {
2131 let f = filePath.trim();
2132 if (!f) return '';
2133 if (path.isAbsolute(f)) f = path.relative(projectPath, f);
2134 // Collapse `.`/`..` segments, then force forward slashes and drop a leading
2135 // `./` (path.normalize already strips it on POSIX; explicit for Windows).
2136 f = path.normalize(f).replace(/\\/g, '/').replace(/^\.\//, '');
2137 return f;
2138}
2139
2140/**
2141 * Convert glob pattern to regex

Callers 1

mainFunction · 0.85

Calls 1

normalizeMethod · 0.80

Tested by

no test coverage detected