Skip to content

Commit 82d090b

Browse files
rbongJounQin
andauthored
feat: add support for jsconfig.json (#161)
Co-authored-by: JounQin <admin@1stg.me>
1 parent 2c05330 commit 82d090b

File tree

7 files changed

+32
-1
lines changed

7 files changed

+32
-1
lines changed

.changeset/neat-glasses-carry.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-import-resolver-typescript": minor
3+
---
4+
5+
feat: add support for `jsconfig.json`

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",

src/index.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ResolverFactory,
1111
} from 'enhanced-resolve'
1212
import { createPathsMatcher, getTsconfig } from 'get-tsconfig'
13+
import type { TsConfigResult } from 'get-tsconfig'
1314
import isCore from 'is-core-module'
1415
import isGlob from 'is-glob'
1516
import { createSyncFn } from 'synckit'
@@ -333,7 +334,15 @@ function initMappers(options: InternalResolverOptions) {
333334
]
334335

335336
mappers = projectPaths.map(projectPath => {
336-
const tsconfigResult = getTsconfig(projectPath)
337+
let tsconfigResult: TsConfigResult | null
338+
339+
if (isFile(projectPath)) {
340+
const { dir, base } = path.parse(projectPath)
341+
tsconfigResult = getTsconfig(dir, base)
342+
} else {
343+
tsconfigResult = getTsconfig(projectPath)
344+
}
345+
337346
return tsconfigResult && createPathsMatcher(tsconfigResult)
338347
})
339348

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)

tests/withJsconfig/importee.js

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

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'

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)