Skip to content

Commit

Permalink
read tsconfig as tsc does
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok committed Jun 6, 2020
1 parent 77e1791 commit dae3cd3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/ExportMap.js
Expand Up @@ -17,6 +17,8 @@ import { tsConfigLoader } from 'tsconfig-paths/lib/tsconfig-loader'

import includes from 'array-includes'

import {parseConfigFileTextToJson} from 'typescript'

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

const exportCache = new Map()
Expand Down Expand Up @@ -450,14 +452,15 @@ ExportMap.parse = function (path, content, context) {
const source = makeSourceCode(content, ast)

function isEsModuleInterop() {
const tsConfig = tsConfigLoader({
const tsConfigInfo = tsConfigLoader({
cwd: context.parserOptions && context.parserOptions.tsconfigRootDir || process.cwd(),
getEnv: (key) => process.env[key],
})
try {
if (tsConfig.tsConfigPath !== undefined) {
const json = fs.readFileSync(tsConfig.tsConfigPath)
return JSON.parse(json).compilerOptions.esModuleInterop
if (tsConfigInfo.tsConfigPath !== undefined) {
const jsonText = fs.readFileSync(tsConfigInfo.tsConfigPath).toString()
const tsConfig = parseConfigFileTextToJson(tsConfigInfo.tsConfigPath, jsonText).config
return tsConfig.compilerOptions.esModuleInterop
}
} catch (e) {
return false
Expand Down Expand Up @@ -565,10 +568,13 @@ ExportMap.parse = function (path, content, context) {
'TSAbstractClassDeclaration',
'TSModuleDeclaration',
]
const exportedDecls = ast.body.filter(({ type, id, declarations }) => includes(declTypes, type) && (
(id && id.name === exportedName) ||
(declarations && declarations.find(d => d.id.name === exportedName))
))
const exportedDecls = ast.body.filter(
({ type, id, declarations }) =>
includes(declTypes, type) &&
((id && id.name === exportedName) ||
(declarations &&
declarations.find((d) => d.id.name === exportedName)))
)
if (exportedDecls.length === 0) {
// Export is not referencing any local declaration, must be re-exporting
m.namespace.set('default', captureDoc(source, docStyleParsers, n))
Expand Down

0 comments on commit dae3cd3

Please sign in to comment.