@@ -7,31 +7,33 @@ const pluginName = "ResolveTypescriptPlugin";
77export default class ResolveTypescriptPlugin {
88 public apply ( resolver : Resolver ) : void {
99 const target = resolver . ensureHook ( "file" ) ;
10- resolver . getHook ( "raw-file" ) . tapAsync ( pluginName , ( request , resolveContext , callback ) => {
11- if ( ! request . path || request . path . match ( / ( ^ | [ \\ / ] ) n o d e _ m o d u l e s ( $ | [ \\ / ] ) / ) ) {
12- return callback ( ) ;
13- }
10+ for ( const extension of [ ".ts" , ".tsx" ] ) {
11+ resolver
12+ . getHook ( "raw-file" )
13+ . tapAsync ( pluginName , ( request , resolveContext , callback ) => {
14+ if ( ! request . path || request . path . match ( / ( ^ | [ \\ / ] ) n o d e _ m o d u l e s ( $ | [ \\ / ] ) / ) ) {
15+ return callback ( ) ;
16+ }
1417
15- const path = request . path . replace ( / \. j s $ / , "" ) ;
16- if ( path === request . path ) {
17- callback ( ) ;
18- } else {
19- for ( const extension of [ ".ts" , ".tsx" ] ) {
20- resolver . doResolve (
21- target ,
22- {
23- ...request ,
24- path : `${ path } ${ extension } ` ,
25- relativePath :
26- request . relativePath &&
27- request . relativePath . replace ( / \. j s $ / , extension )
28- } ,
29- `using path: ${ path } ` ,
30- resolveContext ,
31- callback
32- ) ;
33- }
34- }
35- } ) ;
18+ const path = request . path . replace ( / \. j s $ / , extension ) ;
19+ if ( path === request . path ) {
20+ callback ( ) ;
21+ } else {
22+ resolver . doResolve (
23+ target ,
24+ {
25+ ...request ,
26+ path,
27+ relativePath :
28+ request . relativePath &&
29+ request . relativePath . replace ( / \. j s $ / , extension )
30+ } ,
31+ `using path: ${ path } ` ,
32+ resolveContext ,
33+ callback
34+ ) ;
35+ }
36+ } ) ;
37+ }
3638 }
3739}
0 commit comments