Skip to content

Commit b4a6ef3

Browse files
committed
refactor: export the whole tsconfig instead
1 parent 84b8982 commit b4a6ef3

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

resolvers/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ an object provided via the `import/resolver` setting. `my-cool-resolver` will ge
6060

6161
Please view [ESLint Context] for more details.
6262

63-
##### `options.tsCompilerOptions`
63+
##### `options.tsconfig`
6464

6565
**Only available after `[email protected]`**
6666

67-
Please view [TSConfig Compiler Options] for more details.
67+
Please view [TSConfig] and [ParsedCommandLine] for more details.
6868

6969
#### Return value
7070

@@ -97,4 +97,5 @@ exports.resolve = function (source, file, config) {
9797
[Node resolver]: ./node/index.js
9898
[`resolve`]: https://www.npmjs.com/package/resolve
9999
[ESLint Context]: https://eslint.org/docs/latest/developer-guide/working-with-rules#the-context-object
100-
[TSConfig Compiler Options]: https://www.typescriptlang.org/tsconfig#compilerOptions
100+
[TSConfig]: https://www.typescriptlang.org/tsconfig
101+
[ParsedCommandLine]: https://github.com/microsoft/TypeScript/blob/fd3a84c3f0c80cb201c47399a055625f919a9b91/lib/typescriptServices.d.ts#L3168-L3178

src/ExportMap.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let ts;
2424
const log = debug('eslint-plugin-import:ExportMap');
2525

2626
const exportCache = new Map();
27-
const tsConfigCache = new Map();
27+
const tsconfigCache = new Map();
2828

2929
export default class ExportMap {
3030
constructor(path) {
@@ -361,14 +361,14 @@ ExportMap.for = function (context) {
361361

362362
ExportMap.parse = function (path, content, context) {
363363
const m = new ExportMap(path);
364-
const tsCompilerOptions = getTsCompilerOptions();
364+
const tsconfig = getTsconfig();
365365

366-
const isEsModuleInteropTrue = !!tsCompilerOptions.esModuleInterop;
366+
const isEsModuleInteropTrue = !!(tsconfig && tsconfig.options && tsconfig.options.esModuleInterop);
367367

368368
let ast;
369369
let visitorKeys;
370370
try {
371-
const result = parse(path, content, context, { tsCompilerOptions });
371+
const result = parse(path, content, context, { tsconfig });
372372
ast = result.ast;
373373
visitorKeys = result.visitorKeys;
374374
} catch (err) {
@@ -550,22 +550,22 @@ ExportMap.parse = function (path, content, context) {
550550
const source = makeSourceCode(content, ast);
551551

552552
function readTsConfig() {
553-
const tsConfigInfo = tsConfigLoader({
553+
const tsconfigInfo = tsConfigLoader({
554554
cwd:
555555
(context.parserOptions && context.parserOptions.tsconfigRootDir) ||
556556
process.cwd(),
557557
getEnv: (key) => process.env[key],
558558
});
559559
try {
560-
if (tsConfigInfo.tsConfigPath !== undefined) {
560+
if (tsconfigInfo.tsConfigPath !== undefined) {
561561
// Projects not using TypeScript won't have `typescript` installed.
562562
if (!ts) { ts = require('typescript'); }
563563

564-
const configFile = ts.readConfigFile(tsConfigInfo.tsConfigPath, ts.sys.readFile);
564+
const configFile = ts.readConfigFile(tsconfigInfo.tsConfigPath, ts.sys.readFile);
565565
return ts.parseJsonConfigFileContent(
566566
configFile.config,
567567
ts.sys,
568-
dirname(tsConfigInfo.tsConfigPath),
568+
dirname(tsconfigInfo.tsConfigPath),
569569
);
570570
}
571571
} catch (e) {
@@ -575,17 +575,17 @@ ExportMap.parse = function (path, content, context) {
575575
return null;
576576
}
577577

578-
function getTsCompilerOptions() {
578+
function getTsconfig() {
579579
const cacheKey = hashObject({
580580
tsconfigRootDir: context.parserOptions && context.parserOptions.tsconfigRootDir,
581581
}).digest('hex');
582-
let tsConfig = tsConfigCache.get(cacheKey);
583-
if (typeof tsConfig === 'undefined') {
584-
tsConfig = readTsConfig(context);
585-
tsConfigCache.set(cacheKey, tsConfig);
582+
let tsconfig = tsconfigCache.get(cacheKey);
583+
if (typeof tsconfig === 'undefined') {
584+
tsconfig = readTsConfig(context);
585+
tsconfigCache.set(cacheKey, tsconfig);
586586
}
587587

588-
return tsConfig && tsConfig.options || {};
588+
return tsconfig;
589589
}
590590

591591
ast.body.forEach(function (n) {

0 commit comments

Comments
 (0)