export enum ArchType { ia32 , x64 } export class ArchitectureReplacer { public static checkAndReplaceWSLPipeProgram ( pipeProgramStr , expectedArch ) { let replacedPipeProgram ; const winDir = process . env . WINDIR ? process . env . WINDIR . toLowerCase ( ) : undefined ; const winDirAltDirSep = process . env . WINDIR ? process . env . WINDIR . replace ( '\\' , '/' ) . toLowerCase ( ) : undefined ; const winDirEnv = "${env:windir}" ; if ( winDir && winDirAltDirSep && ( pipeProgramStr . indexOf ( winDir ) === 0 || pipeProgramStr . indexOf ( winDirAltDirSep ) === 0 || pipeProgramStr . indexOf ( winDirEnv ) === 0 ) ) { if ( expectedArch === ArchType . x64 ) { const pathSep = ArchitectureReplacer . checkForFolderInPath ( pipeProgramStr , "sysnative" ) ; if ( pathSep ) { replacedPipeProgram = pipeProgramStr . replace ( `${ pathSep }sysnative${ pathSep }` , `${ pathSep }system32${ pathSep }` ) ; } } else if ( expectedArch === ArchType . ia32 ) { const pathSep = ArchitectureReplacer . checkForFolderInPath ( pipeProgramStr , "system32" ) ; if ( pathSep ) { replacedPipeProgram = pipeProgramStr . replace ( `${ pathSep }system32${ pathSep }` , `${ pathSep }sysnative${ pathSep }` ) ; } } } return replacedPipeProgram ; } public static checkForFolderInPath ( path , folder ) { if ( path . indexOf ( `/${ folder }/` ) >= 0 ) { return '/' ; } else if ( path . indexOf ( `\\${ folder }\\` ) >= 0 ) { return '\\' ; } return "" ; } }