Skip to content

Commit d563eeb

Browse files
authored
fix: wrong path resolution in multiple eslintrc configurations (#51)
close #50 Co-authored-by: Alex Vasiuro <avasuro@Mac-mini-Alex.local>
1 parent afbcdec commit d563eeb

16 files changed

+69
-3
lines changed

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
"lint:tsc": "tsc --incremental false --noEmit",
3636
"prepublishOnly": "yarn build",
3737
"pretest": "r",
38+
"test": "run-p test:*",
39+
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
40+
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
3841
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
3942
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
40-
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
41-
"test": "run-p test:*",
4243
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict"
4344
},
4445
"peerDependencies": {

src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function packageFilter(pkg: Record<string, string>) {
111111
return pkg
112112
}
113113

114+
let mappersBuildForOptions: TsResolverOptions
114115
let mappers:
115116
| Array<(source: string, file: string) => string | undefined>
116117
| undefined
@@ -133,7 +134,7 @@ function getMappedPath(source: string, file: string) {
133134
}
134135

135136
function initMappers(options: TsResolverOptions) {
136-
if (mappers) {
137+
if (mappers && mappersBuildForOptions === options) {
137138
return
138139
}
139140

@@ -171,6 +172,8 @@ function initMappers(options: TsResolverOptions) {
171172
return matchPath(source, undefined, undefined, extensions)
172173
}
173174
})
175+
176+
mappersBuildForOptions = options
174177
}
175178

176179
function isConfigLoaderSuccessResult(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../baseEslintConfig')(__dirname);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// import relative
2+
import './tsImportee'
3+
import './tsxImportee'
4+
import './subfolder/tsImportee'
5+
import './subfolder/tsxImportee'
6+
7+
// import using tsconfig.json path mapping
8+
import 'folder/tsImportee'
9+
import 'folder/tsxImportee'
10+
import 'folder/subfolder/tsImportee'
11+
import 'folder/subfolder/tsxImportee'
12+
13+
// import from node_module
14+
import 'typescript'
15+
import 'dummy.js'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'yes'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'React Component'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'yes'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"jsx": "react",
5+
"paths": {
6+
"folder/*": ["*"],
7+
"*": ["../../../../node_modules/*"]
8+
}
9+
},
10+
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'React Component'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../baseEslintConfig')(__dirname);
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// import relative
2+
import './tsImportee'
3+
import './tsxImportee'
4+
import './subfolder/tsImportee'
5+
import './subfolder/tsxImportee'
6+
7+
// import using tsconfig.json path mapping
8+
import 'folder/tsImportee'
9+
import 'folder/tsxImportee'
10+
import 'folder/subfolder/tsImportee'
11+
import 'folder/subfolder/tsxImportee'
12+
13+
// import from node_module
14+
import 'typescript'
15+
import 'dummy.js'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'yes'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'React Component'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'yes'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"jsx": "react",
5+
"paths": {
6+
"folder/*": ["*"],
7+
"*": ["../../../../node_modules/*"]
8+
}
9+
},
10+
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'React Component'

0 commit comments

Comments
 (0)