@@ -20,7 +20,7 @@ export function resolveWithPaths(
20
20
host : ts . CompilerHost ,
21
21
cache ?: ts . ModuleResolutionCache ,
22
22
) {
23
- if ( ! request ) {
23
+ if ( ! request || ! request . request ) {
24
24
callback ( null , request ) ;
25
25
return ;
26
26
}
@@ -31,6 +31,26 @@ export function resolveWithPaths(
31
31
return ;
32
32
}
33
33
34
+ // check if any path mapping rules are relevant
35
+ const isPathMapped = compilerOptions . paths && Object . keys ( compilerOptions . paths )
36
+ . some ( pattern => {
37
+ // can only contain zero or one
38
+ const starIndex = pattern . indexOf ( '*' ) ;
39
+ if ( starIndex === - 1 ) {
40
+ return pattern === request . request ;
41
+ } else if ( starIndex === pattern . length - 1 ) {
42
+ return request . request . startsWith ( pattern . slice ( 0 , - 1 ) ) ;
43
+ } else {
44
+ const [ prefix , suffix ] = pattern . split ( '*' ) ;
45
+ return request . request . startsWith ( prefix ) && request . request . endsWith ( suffix ) ;
46
+ }
47
+ } ) ;
48
+
49
+ if ( ! isPathMapped ) {
50
+ callback ( null , request ) ;
51
+ return ;
52
+ }
53
+
34
54
const moduleResolver = ts . resolveModuleName (
35
55
request . request ,
36
56
request . contextInfo . issuer ,
@@ -64,40 +84,6 @@ export function resolveWithPaths(
64
84
return ;
65
85
}
66
86
67
- // TypeScript gives `index.ts` and the request is not for the specific file,
68
- // check if it is a module
69
- const requestFilePath = path . basename ( request . request ) ;
70
- if ( path . basename ( moduleFilePath ) === 'index.ts'
71
- && requestFilePath !== 'index' && requestFilePath !== 'index.ts' ) {
72
- const packageRootPath = path . join ( path . dirname ( moduleFilePath ) , 'package.json' ) ;
73
- if ( host . fileExists ( packageRootPath ) ) {
74
- // potential module request
75
- let isPathMapped = false ;
76
- if ( compilerOptions . paths ) {
77
- // check if any path mapping rules are relevant
78
- isPathMapped = Object . keys ( compilerOptions . paths )
79
- . some ( pattern => {
80
- // can only contain zero or one
81
- const starIndex = pattern . indexOf ( '*' ) ;
82
- if ( starIndex === - 1 ) {
83
- return pattern === request . request ;
84
- } else if ( starIndex === pattern . length - 1 ) {
85
- return request . request . startsWith ( pattern . slice ( 0 , - 1 ) ) ;
86
- } else {
87
- const [ prefix , suffix ] = pattern . split ( '*' ) ;
88
- return request . request . startsWith ( prefix ) && request . request . endsWith ( suffix ) ;
89
- }
90
- } ) ;
91
- }
92
- if ( ! isPathMapped ) {
93
- // path mapping not involved, let webpack handle the module request
94
- request . request = path . dirname ( moduleFilePath ) ;
95
- callback ( null , request ) ;
96
- return ;
97
- }
98
- }
99
- }
100
-
101
87
request . request = moduleFilePath ;
102
88
callback ( null , request ) ;
103
89
}
0 commit comments