Skip to content

Commit 6ff8b37

Browse files
committed
Merge branch 'refactoring/plugin-system-other' into refactoring/plugin-system-all
2 parents fb689d9 + 7fb3468 commit 6ff8b37

2 files changed

Lines changed: 25 additions & 4 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
};

‎lib/WebAssemblyParser.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
88

9-
const Tapable = require("tapable-old");
9+
const Tapable = require("tapable").Tapable;
1010

1111
class WebAssemblyParser extends Tapable {
1212
constructor(options) {
1313
super();
14+
this.hooks = {};
1415
this.options = options;
1516
}
1617

0 commit comments

Comments
 (0)