(windowsPath: string)
| 26 | constructor(private wslDistroName: string | undefined) {} |
| 27 | |
| 28 | toLocalPath(windowsPath: string): string { |
| 29 | if (!windowsPath) return windowsPath |
| 30 | |
| 31 | // Check if this is a path from a different WSL distro |
| 32 | if (this.wslDistroName) { |
| 33 | const wslUncMatch = windowsPath.match( |
| 34 | /^\\\\wsl(?:\.localhost|\$)\\([^\\]+)(.*)$/, |
| 35 | ) |
| 36 | if (wslUncMatch && wslUncMatch[1] !== this.wslDistroName) { |
| 37 | // Different distro - wslpath will fail, so return original path |
| 38 | return windowsPath |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | try { |
| 43 | // Use wslpath to convert Windows paths to WSL paths |
| 44 | const result = execFileSync('wslpath', ['-u', windowsPath], { |
| 45 | encoding: 'utf8', |
| 46 | stdio: ['pipe', 'pipe', 'ignore'], // wslpath writes "wslpath: <errortext>" to stderr |
| 47 | }).trim() |
| 48 | |
| 49 | return result |
| 50 | } catch { |
| 51 | // If wslpath fails, fall back to manual conversion |
| 52 | return windowsPath |
| 53 | .replace(/\\/g, '/') // Convert backslashes to forward slashes |
| 54 | .replace(/^([A-Z]):/i, (_, letter) => `/mnt/${letter.toLowerCase()}`) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | toIDEPath(wslPath: string): string { |
| 59 | if (!wslPath) return wslPath |
no outgoing calls
no test coverage detected