Skip to content

Commit

Permalink
Add support for jsconfig.json (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbong committed Aug 1, 2022
1 parent 65bed89 commit 3155a4e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -82,6 +82,7 @@
"test": "run-p test:*",
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test:withJsconfig": "eslint --ext js tests/withJsconfig",
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Expand Up @@ -333,7 +333,15 @@ function initMappers(options: InternalResolverOptions) {
]

mappers = projectPaths.map(projectPath => {
const tsconfigResult = getTsconfig(projectPath)
let tsconfigResult

if (isFile(projectPath)) {
const { dir, base } = path.parse(projectPath)
tsconfigResult = getTsconfig(dir, base)
} else {
tsconfigResult = getTsconfig(projectPath)
}

return tsconfigResult && createPathsMatcher(tsconfigResult)
})

Expand Down
5 changes: 5 additions & 0 deletions tests/withJsconfig/.eslintrc.cjs
@@ -0,0 +1,5 @@
const path = require('path')

const configPath = path.join(__dirname, 'jsconfig.json')

module.exports = require('../baseEslintConfig.cjs')(configPath)
1 change: 1 addition & 0 deletions tests/withJsconfig/importee.js
@@ -0,0 +1 @@
export default 'importee'
2 changes: 2 additions & 0 deletions tests/withJsconfig/index.js
@@ -0,0 +1,2 @@
// import using jsconfig.json path mapping
import '#/importee'
8 changes: 8 additions & 0 deletions tests/withJsconfig/jsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"#/*": ["*"]
}
}
}

0 comments on commit 3155a4e

Please sign in to comment.