File tree 2 files changed +19
-8
lines changed
2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -362,18 +362,25 @@ function getMappedPaths(
362
362
const isJs = JS_EXT_PATTERN . test ( source )
363
363
if ( isJs ) {
364
364
const jsExt = path . extname ( source )
365
+ // cjs -> cts, js -> ts, jsx -> tsx, mjs -> mts
365
366
const tsExt = jsExt . replace ( 'js' , 'ts' )
367
+
366
368
const basename = source . replace ( JS_EXT_PATTERN , '' )
367
369
368
- const mappedPaths = getMappedPaths ( basename + tsExt , file )
370
+ let resolved = getMappedPaths ( basename + tsExt , file )
369
371
370
- const resolved =
371
- mappedPaths . length > 0
372
- ? mappedPaths
373
- : getMappedPaths (
374
- basename + '.d' + ( tsExt === '.tsx' ? '.ts' : tsExt ) ,
375
- file ,
376
- )
372
+ if ( resolved . length === 0 && jsExt === '.js' ) {
373
+ // js -> tsx
374
+ const tsxExt = jsExt . replace ( 'js' , 'tsx' )
375
+ resolved = getMappedPaths ( basename + tsxExt , file )
376
+ }
377
+
378
+ if ( resolved . length === 0 ) {
379
+ resolved = getMappedPaths (
380
+ basename + '.d' + ( tsExt === '.tsx' ? '.ts' : tsExt ) ,
381
+ file ,
382
+ )
383
+ }
377
384
378
385
if ( resolved . length > 0 ) {
379
386
return resolved
Original file line number Diff line number Diff line change @@ -6,9 +6,13 @@ import './subfolder/tsxImportee'
6
6
7
7
// import using tsconfig.json path mapping
8
8
import 'folder/tsImportee'
9
+ import 'folder/tsImportee.js'
9
10
import 'folder/tsxImportee'
11
+ import 'folder/tsxImportee.js'
10
12
import 'folder/subfolder/tsImportee'
13
+ import 'folder/subfolder/tsImportee.js'
11
14
import 'folder/subfolder/tsxImportee'
15
+ import 'folder/subfolder/tsxImportee.js'
12
16
13
17
// import module with typings set in package.json
14
18
import 'folder/module'
You can’t perform that action at this time.
0 commit comments