Skip to content

Commit 53eada6

Browse files
committed
upgrade tapable for ResolverFactory
1 parent 3f453a4 commit 53eada6

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

‎lib/ResolverFactory.js‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,32 @@
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;
811
const Factory = require("enhanced-resolve").ResolverFactory;
912

1013
module.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 = /^resolve-options (.+)$/.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 = /^resolver (.+)$/.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

Comments
 (0)