Skip to content

Commit 7dd41b5

Browse files
committed
Replace deprecated Tapable#apply by Plugin#apply
1 parent e72c00f commit 7dd41b5

30 files changed

+189
-614
lines changed

lib/CachePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CachePlugin {
1515
apply(compiler) {
1616
if(Array.isArray(compiler.compilers)) {
1717
compiler.compilers.forEach((c, idx) => {
18-
c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
18+
new CachePlugin(this.cache[idx] = this.cache[idx] || {}).apply(c);
1919
});
2020
} else {
2121
const registerCacheToCompiler = (compiler, cache) => {

lib/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class Compiler extends Tapable {
522522
createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) {
523523
const childCompiler = new Compiler(this.context);
524524
if(Array.isArray(plugins)) {
525-
plugins.forEach(plugin => childCompiler.apply(plugin));
525+
plugins.forEach(plugin => plugin.apply(childCompiler));
526526
}
527527
for(const name in this.hooks) {
528528
if(["make", "compile", "emit", "afterEmit", "invalid", "done", "thisCompilation"].indexOf(name) < 0) {

lib/DelegatedPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class DelegatedPlugin {
2626
compiler.hooks.compile.tap("DelegatedPlugin", ({
2727
normalModuleFactory
2828
}) => {
29-
normalModuleFactory.apply(new DelegatedModuleFactoryPlugin(this.options));
29+
new DelegatedModuleFactoryPlugin(this.options).apply(normalModuleFactory);
3030
});
3131
}
3232
}

lib/DllPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ class DllPlugin {
2727
};
2828
if(typeof entry === "object" && !Array.isArray(entry)) {
2929
Object.keys(entry).forEach(name => {
30-
compiler.apply(itemToPlugin(entry[name], name));
30+
itemToPlugin(entry[name], name).apply(compiler);
3131
});
3232
} else {
33-
compiler.apply(itemToPlugin(entry, "main"));
33+
itemToPlugin(entry, "main").apply(compiler);
3434
}
3535
return true;
3636
});
37-
compiler.apply(new LibManifestPlugin(this.options));
38-
compiler.apply(new FlagInitialModulesAsUsedPlugin("DllPlugin"));
37+
new LibManifestPlugin(this.options).apply(compiler);
38+
new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
3939
}
4040
}
4141

lib/DllReferencePlugin.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ class DllReferencePlugin {
5151
const externals = {};
5252
const source = "dll-reference " + name;
5353
externals[source] = name;
54-
params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(sourceType, externals));
55-
params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin({
54+
const normalModuleFactory = params.normalModuleFactory;
55+
new ExternalModuleFactoryPlugin(sourceType, externals).apply(normalModuleFactory);
56+
new DelegatedModuleFactoryPlugin({
5657
source: source,
5758
type: this.options.type,
5859
scope: this.options.scope,
5960
context: this.options.context || compiler.options.context,
6061
content: this.options.content || manifest.content,
6162
extensions: this.options.extensions
62-
}));
63+
}).apply(normalModuleFactory);
6364
});
6465
}
6566
}

lib/EntryOptionPlugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ module.exports = class EntryOptionPlugin {
1919
apply(compiler) {
2020
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
2121
if(typeof entry === "string" || Array.isArray(entry)) {
22-
compiler.apply(itemToPlugin(context, entry, "main"));
22+
itemToPlugin(context, entry, "main").apply(compiler);
2323
} else if(typeof entry === "object") {
24-
Object.keys(entry).forEach(name => compiler.apply(itemToPlugin(context, entry[name], name)));
24+
Object.keys(entry).forEach(name => itemToPlugin(context, entry[name], name).apply(compiler));
2525
} else if(typeof entry === "function") {
26-
compiler.apply(new DynamicEntryPlugin(context, entry));
26+
new DynamicEntryPlugin(context, entry).apply(compiler);
2727
}
2828
return true;
2929
});

lib/EnvironmentPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class EnvironmentPlugin {
4343
return defs;
4444
}, {});
4545

46-
compiler.apply(new DefinePlugin(definitions));
46+
new DefinePlugin(definitions).apply(compiler);
4747
}
4848
}
4949

lib/EvalDevToolModulePlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class EvalDevToolModulePlugin {
1515

1616
apply(compiler) {
1717
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", (compilation) => {
18-
compilation.moduleTemplates.javascript.apply(new EvalDevToolModuleTemplatePlugin({
18+
new EvalDevToolModuleTemplatePlugin({
1919
sourceUrlComment: this.sourceUrlComment,
2020
moduleFilenameTemplate: this.moduleFilenameTemplate,
2121
namespace: this.namespace
22-
}));
22+
}).apply(compilation.moduleTemplates.javascript);
2323
});
2424
}
2525
}

lib/EvalSourceMapDevToolPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class EvalSourceMapDevToolPlugin {
2424
const options = this.options;
2525
compiler.hooks.compilation.tap("EvalSourceMapDevToolPlugin", (compilation) => {
2626
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
27-
compilation.moduleTemplates.javascript.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
27+
new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options).apply(compilation.moduleTemplates.javascript);
2828
});
2929
}
3030
}

lib/ExternalsPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExternalsPlugin {
1515
compiler.hooks.compile.tap("ExternalsPlugin", ({
1616
normalModuleFactory
1717
}) => {
18-
normalModuleFactory.apply(new ExternalModuleFactoryPlugin(this.type, this.externals));
18+
new ExternalModuleFactoryPlugin(this.type, this.externals).apply(normalModuleFactory);
1919
});
2020
}
2121
}

lib/FunctionModulePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class FunctionModulePlugin {
1313

1414
apply(compiler) {
1515
compiler.hooks.compilation.tap("FunctionModulePlugin", (compilation) => {
16-
compilation.moduleTemplates.javascript.apply(new FunctionModuleTemplatePlugin());
16+
new FunctionModuleTemplatePlugin().apply(compilation.moduleTemplates.javascript);
1717
});
1818
}
1919
}

lib/LibraryTemplatePlugin.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,49 @@ class LibraryTemplatePlugin {
3838
compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", (compilation) => {
3939
if(this.exportProperty) {
4040
var ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
41-
compilation.apply(new ExportPropertyMainTemplatePlugin(this.exportProperty));
41+
new ExportPropertyMainTemplatePlugin(this.exportProperty).apply(compilation);
4242
}
4343
switch(this.target) {
4444
case "var":
45-
compilation.apply(new SetVarMainTemplatePlugin(`var ${accessorAccess(false, this.name)}`));
45+
new SetVarMainTemplatePlugin(`var ${accessorAccess(false, this.name)}`).apply(compilation);
4646
break;
4747
case "assign":
48-
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(undefined, this.name)));
48+
new SetVarMainTemplatePlugin(accessorAccess(undefined, this.name)).apply(compilation);
4949
break;
5050
case "this":
5151
case "window":
5252
case "global":
5353
if(this.name)
54-
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(this.target, this.name)));
54+
new SetVarMainTemplatePlugin(accessorAccess(this.target, this.name)).apply(compilation);
5555
else
56-
compilation.apply(new SetVarMainTemplatePlugin(this.target, true));
56+
new SetVarMainTemplatePlugin(this.target, true).apply(compilation);
5757
break;
5858
case "commonjs":
5959
if(this.name)
60-
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess("exports", this.name)));
60+
new SetVarMainTemplatePlugin(accessorAccess("exports", this.name)).apply(compilation);
6161
else
62-
compilation.apply(new SetVarMainTemplatePlugin("exports", true));
62+
new SetVarMainTemplatePlugin("exports", true).apply(compilation);
6363
break;
6464
case "commonjs2":
6565
case "commonjs-module":
66-
compilation.apply(new SetVarMainTemplatePlugin("module.exports"));
66+
new SetVarMainTemplatePlugin("module.exports").apply(compilation);
6767
break;
6868
case "amd":
6969
var AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
70-
compilation.apply(new AmdMainTemplatePlugin(this.name));
70+
new AmdMainTemplatePlugin(this.name).apply(compilation);
7171
break;
7272
case "umd":
7373
case "umd2":
7474
var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
75-
compilation.apply(new UmdMainTemplatePlugin(this.name, {
75+
new UmdMainTemplatePlugin(this.name, {
7676
optionalAmdExternalAsGlobal: this.target === "umd2",
7777
namedDefine: this.umdNamedDefine,
7878
auxiliaryComment: this.auxiliaryComment
79-
}));
79+
}).apply(compilation);
8080
break;
8181
case "jsonp":
8282
var JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
83-
compilation.apply(new JsonpExportMainTemplatePlugin(this.name));
83+
new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
8484
break;
8585
default:
8686
throw new Error(`${this.target} is not a valid Library target`);

lib/ProgressPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ class ProgressPlugin {
8585
if(compiler.compilers) {
8686
const states = new Array(compiler.compilers.length);
8787
compiler.compilers.forEach((compiler, idx) => {
88-
compiler.apply(new ProgressPlugin((p, msg, ...args) => {
88+
new ProgressPlugin((p, msg, ...args) => {
8989
states[idx] = args;
9090
handler(
9191
states.map(state => state && state[0] || 0).reduce((a, b) => a + b) / states.length,
9292
`[${idx}] ${msg}`,
9393
...args
9494
);
95-
}));
95+
}).apply(compiler);
9696
});
9797
} else {
9898
let lastModulesCount = 0;

0 commit comments

Comments
 (0)