Skip to content

Commit

Permalink
Resolve extended TypeScript configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb committed Sep 28, 2021
1 parent dd81424 commit 96de64b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/ExportMap.js
Expand Up @@ -18,7 +18,7 @@ import { tsConfigLoader } from 'tsconfig-paths/lib/tsconfig-loader';

import includes from 'array-includes';

let parseConfigFileTextToJson;
let ts;

const log = debug('eslint-plugin-import:ExportMap');

Expand Down Expand Up @@ -525,12 +525,15 @@ ExportMap.parse = function (path, content, context) {
});
try {
if (tsConfigInfo.tsConfigPath !== undefined) {
const jsonText = fs.readFileSync(tsConfigInfo.tsConfigPath).toString();
if (!parseConfigFileTextToJson) {
// this is because projects not using TypeScript won't have typescript installed
({ parseConfigFileTextToJson } = require('typescript'));
}
return parseConfigFileTextToJson(tsConfigInfo.tsConfigPath, jsonText).config;
// Projects not using TypeScript won't have `typescript` installed.
if (!ts) (ts = require('typescript'));

const configFile = ts.readConfigFile(tsConfigInfo.tsConfigPath, ts.sys.readFile);
return ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
tsConfigInfo.tsConfigPath,
);
}
} catch (e) {
// Catch any errors
Expand All @@ -549,7 +552,7 @@ ExportMap.parse = function (path, content, context) {
tsConfigCache.set(cacheKey, tsConfig);
}

return tsConfig && tsConfig.compilerOptions ? tsConfig.compilerOptions.esModuleInterop : false;
return tsConfig && tsConfig.options ? tsConfig.options.esModuleInterop : false;
}

ast.body.forEach(function (n) {
Expand Down

0 comments on commit 96de64b

Please sign in to comment.