Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-glasses-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": minor
---

feat: add support for `jsconfig.json`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ResolverFactory,
} from 'enhanced-resolve'
import { createPathsMatcher, getTsconfig } from 'get-tsconfig'
import type { TsConfigResult } from 'get-tsconfig'
import isCore from 'is-core-module'
import isGlob from 'is-glob'
import { createSyncFn } from 'synckit'
Expand Down Expand Up @@ -333,7 +334,15 @@ function initMappers(options: InternalResolverOptions) {
]

mappers = projectPaths.map(projectPath => {
const tsconfigResult = getTsconfig(projectPath)
let tsconfigResult: TsConfigResult | null

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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 'importee'
2 changes: 2 additions & 0 deletions tests/withJsconfig/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// import using jsconfig.json path mapping
import '#/importee'
8 changes: 8 additions & 0 deletions tests/withJsconfig/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"#/*": ["*"]
}
}
}