Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmckeb committed Sep 28, 2021
1 parent a316041 commit 70c0510
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 58 deletions.
57 changes: 27 additions & 30 deletions src/ExportMap.js
@@ -1,5 +1,5 @@
import fs from 'fs';
import path from 'path';
import { dirname } from 'path';

import doctrine from 'doctrine';

Expand Down Expand Up @@ -517,6 +517,32 @@ ExportMap.parse = function (path, content, context) {

const source = makeSourceCode(content, ast);

function readTsConfig() {
const tsConfigInfo = tsConfigLoader({
cwd:
(context.parserOptions && context.parserOptions.tsconfigRootDir) ||
process.cwd(),
getEnv: (key) => process.env[key],
});
try {
if (tsConfigInfo.tsConfigPath !== undefined) {
// 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,
dirname(tsConfigInfo.tsConfigPath),
);
}
} catch (e) {
// Catch any errors
}

return null;
}

function isEsModuleInterop() {
const cacheKey = hashObject({
tsconfigRootDir: context.parserOptions && context.parserOptions.tsconfigRootDir,
Expand Down Expand Up @@ -763,32 +789,3 @@ function makeSourceCode(text, ast) {
return new SourceCode({ text, ast });
}
}

/**
* Returns a project's TypeScript configuration.
*/
export function readTsConfig(context) {
const tsConfigInfo = tsConfigLoader({
cwd:
(context.parserOptions && context.parserOptions.tsconfigRootDir) ||
process.cwd(),
getEnv: (key) => process.env[key],
});
try {
if (tsConfigInfo.tsConfigPath !== undefined) {
// 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,
path.dirname(tsConfigInfo.tsConfigPath),
);
}
} catch (e) {
// Catch any errors
}

return null;
}
3 changes: 3 additions & 0 deletions tests/files/typescript-extended-config/index.d.ts
@@ -0,0 +1,3 @@
export = FooBar;

declare namespace FooBar {}
5 changes: 1 addition & 4 deletions tests/files/typescript-extended-config/tsconfig.base.json
@@ -1,8 +1,5 @@
{
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"strict": true
"esModuleInterop": true
}
}
4 changes: 1 addition & 3 deletions tests/files/typescript-extended-config/tsconfig.json
@@ -1,6 +1,4 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true
}
"compilerOptions": {}
}
21 changes: 0 additions & 21 deletions tests/src/ExportMap.js

This file was deleted.

11 changes: 11 additions & 0 deletions tests/src/rules/default.js
Expand Up @@ -231,6 +231,17 @@ context('TypeScript', function () {
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-export-react-test-renderer/'),
},
}),
test({
code: `import Foo from "./typescript-extended-config"`,
parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
parserOptions: {
tsconfigRootDir: path.resolve(__dirname, '../../files/typescript-extended-config/'),
},
}),
test({
code: `import foobar from "./typescript-export-assign-property"`,
parser,
Expand Down

0 comments on commit 70c0510

Please sign in to comment.