From 602aef453f4459809ca043837821ba2674ce828e Mon Sep 17 00:00:00 2001 From: Pmyl Date: Thu, 16 Jan 2020 16:42:46 +0000 Subject: [PATCH] fix(definitelyTyped): copy compiler option "paths" from processed type --- definitelyTypedTests/index.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/definitelyTypedTests/index.js b/definitelyTypedTests/index.js index d820524d6..e63e7af58 100644 --- a/definitelyTypedTests/index.js +++ b/definitelyTypedTests/index.js @@ -91,19 +91,34 @@ async function run(dir, processId) { } ], 'typeRoots': [ - '../DefinitelyTyped/types/' + definitelyTyped.typesFolder ], - "types": [], - "baseUrl": "../DefinitelyTyped/types/" + 'types': [], + 'baseUrl': definitelyTyped.typesFolder }, 'files': [ `./${processId}.index.ts` ] }; + const typePath = `${definitelyTyped.typesFolder}/${dir}`; + const typeTsConfigPath = `${typePath}/tsconfig.json`; + if (fs.existsSync(typeTsConfigPath)) { + const typeTsConfigFileContent = await fs.promises.readFile(typeTsConfigPath); + + try { + const typeTsConfig = JSON.parse(typeTsConfigFileContent); + if (typeTsConfig && typeTsConfig.compilerOptions && typeTsConfig.compilerOptions.paths) { + config.compilerOptions.paths = typeTsConfig.compilerOptions.paths; + } + } catch { + console.warn('tsconfig.json of type found but failed to parse.'); + } + } + fs.writeFileSync(`tsconfig.types.${processId}.json`, JSON.stringify(config)); fs.writeFileSync(`${processId}.index.ts`, ` -import pak = require('./${definitelyTyped.folder}/types/${dir}/'); +import pak = require('${typePath}/'); import { createMock } from '../dist'; // @ts-ignore createMock(); @@ -134,7 +149,7 @@ createMock(); console.error(error.error); if (error.stdout.trim()) { - errorData += "\n" + error.stdout; + errorData += '\n' + error.stdout; console.error(error.stdout); }