11import { MacCodacyCli } from './MacCodacyCli'
22
3+
34export class WinWSLCodacyCli extends MacCodacyCli {
45 constructor ( rootPath : string , provider ?: string , organization ?: string , repository ?: string ) {
56 const winRootPath =
@@ -10,20 +11,26 @@ export class WinWSLCodacyCli extends MacCodacyCli {
1011 private static toWSLPath ( path : string ) : string {
1112 // Convert Windows path to WSL path
1213 // Example: 'C:\Users\user\project' -> '/mnt/c/Users/user/project'
13- const wslPath = path . replace ( / \\ / g, '/' ) . replace ( ' ' , '\\ ' ) . replace ( / ^ ' ( [ a - z A - Z ] ) : / , "'/mnt/$1" )
14+ // First, unescape any escaped spaces (backslash-space -> space)
15+ let cleanPath = path . replace ( / ^ ' | ' $ / g, '' )
16+ // Unescape any escaped spaces (backslash-space -> space)
17+ cleanPath = cleanPath . replace ( / \\ / g, ' ' )
18+ // Then convert backslashes to slashes and add /mnt/ prefix
19+ const wslPath = cleanPath . replace ( / \\ / g, '/' ) . replace ( / ^ ' ? ( [ a - z A - Z ] ) : / , '/mnt/$1' ) . replace ( / / g, '\\ ' )
1420 return wslPath
1521 }
1622
1723 private static fromWSLPath ( path : string ) : string {
1824 // Convert WSL path to Windows path while keeping quotes
1925 // Example: '/mnt/c/Users/user/project' -> 'C:\Users\user\project'
20- const windowsPath = path . replace ( / ^ ' \/ m n t \/ ( [ a - z A - Z ] ) / , "'$1:" ) . replace ( '\\ ' , ' ' , ) . replace ( / \/ / g, '\\' )
26+ const windowsPath = path . replace ( / ^ ' \/ m n t \/ ( [ a - z A - Z ] ) / , "'$1:" ) . replace ( / \/ / g, '\\' )
2127 return windowsPath
2228 }
2329
2430 protected preparePathForExec ( path : string ) : string {
25- // Convert the path to WSL format
26- return WinWSLCodacyCli . toWSLPath ( path )
31+ // Convert the path to WSL format and wrap in quotes to handle spaces
32+ const wslPath = WinWSLCodacyCli . toWSLPath ( path )
33+ return `'${ wslPath } '`
2734 }
2835
2936 protected async execAsync (
0 commit comments