Skip to content

Commit

Permalink
fix: 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 d63e632
Show file tree
Hide file tree
Showing 6 changed files with 27 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
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": {
"#/*": ["*"]
}
}
}

0 comments on commit d63e632

Please sign in to comment.