/** * Path normalization chokepoint. * * Internal contract: every path stored, compared, or used as a Map/Set key * inside this library is in POSIX form (forward slashes). The library accepts * native paths (backslash on Windows, forward slash elsewhere) at every public * API boundary and at every `node:path` call site whose result flows into * storage or comparison. * * `toPosixPath` is the only normalization primitive — anything that needs to * convert a native path to the internal form goes through it. The function is * idempotent: forward-slash inputs round-trip unchanged, so calls outside * Windows are effectively a no-op. * * Drive-letter case (`C:` vs `c:`) and Windows long-path prefixes (`\\?\`) are * deliberately out of scope — they don't arise from the path sources this * library consumes (tsconfig roots, glob results, caller-supplied ids). * * @module */ /** * Normalize a path to POSIX form (forward slashes). * * Replaces every backslash with a forward slash. Idempotent: forward-slash * input returns unchanged. Empty string returns empty string. * * @example * ```ts * toPosixPath('C:\\proj\\src\\lib\\foo.ts') // => 'C:/proj/src/lib/foo.ts' * toPosixPath('/home/user/proj/foo.ts') // => '/home/user/proj/foo.ts' (unchanged) * toPosixPath('') // => '' * ``` */ export const toPosixPath = (p: string): string => (p.includes('\\') ? p.replace(/\\/g, '/') : p);
{ "path": "paths.ts", "declarations": [ { "name": "toPosixPath", "kind": "function", "docComment": "Normalize a path to POSIX form (forward slashes).\n\nReplaces every backslash with a forward slash. Idempotent: forward-slash\ninput returns unchanged. Empty string returns empty string.", "typeSignature": "(p: string): string", "sourceLine": 35, "examples": [ "```ts\ntoPosixPath('C:\\\\proj\\\\src\\\\lib\\\\foo.ts') // => 'C:/proj/src/lib/foo.ts'\ntoPosixPath('/home/user/proj/foo.ts') // => '/home/user/proj/foo.ts' (unchanged)\ntoPosixPath('') // => ''\n```" ], "parameters": [ { "name": "p", "type": "string" } ], "returnType": "string" } ], "moduleComment": "Path normalization chokepoint.\n\nInternal contract: every path stored, compared, or used as a Map/Set key\ninside this library is in POSIX form (forward slashes). The library accepts\nnative paths (backslash on Windows, forward slash elsewhere) at every public\nAPI boundary and at every `node:path` call site whose result flows into\nstorage or comparison.\n\n`toPosixPath` is the only normalization primitive — anything that needs to\nconvert a native path to the internal form goes through it. The function is\nidempotent: forward-slash inputs round-trip unchanged, so calls outside\nWindows are effectively a no-op.\n\nDrive-letter case (`C:` vs `c:`) and Windows long-path prefixes (`\\\\?\\`) are\ndeliberately out of scope — they don't arise from the path sources this\nlibrary consumes (tsconfig roots, glob results, caller-supplied ids).", "dependents": [ "analyze-core.ts", "exports.ts", "files.ts", "postprocess.ts", "session.ts", "source-config.ts", "svelte.ts", "typescript-program.ts", "vite.ts" ] }