Skip to content

Commit

Permalink
fix(definitelyTyped): copy compiler option "paths" from processed type (
Browse files Browse the repository at this point in the history
  • Loading branch information
Pmyl authored Jan 16, 2020
1 parent acd2c6f commit 6265fde
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions definitelyTypedTests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof pak>();
Expand Down Expand Up @@ -134,7 +149,7 @@ createMock<typeof pak>();
console.error(error.error);

if (error.stdout.trim()) {
errorData += "\n" + error.stdout;
errorData += '\n' + error.stdout;
console.error(error.stdout);
}

Expand Down

0 comments on commit 6265fde

Please sign in to comment.