import { child_process } from 'mz' ; import { EOL } from "os" ; import * as executables from './executables' ; returns export async function getHostVersion ( ) { const dotnetExecutable = await executables . find ( 'dotnet' ) ; if ( dotnetExecutable === null ) return '' ; const [ stdOut , stdError ] = await child_process . execFile ( dotnetExecutable , [ '--info' ] ) ; const lines = stdOut . trim ( ) . split ( EOL ) ; if ( lines . length <= 1 ) return stdError . trim ( ) ; let infoSectionName = null ; let runtimeEnvironmentSectionName = null ; let hostSectionName = null ; let sdkListSectionName = null ; let runtimeListSectionName = null ; let sectionName = "unknown" ; let sectionData = new Map < string , string [ ] > ( ) ; let currentSection = [ ] ; sectionData [ sectionName ] = currentSection ; for ( let lineIndex = 0 ; lineIndex < lines . length ; lineIndex ++ ) { const currentLine = lines [ lineIndex ] ; if ( currentLine . trim ( ) . length === 0 ) continue ; if ( currentLine . startsWith ( ' ' ) ) { currentSection . push ( currentLine . trim ( ) ) ; } else { sectionName = currentLine . trim ( ) ; currentSection = sectionData . get ( sectionName ) ; if ( ! currentSection ) { currentSection = [ ] ; sectionData . set ( sectionName , currentSection ) ; } if ( ! infoSectionName ) infoSectionName = sectionName ; else if ( ! runtimeEnvironmentSectionName ) runtimeEnvironmentSectionName = sectionName ; else if ( ! hostSectionName ) hostSectionName = sectionName ; else if ( ! sdkListSectionName ) sdkListSectionName = sectionName ; else if ( ! runtimeListSectionName ) runtimeListSectionName = sectionName ; } } if ( ! hostSectionName ) throw new Error ( 'Failed to find the Host section in output from "dotnet --info".' ) ; const hostSection = sectionData . get ( hostSectionName ) ; const hostVersionInfo = hostSection . find ( keyValuePair => keyValuePair . startsWith ( 'Version: ' ) ) ; if ( ! hostVersionInfo ) throw new Error ( 'Failed to find the Host version information in output from "dotnet --info".' ) ; const hostVersion = hostVersionInfo . split ( ':' ) [ 1 ] . trim ( ) ; return hostVersion ; }