import * as ts from "typescript" ; import * as path from "path" ; const defaultTscUtil = getTscUtil ( ts ) ; export const parseCommandLine = defaultTscUtil . parseCommandLine ; export const findConfigFile = defaultTscUtil . findConfigFile ; export const readConfigFile = defaultTscUtil . readConfigFile ; export function convertToOptionsWithAbsolutePath ( options , cwd ) { const result = { ... options } ; for ( const key of [ "baseUrl" , "configFilePath" , "declarationDir" , "outDir" , "rootDir" , "project" ] ) { const value = result [ key ] as string ; if ( value !== undefined ) { result [ key ] = path . resolve ( cwd , value ) ; } } for ( const key of [ "typeRoots" ] ) { const value = result [ key ] as string [ ] ; if ( value !== undefined ) { result [ key ] = value . map ( ( relative ) => path . resolve ( cwd , relative ) ) ; } } return result ; } export function getTscUtil ( tsLib ) { return { parseCommandLine : ( command ) => { const args = command . split ( " " ) ; const parsedCommand = tsLib . parseCommandLine ( args . slice ( 1 ) ) ; if ( parsedCommand . errors . length ) { return undefined ; } return parsedCommand ; } , findConfigFile : ( directory , parsedCommand ) => { let tsConfigFullPath ; const project = parsedCommand ?. options . project ; if ( project !== undefined ) { tsConfigFullPath = path . resolve ( directory , project ) ; } else { const foundConfigFile = tsLib . findConfigFile ( directory , tsLib . sys . fileExists , "tsconfig.json" ) ; if ( foundConfigFile ) { tsConfigFullPath = foundConfigFile ; } else { tsConfigFullPath = path . join ( directory , "tsconfig.json" ) ; } } return tsConfigFullPath ; } , readConfigFile : ( path ) => { const configFile = tsLib . readConfigFile ( path , tsLib . sys . readFile ) ; if ( configFile . error ) { return undefined ; } return configFile . config ; } , convertToOptionsWithAbsolutePath , } ; } ;