diff --git a/.size-limit.json b/.size-limit.json index 648747e..bdf7573 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -1,6 +1,6 @@ [ { "path": "./lib/index.js", - "limit": "3.1kB" + "limit": "3.2kB" } ] diff --git a/CHANGELOG.md b/CHANGELOG.md index f2183de..9c06004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 3.8.6 + +### Patch Changes + +- [#374](https://github.com/import-js/eslint-import-resolver-typescript/pull/374) [`c9d5ab0`](https://github.com/import-js/eslint-import-resolver-typescript/commit/c9d5ab0fa963bd891b6f2ae312ae3ec10a397b7c) Thanks [@JounQin](https://github.com/JounQin)! - fix: add support for importing with .js extension as tsx importee + ## 3.8.5 ### Patch Changes diff --git a/package.json b/package.json index 86e5374..8d601b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-import-resolver-typescript", - "version": "3.8.5", + "version": "3.8.6", "type": "module", "description": "This plugin adds `TypeScript` support to `eslint-plugin-import`", "repository": "git+https://github.com/import-js/eslint-import-resolver-typescript", diff --git a/src/index.ts b/src/index.ts index b774b3c..c5a8822 100644 --- a/src/index.ts +++ b/src/index.ts @@ -362,18 +362,25 @@ function getMappedPaths( const isJs = JS_EXT_PATTERN.test(source) if (isJs) { const jsExt = path.extname(source) + // cjs -> cts, js -> ts, jsx -> tsx, mjs -> mts const tsExt = jsExt.replace('js', 'ts') + const basename = source.replace(JS_EXT_PATTERN, '') - const mappedPaths = getMappedPaths(basename + tsExt, file) + let resolved = getMappedPaths(basename + tsExt, file) - const resolved = - mappedPaths.length > 0 - ? mappedPaths - : getMappedPaths( - basename + '.d' + (tsExt === '.tsx' ? '.ts' : tsExt), - file, - ) + if (resolved.length === 0 && jsExt === '.js') { + // js -> tsx + const tsxExt = jsExt.replace('js', 'tsx') + resolved = getMappedPaths(basename + tsxExt, file) + } + + if (resolved.length === 0) { + resolved = getMappedPaths( + basename + '.d' + (tsExt === '.tsx' ? '.ts' : tsExt), + file, + ) + } if (resolved.length > 0) { return resolved diff --git a/tests/withPaths/index.ts b/tests/withPaths/index.ts index 594e79d..696bf40 100644 --- a/tests/withPaths/index.ts +++ b/tests/withPaths/index.ts @@ -6,9 +6,13 @@ import './subfolder/tsxImportee' // import using tsconfig.json path mapping import 'folder/tsImportee' +import 'folder/tsImportee.js' import 'folder/tsxImportee' +import 'folder/tsxImportee.js' import 'folder/subfolder/tsImportee' +import 'folder/subfolder/tsImportee.js' import 'folder/subfolder/tsxImportee' +import 'folder/subfolder/tsxImportee.js' // import module with typings set in package.json import 'folder/module'