@@ -25,11 +25,9 @@ function resolveFile(source, file, config) {
25
25
}
26
26
27
27
let foundTsPath = null ;
28
- const extensions = Object . keys ( require . extensions ) . concat (
29
- '.ts' ,
30
- '.tsx' ,
31
- '.d.ts' ,
32
- ) ;
28
+ const extensions = Object . keys ( require . extensions ) ;
29
+
30
+ extensions . unshift ( '.ts' , '.tsx' , '.d.ts' ) ;
33
31
34
32
// setup tsconfig-paths
35
33
const searchStart = config . directory || process . cwd ( ) ;
@@ -54,25 +52,28 @@ function resolveFile(source, file, config) {
54
52
55
53
// note that even if we match via tsconfig-paths, we still need to do a final resolve
56
54
let foundNodePath ;
57
- const basedir = path . dirname ( path . resolve ( file ) )
58
55
try {
59
56
foundNodePath = resolve . sync ( foundTsPath || source , {
60
57
extensions,
61
- basedir,
58
+ basedir : path . dirname ( path . resolve ( file ) ) ,
62
59
packageFilter,
63
60
} ) ;
64
61
} catch ( err ) {
65
62
foundNodePath = null ;
66
63
}
67
64
68
- if ( foundNodePath && / \. j s x ? $ / . test ( foundNodePath ) ) {
69
- try {
70
- foundNodePath = resolve . sync ( foundTsPath || source , {
71
- extensions : [ '.d.ts' ] ,
72
- basedir,
73
- packageFilter,
74
- } ) ;
75
- } catch ( err ) { }
65
+ // naive attempt at @types /* resolution,
66
+ // iff path is neither absolute nor relative
67
+ if (
68
+ / \. j s x ? $ / . test ( foundNodePath ) &&
69
+ ! / ^ @ t y p e s [ \/ \\ ] / . test ( source ) &&
70
+ ! path . isAbsolute ( source ) &&
71
+ source [ 0 ] !== '.'
72
+ ) {
73
+ const definitely = resolveFile ( '@types/' + source , file , config ) ;
74
+ if ( definitely . found ) {
75
+ return definitely ;
76
+ }
76
77
}
77
78
78
79
if ( foundNodePath ) {
0 commit comments