Skip to content

Commit

Permalink
Replace deprecated Tapable#apply by Plugin#apply
Browse files Browse the repository at this point in the history
  • Loading branch information
ooflorent committed Dec 20, 2017
1 parent e72c00f commit 7dd41b5
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 614 deletions.
2 changes: 1 addition & 1 deletion lib/CachePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CachePlugin {
apply(compiler) {
if(Array.isArray(compiler.compilers)) {
compiler.compilers.forEach((c, idx) => {
c.apply(new CachePlugin(this.cache[idx] = this.cache[idx] || {}));
new CachePlugin(this.cache[idx] = this.cache[idx] || {}).apply(c);
});
} else {
const registerCacheToCompiler = (compiler, cache) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class Compiler extends Tapable {
createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) {
const childCompiler = new Compiler(this.context);
if(Array.isArray(plugins)) {
plugins.forEach(plugin => childCompiler.apply(plugin));
plugins.forEach(plugin => plugin.apply(childCompiler));
}
for(const name in this.hooks) {
if(["make", "compile", "emit", "afterEmit", "invalid", "done", "thisCompilation"].indexOf(name) < 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/DelegatedPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DelegatedPlugin {
compiler.hooks.compile.tap("DelegatedPlugin", ({
normalModuleFactory
}) => {
normalModuleFactory.apply(new DelegatedModuleFactoryPlugin(this.options));
new DelegatedModuleFactoryPlugin(this.options).apply(normalModuleFactory);
});
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/DllPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class DllPlugin {
};
if(typeof entry === "object" && !Array.isArray(entry)) {
Object.keys(entry).forEach(name => {
compiler.apply(itemToPlugin(entry[name], name));
itemToPlugin(entry[name], name).apply(compiler);
});
} else {
compiler.apply(itemToPlugin(entry, "main"));
itemToPlugin(entry, "main").apply(compiler);
}
return true;
});
compiler.apply(new LibManifestPlugin(this.options));
compiler.apply(new FlagInitialModulesAsUsedPlugin("DllPlugin"));
new LibManifestPlugin(this.options).apply(compiler);
new FlagInitialModulesAsUsedPlugin("DllPlugin").apply(compiler);
}
}

Expand Down
7 changes: 4 additions & 3 deletions lib/DllReferencePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ class DllReferencePlugin {
const externals = {};
const source = "dll-reference " + name;
externals[source] = name;
params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(sourceType, externals));
params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin({
const normalModuleFactory = params.normalModuleFactory;
new ExternalModuleFactoryPlugin(sourceType, externals).apply(normalModuleFactory);
new DelegatedModuleFactoryPlugin({
source: source,
type: this.options.type,
scope: this.options.scope,
context: this.options.context || compiler.options.context,
content: this.options.content || manifest.content,
extensions: this.options.extensions
}));
}).apply(normalModuleFactory);
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/EntryOptionPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module.exports = class EntryOptionPlugin {
apply(compiler) {
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
if(typeof entry === "string" || Array.isArray(entry)) {
compiler.apply(itemToPlugin(context, entry, "main"));
itemToPlugin(context, entry, "main").apply(compiler);
} else if(typeof entry === "object") {
Object.keys(entry).forEach(name => compiler.apply(itemToPlugin(context, entry[name], name)));
Object.keys(entry).forEach(name => itemToPlugin(context, entry[name], name).apply(compiler));
} else if(typeof entry === "function") {
compiler.apply(new DynamicEntryPlugin(context, entry));
new DynamicEntryPlugin(context, entry).apply(compiler);
}
return true;
});
Expand Down
2 changes: 1 addition & 1 deletion lib/EnvironmentPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EnvironmentPlugin {
return defs;
}, {});

compiler.apply(new DefinePlugin(definitions));
new DefinePlugin(definitions).apply(compiler);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/EvalDevToolModulePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class EvalDevToolModulePlugin {

apply(compiler) {
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", (compilation) => {
compilation.moduleTemplates.javascript.apply(new EvalDevToolModuleTemplatePlugin({
new EvalDevToolModuleTemplatePlugin({
sourceUrlComment: this.sourceUrlComment,
moduleFilenameTemplate: this.moduleFilenameTemplate,
namespace: this.namespace
}));
}).apply(compilation.moduleTemplates.javascript);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/EvalSourceMapDevToolPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EvalSourceMapDevToolPlugin {
const options = this.options;
compiler.hooks.compilation.tap("EvalSourceMapDevToolPlugin", (compilation) => {
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
compilation.moduleTemplates.javascript.apply(new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options));
new EvalSourceMapDevToolModuleTemplatePlugin(compilation, options).apply(compilation.moduleTemplates.javascript);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ExternalsPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExternalsPlugin {
compiler.hooks.compile.tap("ExternalsPlugin", ({
normalModuleFactory
}) => {
normalModuleFactory.apply(new ExternalModuleFactoryPlugin(this.type, this.externals));
new ExternalModuleFactoryPlugin(this.type, this.externals).apply(normalModuleFactory);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/FunctionModulePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FunctionModulePlugin {

apply(compiler) {
compiler.hooks.compilation.tap("FunctionModulePlugin", (compilation) => {
compilation.moduleTemplates.javascript.apply(new FunctionModuleTemplatePlugin());
new FunctionModuleTemplatePlugin().apply(compilation.moduleTemplates.javascript);
});
}
}
Expand Down
24 changes: 12 additions & 12 deletions lib/LibraryTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,49 @@ class LibraryTemplatePlugin {
compiler.hooks.thisCompilation.tap("LibraryTemplatePlugin", (compilation) => {
if(this.exportProperty) {
var ExportPropertyMainTemplatePlugin = require("./ExportPropertyMainTemplatePlugin");
compilation.apply(new ExportPropertyMainTemplatePlugin(this.exportProperty));
new ExportPropertyMainTemplatePlugin(this.exportProperty).apply(compilation);
}
switch(this.target) {
case "var":
compilation.apply(new SetVarMainTemplatePlugin(`var ${accessorAccess(false, this.name)}`));
new SetVarMainTemplatePlugin(`var ${accessorAccess(false, this.name)}`).apply(compilation);
break;
case "assign":
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(undefined, this.name)));
new SetVarMainTemplatePlugin(accessorAccess(undefined, this.name)).apply(compilation);
break;
case "this":
case "window":
case "global":
if(this.name)
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess(this.target, this.name)));
new SetVarMainTemplatePlugin(accessorAccess(this.target, this.name)).apply(compilation);
else
compilation.apply(new SetVarMainTemplatePlugin(this.target, true));
new SetVarMainTemplatePlugin(this.target, true).apply(compilation);
break;
case "commonjs":
if(this.name)
compilation.apply(new SetVarMainTemplatePlugin(accessorAccess("exports", this.name)));
new SetVarMainTemplatePlugin(accessorAccess("exports", this.name)).apply(compilation);
else
compilation.apply(new SetVarMainTemplatePlugin("exports", true));
new SetVarMainTemplatePlugin("exports", true).apply(compilation);
break;
case "commonjs2":
case "commonjs-module":
compilation.apply(new SetVarMainTemplatePlugin("module.exports"));
new SetVarMainTemplatePlugin("module.exports").apply(compilation);
break;
case "amd":
var AmdMainTemplatePlugin = require("./AmdMainTemplatePlugin");
compilation.apply(new AmdMainTemplatePlugin(this.name));
new AmdMainTemplatePlugin(this.name).apply(compilation);
break;
case "umd":
case "umd2":
var UmdMainTemplatePlugin = require("./UmdMainTemplatePlugin");
compilation.apply(new UmdMainTemplatePlugin(this.name, {
new UmdMainTemplatePlugin(this.name, {
optionalAmdExternalAsGlobal: this.target === "umd2",
namedDefine: this.umdNamedDefine,
auxiliaryComment: this.auxiliaryComment
}));
}).apply(compilation);
break;
case "jsonp":
var JsonpExportMainTemplatePlugin = require("./web/JsonpExportMainTemplatePlugin");
compilation.apply(new JsonpExportMainTemplatePlugin(this.name));
new JsonpExportMainTemplatePlugin(this.name).apply(compilation);
break;
default:
throw new Error(`${this.target} is not a valid Library target`);
Expand Down
4 changes: 2 additions & 2 deletions lib/ProgressPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ class ProgressPlugin {
if(compiler.compilers) {
const states = new Array(compiler.compilers.length);
compiler.compilers.forEach((compiler, idx) => {
compiler.apply(new ProgressPlugin((p, msg, ...args) => {
new ProgressPlugin((p, msg, ...args) => {
states[idx] = args;
handler(
states.map(state => state && state[0] || 0).reduce((a, b) => a + b) / states.length,
`[${idx}] ${msg}`,
...args
);
}));
}).apply(compiler);
});
} else {
let lastModulesCount = 0;
Expand Down

0 comments on commit 7dd41b5

Please sign in to comment.