diff --git a/src/ExportMap.js b/src/ExportMap.js index 53091e4668..b758d0f09c 100644 --- a/src/ExportMap.js +++ b/src/ExportMap.js @@ -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'); @@ -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 @@ -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) {