Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for jsconfig.json #161

Merged
merged 2 commits into from Aug 1, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/neat-glasses-carry.md
@@ -0,0 +1,5 @@
---
"eslint-import-resolver-typescript": minor
---

feat: add support for `jsconfig.json`
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
11 changes: 10 additions & 1 deletion src/index.ts
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
@@ -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": {
"#/*": ["*"]
}
}
}