@@ -96,7 +96,7 @@ export class PathsPlugin implements Tapable {
96
96
aliasPattern = new RegExp ( `^${ excapedAlias } $` ) ;
97
97
} else {
98
98
let withStarCapturing = excapedAlias . replace ( '\\*' , '(.*)' ) ;
99
- aliasPattern = new RegExp ( `^${ withStarCapturing } ` ) ;
99
+ aliasPattern = new RegExp ( `^${ withStarCapturing } $ ` ) ;
100
100
}
101
101
102
102
this . mappings . push ( {
@@ -122,22 +122,38 @@ export class PathsPlugin implements Tapable {
122
122
}
123
123
124
124
resolve ( resolver : ResolverPlugin , mapping : any , request : any , callback : Callback < any > ) : any {
125
+ if ( mapping . alias === '*' ) {
126
+ return callback ( ) ;
127
+ }
128
+
125
129
let innerRequest = getInnerRequest ( resolver , request ) ;
126
130
if ( ! innerRequest ) {
127
131
return callback ( ) ;
128
132
}
129
133
134
+ let newRequestStr : string ;
135
+
136
+ let moduleNames =
137
+ ts . nodeModuleNameResolver ( innerRequest , mapping . alias , this . _compilerOptions , this . _host ) ;
138
+ if ( ! moduleNames . resolvedModule ) {
139
+ callback ( ) ;
140
+ } else {
141
+ newRequestStr = moduleNames . resolvedModule . resolvedFileName ;
142
+ }
143
+
130
144
let match = innerRequest . match ( mapping . aliasPattern ) ;
131
- if ( ! match ) {
145
+ if ( ! match && ! newRequestStr ) {
132
146
return callback ( ) ;
133
147
}
134
148
135
- let newRequestStr = mapping . target ;
136
- if ( ! mapping . onlyModule ) {
137
- newRequestStr = newRequestStr . replace ( '*' , match [ 1 ] ) ;
138
- }
139
- if ( newRequestStr [ 0 ] === '.' ) {
140
- newRequestStr = path . resolve ( this . _absoluteBaseUrl , newRequestStr ) ;
149
+ if ( ! newRequestStr ) {
150
+ newRequestStr = mapping . target ;
151
+ if ( ! mapping . onlyModule ) {
152
+ newRequestStr = newRequestStr . replace ( '*' , match [ 1 ] ) ;
153
+ }
154
+ if ( newRequestStr [ 0 ] === '.' ) {
155
+ newRequestStr = path . resolve ( this . _absoluteBaseUrl , newRequestStr ) ;
156
+ }
141
157
}
142
158
143
159
let newRequest = Object . assign ( { } , request , {
@@ -163,7 +179,7 @@ export class PathsPlugin implements Tapable {
163
179
}
164
180
165
181
createPlugin ( resolver : ResolverPlugin , mapping : any ) : any {
166
- return ( request : any , callback : Callback < any > ) => {
182
+ return ( request : Request , callback : Callback < any > ) => {
167
183
try {
168
184
this . resolve ( resolver , mapping , request , callback ) ;
169
185
} catch ( err ) {
0 commit comments