MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / WindowsToWSLConverter

Class WindowsToWSLConverter

src/utils/idePathConversion.ts:25–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23 * Converter for Windows IDE + WSL Claude scenario
24 */
25export class WindowsToWSLConverter implements IDEPathConverter {
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
60
61 try {
62 // Use wslpath to convert WSL paths to Windows paths
63 const result = execFileSync('wslpath', ['-w', wslPath], {
64 encoding: 'utf8',
65 stdio: ['pipe', 'pipe', 'ignore'], // wslpath writes "wslpath: <errortext>" to stderr
66 }).trim()
67
68 return result
69 } catch {
70 // If wslpath fails, return the original path
71 return wslPath
72 }
73 }
74}
75
76/**
77 * Check if distro names match for WSL UNC paths

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected