Skip to content

Commit

Permalink
fix: wrong path resolution in multiple eslintrc configurations (#51)
Browse files Browse the repository at this point in the history
close #50
Co-authored-by: Alex Vasiuro <[email protected]>
  • Loading branch information
avasuro authored Jul 9, 2020
1 parent afbcdec commit d563eeb
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 3 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
"lint:tsc": "tsc --incremental false --noEmit",
"prepublishOnly": "yarn build",
"pretest": "r",
"test": "run-p test:*",
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test": "run-p test:*",
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict"
},
"peerDependencies": {
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ function packageFilter(pkg: Record<string, string>) {
return pkg
}

let mappersBuildForOptions: TsResolverOptions
let mappers:
| Array<(source: string, file: string) => string | undefined>
| undefined
Expand All @@ -133,7 +134,7 @@ function getMappedPath(source: string, file: string) {
}

function initMappers(options: TsResolverOptions) {
if (mappers) {
if (mappers && mappersBuildForOptions === options) {
return
}

Expand Down Expand Up @@ -171,6 +172,8 @@ function initMappers(options: TsResolverOptions) {
return matchPath(source, undefined, undefined, extensions)
}
})

mappersBuildForOptions = options
}

function isConfigLoaderSuccessResult(
Expand Down
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../baseEslintConfig')(__dirname);
15 changes: 15 additions & 0 deletions tests/multipleEslintrcs/module-a/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import relative
import './tsImportee'
import './tsxImportee'
import './subfolder/tsImportee'
import './subfolder/tsxImportee'

// import using tsconfig.json path mapping
import 'folder/tsImportee'
import 'folder/tsxImportee'
import 'folder/subfolder/tsImportee'
import 'folder/subfolder/tsxImportee'

// import from node_module
import 'typescript'
import 'dummy.js'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/subfolder/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/subfolder/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
11 changes: 11 additions & 0 deletions tests/multipleEslintrcs/module-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react",
"paths": {
"folder/*": ["*"],
"*": ["../../../../node_modules/*"]
}
},
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
}
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-a/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../baseEslintConfig')(__dirname);
15 changes: 15 additions & 0 deletions tests/multipleEslintrcs/module-b/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import relative
import './tsImportee'
import './tsxImportee'
import './subfolder/tsImportee'
import './subfolder/tsxImportee'

// import using tsconfig.json path mapping
import 'folder/tsImportee'
import 'folder/tsxImportee'
import 'folder/subfolder/tsImportee'
import 'folder/subfolder/tsxImportee'

// import from node_module
import 'typescript'
import 'dummy.js'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/subfolder/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/subfolder/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/tsImportee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'yes'
11 changes: 11 additions & 0 deletions tests/multipleEslintrcs/module-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"jsx": "react",
"paths": {
"folder/*": ["*"],
"*": ["../../../../node_modules/*"]
}
},
"files": ["index.ts", "tsImportee.ts", "tsxImportee.tsx"]
}
1 change: 1 addition & 0 deletions tests/multipleEslintrcs/module-b/tsxImportee.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'React Component'

0 comments on commit d563eeb

Please sign in to comment.