import { JsxEmit , ScriptTarget , ModuleResolutionKind , parseJsonConfigFileContent , CompilerOptions , findConfigFile , sys , readJsonConfigFile , parseJsonSourceFileConfigFileContent , ModuleKind } from '@tsd/typescript' ; import { Config , PackageJsonWithTsdConfig , RawCompilerOptions } from './interfaces' ; param pkg returns export default ( pkg , cwd ) : Config => { const pkgConfig = pkg . tsd ?? { } ; const tsConfigCompilerOptions = getOptionsFromTsConfig ( cwd ) ; const packageJsonCompilerOptions = parseCompilerConfigObject ( pkgConfig . compilerOptions ?? { } , cwd ) ; return { directory : 'test-d' , ... pkgConfig , compilerOptions : { strict : true , jsx : JsxEmit . React , lib : parseRawLibs ( [ 'es2017' , 'dom' , 'dom.iterable' ] , cwd ) , module : ModuleKind . CommonJS , target : ScriptTarget . ES2017 , esModuleInterop : true , ... tsConfigCompilerOptions , ... packageJsonCompilerOptions , moduleResolution : ModuleResolutionKind . NodeJs , skipLibCheck : false } } ; } ; function getOptionsFromTsConfig ( cwd ) { const configPath = findConfigFile ( cwd , sys . fileExists ) ; if ( ! configPath ) { return { } ; } return parseJsonSourceFileConfigFileContent ( readJsonConfigFile ( configPath , sys . readFile ) , sys , cwd , undefined , configPath ) . options ; } function parseCompilerConfigObject ( compilerOptions , cwd ) { return parseJsonConfigFileContent ( { compilerOptions : compilerOptions || { } } , sys , cwd ) . options ; } function parseRawLibs ( libs , cwd ) { return parseCompilerConfigObject ( { lib : libs } , cwd ) . lib ?? [ ] ; }