Skip to content

Commit 3155a4e

Browse files
committed
Add support for jsconfig.json (#73)
1 parent 65bed89 commit 3155a4e

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"test": "run-p test:*",
8383
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
8484
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
85+
"test:withJsconfig": "eslint --ext js tests/withJsconfig",
8586
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
8687
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
8788
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",

Diff for: src/index.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,15 @@ function initMappers(options: InternalResolverOptions) {
333333
]
334334

335335
mappers = projectPaths.map(projectPath => {
336-
const tsconfigResult = getTsconfig(projectPath)
336+
let tsconfigResult
337+
338+
if (isFile(projectPath)) {
339+
const { dir, base } = path.parse(projectPath)
340+
tsconfigResult = getTsconfig(dir, base)
341+
} else {
342+
tsconfigResult = getTsconfig(projectPath)
343+
}
344+
337345
return tsconfigResult && createPathsMatcher(tsconfigResult)
338346
})
339347

Diff for: tests/withJsconfig/.eslintrc.cjs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const path = require('path')
2+
3+
const configPath = path.join(__dirname, 'jsconfig.json')
4+
5+
module.exports = require('../baseEslintConfig.cjs')(configPath)

Diff for: tests/withJsconfig/importee.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 'importee'

Diff for: tests/withJsconfig/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// import using jsconfig.json path mapping
2+
import '#/importee'

Diff for: tests/withJsconfig/jsconfig.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "./",
4+
"paths": {
5+
"#/*": ["*"]
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)