44 */
55"use strict" ;
66
7- const Tapable = require ( "tapable-old" ) ;
7+ const Tapable = require ( "tapable" ) . Tapable ;
8+ const HookMap = require ( "tapable" ) . HookMap ;
9+ const SyncHook = require ( "tapable" ) . SyncHook ;
10+ const SyncWaterfallHook = require ( "tapable" ) . SyncWaterfallHook ;
811const Factory = require ( "enhanced-resolve" ) . ResolverFactory ;
912
1013module . exports = class ResolverFactory extends Tapable {
1114 constructor ( ) {
1215 super ( ) ;
16+ this . hooks = {
17+ resolveOptions : new HookMap ( ( ) => new SyncWaterfallHook ( [ "resolveOptions" ] ) ) ,
18+ resolver : new HookMap ( ( ) => new SyncHook ( [ "resolver" , "resolveOptions" ] ) ) ,
19+ } ;
20+ this . _pluginCompat . tap ( "ResolverFactory" , options => {
21+ let match ;
22+ match = / ^ r e s o l v e - o p t i o n s ( .+ ) $ / . exec ( options . name ) ;
23+ if ( match ) {
24+ this . hooks . resolveOptions . tap ( match [ 1 ] , options . fn . name || "unnamed compat plugin" , options . fn ) ;
25+ return true ;
26+ }
27+ match = / ^ r e s o l v e r ( .+ ) $ / . exec ( options . name ) ;
28+ if ( match ) {
29+ this . hooks . resolver . tap ( match [ 1 ] , options . fn . name || "unnamed compat plugin" , options . fn ) ;
30+ return true ;
31+ }
32+ } ) ;
1333 this . cache1 = new WeakMap ( ) ;
1434 this . cache2 = new Map ( ) ;
1535 }
@@ -26,12 +46,12 @@ module.exports = class ResolverFactory extends Tapable {
2646 }
2747
2848 _create ( type , resolveOptions ) {
29- resolveOptions = this . applyPluginsWaterfall ( `resolve-options ${ type } ` , resolveOptions ) ;
49+ resolveOptions = this . hooks . resolveOptions . for ( type ) . call ( resolveOptions ) ;
3050 const resolver = Factory . createResolver ( resolveOptions ) ;
3151 if ( ! resolver ) {
3252 throw new Error ( "No resolver created" ) ;
3353 }
34- this . applyPlugins2 ( ` resolver ${ type } ` , resolver , resolveOptions ) ;
54+ this . hooks . resolver . for ( type ) . call ( resolver , resolveOptions ) ;
3555 return resolver ;
3656 }
3757} ;
0 commit comments