From 3155a4e3353cdb5493eff05af229c3a922b00201 Mon Sep 17 00:00:00 2001 From: Roger Bongers Date: Mon, 1 Aug 2022 10:13:41 -0400 Subject: [PATCH] Add support for jsconfig.json (#73) --- package.json | 1 + src/index.ts | 10 +++++++++- tests/withJsconfig/.eslintrc.cjs | 5 +++++ tests/withJsconfig/importee.js | 1 + tests/withJsconfig/index.js | 2 ++ tests/withJsconfig/jsconfig.json | 8 ++++++++ 6 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/withJsconfig/.eslintrc.cjs create mode 100644 tests/withJsconfig/importee.js create mode 100644 tests/withJsconfig/index.js create mode 100644 tests/withJsconfig/jsconfig.json diff --git a/package.json b/package.json index a7c1ee6..0806f33 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 4404230..30700df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -333,7 +333,15 @@ function initMappers(options: InternalResolverOptions) { ] mappers = projectPaths.map(projectPath => { - const tsconfigResult = getTsconfig(projectPath) + let tsconfigResult + + if (isFile(projectPath)) { + const { dir, base } = path.parse(projectPath) + tsconfigResult = getTsconfig(dir, base) + } else { + tsconfigResult = getTsconfig(projectPath) + } + return tsconfigResult && createPathsMatcher(tsconfigResult) }) diff --git a/tests/withJsconfig/.eslintrc.cjs b/tests/withJsconfig/.eslintrc.cjs new file mode 100644 index 0000000..f20d5d2 --- /dev/null +++ b/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) diff --git a/tests/withJsconfig/importee.js b/tests/withJsconfig/importee.js new file mode 100644 index 0000000..cb43be0 --- /dev/null +++ b/tests/withJsconfig/importee.js @@ -0,0 +1 @@ +export default 'importee' diff --git a/tests/withJsconfig/index.js b/tests/withJsconfig/index.js new file mode 100644 index 0000000..7e44c56 --- /dev/null +++ b/tests/withJsconfig/index.js @@ -0,0 +1,2 @@ +// import using jsconfig.json path mapping +import '#/importee' diff --git a/tests/withJsconfig/jsconfig.json b/tests/withJsconfig/jsconfig.json new file mode 100644 index 0000000..a06fc56 --- /dev/null +++ b/tests/withJsconfig/jsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "baseUrl": "./", + "paths": { + "#/*": ["*"] + } + } +}