Skip to content

Commit 9569460

Browse files
committed
fix: add support for tsconfig.json paths imports with .js extension for tsx importee
1 parent ca11f1c commit 9569460

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,12 @@ function getMappedPath(
306306
if (isJs) {
307307
const jsExt = path.extname(source)
308308
const tsExt = jsExt.replace('js', 'ts')
309+
const tsxExt = jsExt.replace('js', 'tsx')
309310
const basename = source.replace(JS_EXT_PATTERN, '')
310311

311312
const resolved =
312313
getMappedPath(basename + tsExt, file) ||
314+
getMappedPath(basename + tsxExt, file) ||
313315
getMappedPath(
314316
basename + '.d' + (tsExt === '.tsx' ? '.ts' : tsExt),
315317
file,

tests/withPaths/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import './subfolder/tsxImportee'
66

77
// import using tsconfig.json path mapping
88
import 'folder/tsImportee'
9+
import 'folder/tsImportee.js'
910
import 'folder/tsxImportee'
11+
import 'folder/tsxImportee.js'
1012
import 'folder/subfolder/tsImportee'
13+
import 'folder/subfolder/tsImportee.js'
1114
import 'folder/subfolder/tsxImportee'
15+
import 'folder/subfolder/tsxImportee.js'
1216

1317
// import module with typings set in package.json
1418
import 'folder/module'

0 commit comments

Comments
 (0)