Skip to content

Commit

Permalink
fix: don't ignore the tsconfig file name in project paths or path pat…
Browse files Browse the repository at this point in the history
…terns

`getTsConfig` treats every path as a directory and looks for a `tsconfig.json` in the closest parent directory

this breaks any configuration that uses file names other than tsconfig.json, as is convention for [solution-style](https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig) tsconfigs, which is exacerbated by the lack of support for the `references` field (see import-js#94)
  • Loading branch information
line0 committed Jul 6, 2022
1 parent 2ec7aaf commit a1d87b7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
"test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring",
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
"test:nonDefaultTsconfigFileName": "eslint --ext ts,tsx tests/nonDefaultTsconfigFileName",
"typecov": "type-coverage"
},
"peerDependencies": {
Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Resolver,
ResolverFactory,
} from 'enhanced-resolve'
import { createPathsMatcher, getTsconfig } from 'get-tsconfig'
import { createPathsMatcher, getTsconfig, parseTsconfig } from 'get-tsconfig'
import isCore from 'is-core-module'
import isGlob from 'is-glob'
import { createSyncFn } from 'synckit'
Expand Down Expand Up @@ -350,7 +350,10 @@ function initMappers(options: TsResolverOptions) {
]

mappers = projectPaths.map(projectPath => {
const tsconfigResult = getTsconfig(projectPath)
const tsconfigResult =
fs.existsSync(projectPath) && fs.statSync(projectPath).isFile()
? { path: projectPath, config: parseTsconfig(projectPath) }
: getTsconfig(projectPath)
return tsconfigResult && createPathsMatcher(tsconfigResult)
})

Expand Down
5 changes: 5 additions & 0 deletions tests/nonDefaultTsconfigFileName/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const path = require('path')

module.exports = require('../baseEslintConfig.cjs')(
path.join(__dirname, 'tsconfig.custom.json'),
)
2 changes: 2 additions & 0 deletions tests/nonDefaultTsconfigFileName/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// import using tsconfig.json path mapping
import 'folder/tsImportee'
1 change: 1 addition & 0 deletions tests/nonDefaultTsconfigFileName/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
9 changes: 9 additions & 0 deletions tests/nonDefaultTsconfigFileName/tsconfig.custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"folder/*": ["*"],
}
},
"files": ["index.ts", "tsImportee.ts"]
}

0 comments on commit a1d87b7

Please sign in to comment.