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