Skip to content

Commit d16ccc9

Browse files
committed
Use tap() instead of tapAsync() when possible
1 parent 08ddad2 commit d16ccc9

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

lib/ContextReplacementPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class ContextReplacementPlugin {
4646
const newContentCreateContextMap = this.newContentCreateContextMap;
4747

4848
compiler.hooks.contextModuleFactory.tap("ContextReplacementPlugin", (cmf) => {
49-
cmf.hooks.beforeResolve.tapAsync("ContextReplacementPlugin", (result, callback) => {
50-
if(!result) return callback();
49+
cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", (result) => {
50+
if(!result) return;
5151
if(resourceRegExp.test(result.request)) {
5252
if(typeof newContentResource !== "undefined")
5353
result.request = newContentResource;
@@ -64,10 +64,10 @@ class ContextReplacementPlugin {
6464
});
6565
}
6666
}
67-
return callback(null, result);
67+
return result;
6868
});
69-
cmf.hooks.afterResolve.tapAsync("ContextReplacementPlugin", (result, callback) => {
70-
if(!result) return callback();
69+
cmf.hooks.afterResolve.tap("ContextReplacementPlugin", (result) => {
70+
if(!result) return;
7171
if(resourceRegExp.test(result.resource)) {
7272
if(typeof newContentResource !== "undefined")
7373
result.resource = path.resolve(result.resource, newContentResource);
@@ -90,7 +90,7 @@ class ContextReplacementPlugin {
9090
});
9191
}
9292
}
93-
return callback(null, result);
93+
return result;
9494
});
9595
});
9696
}

lib/IgnorePlugin.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ class IgnorePlugin {
4848
return this.checkResource(result.request) && this.checkContext(result.context);
4949
}
5050

51-
checkIgnore(result, callback) {
51+
checkIgnore(result) {
5252
// check if result is ignored
5353
if(this.checkResult(result)) {
54-
return callback(null, null);
54+
return null;
5555
}
56-
return callback(null, result);
56+
return result;
5757
}
5858

5959
apply(compiler) {
6060
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", (nmf) => {
61-
nmf.hooks.beforeResolve.tapAsync("IgnorePlugin", this.checkIgnore);
61+
nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
6262
});
6363
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", (cmf) => {
64-
cmf.hooks.beforeResolve.tapAsync("IgnorePlugin", this.checkIgnore);
64+
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
6565
});
6666
}
6767
}

lib/NormalModuleReplacementPlugin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ class NormalModuleReplacementPlugin {
1616
const resourceRegExp = this.resourceRegExp;
1717
const newResource = this.newResource;
1818
compiler.hooks.normalModuleFactory.tap("NormalModuleReplacementPlugin", (nmf) => {
19-
nmf.hooks.beforeResolve.tapAsync("NormalModuleReplacementPlugin", (result, callback) => {
20-
if(!result) return callback();
19+
nmf.hooks.beforeResolve.tap("NormalModuleReplacementPlugin", (result) => {
20+
if(!result) return;
2121
if(resourceRegExp.test(result.request)) {
2222
if(typeof newResource === "function") {
2323
newResource(result);
2424
} else {
2525
result.request = newResource;
2626
}
2727
}
28-
return callback(null, result);
28+
return result;
2929
});
30-
nmf.hooks.afterResolve.tapAsync("NormalModuleReplacementPlugin", (result, callback) => {
31-
if(!result) return callback();
30+
nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", (result) => {
31+
if(!result) return;
3232
if(resourceRegExp.test(result.resource)) {
3333
if(typeof newResource === "function") {
3434
newResource(result);
3535
} else {
3636
result.resource = path.resolve(path.dirname(result.resource), newResource);
3737
}
3838
}
39-
return callback(null, result);
39+
return result;
4040
});
4141
});
4242
}

lib/dependencies/RequireContextPlugin.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ class RequireContextPlugin {
4040
normalModuleFactory.hooks.parser.for("javascript/auto").tap("RequireContextPlugin", handler);
4141
normalModuleFactory.hooks.parser.for("javascript/dynamic").tap("RequireContextPlugin", handler);
4242

43-
contextModuleFactory.hooks.alternatives.tapAsync("RequireContextPlugin", (items, callback) => {
44-
if(items.length === 0) return callback(null, items);
45-
46-
callback(null, items.map((obj) => {
43+
contextModuleFactory.hooks.alternatives.tap("RequireContextPlugin", (items) => {
44+
if(items.length === 0) return items;
45+
return items.map((obj) => {
4746
return this.extensions.filter((ext) => {
4847
const l = obj.request.length;
4948
return l > ext.length && obj.request.substr(l - ext.length, l) === ext;
@@ -54,13 +53,12 @@ class RequireContextPlugin {
5453
request: obj.request.substr(0, l - ext.length)
5554
};
5655
}).concat(obj);
57-
}).reduce((a, b) => a.concat(b), []));
56+
}).reduce((a, b) => a.concat(b), []);
5857
});
5958

60-
contextModuleFactory.hooks.alternatives.tapAsync("RequireContextPlugin", (items, callback) => {
61-
if(items.length === 0) return callback(null, items);
62-
63-
callback(null, items.map((obj) => {
59+
contextModuleFactory.hooks.alternatives.tap("RequireContextPlugin", (items) => {
60+
if(items.length === 0) return items;
61+
return items.map((obj) => {
6462
return this.mainFiles.filter((mainFile) => {
6563
const l = obj.request.length;
6664
return l > mainFile.length + 1 && obj.request.substr(l - mainFile.length - 1, l) === "/" + mainFile;
@@ -74,13 +72,12 @@ class RequireContextPlugin {
7472
request: obj.request.substr(0, l - mainFile.length - 1)
7573
}];
7674
}).reduce((a, b) => a.concat(b), []).concat(obj);
77-
}).reduce((a, b) => a.concat(b), []));
75+
}).reduce((a, b) => a.concat(b), []);
7876
});
7977

80-
contextModuleFactory.hooks.alternatives.tapAsync("RequireContextPlugin", (items, callback) => {
81-
if(items.length === 0) return callback(null, items);
82-
83-
callback(null, items.map((obj) => {
78+
contextModuleFactory.hooks.alternatives.tap("RequireContextPlugin", (items) => {
79+
if(items.length === 0) return items;
80+
return items.map((obj) => {
8481
for(let i = 0; i < this.modulesDirectories.length; i++) {
8582
const dir = this.modulesDirectories[i];
8683
const idx = obj.request.indexOf("./" + dir + "/");
@@ -90,7 +87,7 @@ class RequireContextPlugin {
9087
}
9188
}
9289
return obj;
93-
}));
90+
});
9491
});
9592
});
9693
}

0 commit comments

Comments
 (0)