Skip to content

Commit bbf1458

Browse files
authored
Merge pull request webpack#6096 from ooflorent/use_tapable
Use tapable instead of 'plugin'
2 parents 699a392 + 36c690d commit bbf1458

File tree

81 files changed

+254
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+254
-242
lines changed

lib/APIPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ const REPLACEMENT_TYPES = {
2828

2929
class APIPlugin {
3030
apply(compiler) {
31-
compiler.plugin("compilation", (compilation, params) => {
31+
compiler.hooks.compilation.tap("APIPlugin", (compilation, {
32+
normalModuleFactory
33+
}) => {
3234
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
3335
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
3436

35-
params.normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], parser => {
37+
normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], parser => {
3638
Object.keys(REPLACEMENTS).forEach(key => {
3739
parser.plugin(`expression ${key}`, ParserHelpers.toConstantDependency(REPLACEMENTS[key]));
3840
parser.plugin(`evaluate typeof ${key}`, ParserHelpers.evaluateToString(REPLACEMENT_TYPES[key]));

lib/AutomaticPrefetchPlugin.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@ const NormalModule = require("./NormalModule");
1010

1111
class AutomaticPrefetchPlugin {
1212
apply(compiler) {
13-
compiler.plugin("compilation", (compilation, params) => {
14-
const normalModuleFactory = params.normalModuleFactory;
15-
13+
compiler.hooks.compilation.tap("AutomaticPrefetchPlugin", (compilation, {
14+
normalModuleFactory
15+
}) => {
1616
compilation.dependencyFactories.set(PrefetchDependency, normalModuleFactory);
1717
});
1818
let lastModules = null;
19-
compiler.plugin("after-compile", (compilation, callback) => {
19+
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", (compilation) => {
2020
lastModules = compilation.modules
2121
.filter(m => m instanceof NormalModule)
2222
.map(m => ({
2323
context: m.context,
2424
request: m.request
2525
}));
26-
callback();
2726
});
28-
compiler.plugin("make", (compilation, callback) => {
27+
compiler.hooks.make.tapAsync("AutomaticPrefetchPlugin", (compilation, callback) => {
2928
if(!lastModules) return callback();
3029
asyncLib.forEach(lastModules, (m, callback) => {
3130
compilation.prefetch(m.context || compiler.context, new PrefetchDependency(m.request), callback);

lib/BannerPlugin.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class BannerPlugin {
3636
const options = this.options;
3737
const banner = this.banner;
3838

39-
compiler.plugin("compilation", (compilation) => {
40-
compilation.plugin("optimize-chunk-assets", (chunks, callback) => {
39+
compiler.hooks.compilation.tap("BannerPlugin", (compilation) => {
40+
compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", (chunks) => {
4141
chunks.forEach((chunk) => {
4242
if(options.entryOnly && !chunk.isInitial()) return;
4343
chunk.files
@@ -71,7 +71,6 @@ class BannerPlugin {
7171
return compilation.assets[file] = new ConcatSource(comment, "\n", compilation.assets[file]);
7272
});
7373
});
74-
callback();
7574
});
7675
});
7776
}

lib/CachePlugin.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class CachePlugin {
1919
});
2020
} else {
2121
const registerCacheToCompiler = (compiler, cache) => {
22-
compiler.plugin("this-compilation", compilation => {
22+
compiler.hooks.thisCompilation.tap("CachePlugin", (compilation) => {
2323
compilation.cache = cache;
24-
compilation.plugin("child-compiler", (childCompiler, compilerName, compilerIndex) => {
24+
compilation.hooks.childCompiler.tap("CachePlugin", (childCompiler, compilerName, compilerIndex) => {
2525
if(cache) {
2626
let childCache;
2727
if(!cache.children) cache.children = {};
@@ -36,11 +36,10 @@ class CachePlugin {
3636
});
3737
};
3838
registerCacheToCompiler(compiler, this.cache);
39-
compiler.plugin("watch-run", (compiler, callback) => {
39+
compiler.hooks.watchRun.tap("CachePlugin", () => {
4040
this.watching = true;
41-
callback();
4241
});
43-
compiler.plugin("run", (compiler, callback) => {
42+
compiler.hooks.run.tapAsync("CachePlugin", (compiler, callback) => {
4443
if(!compiler._lastCompilationFileDependencies) return callback();
4544
const fs = compiler.inputFileSystem;
4645
const fileTs = compiler.fileTimestamps = {};
@@ -65,10 +64,9 @@ class CachePlugin {
6564
callback();
6665
});
6766
});
68-
compiler.plugin("after-compile", (compilation, callback) => {
67+
compiler.hooks.afterCompile.tap("CachePlugin", (compilation) => {
6968
compilation.compiler._lastCompilationFileDependencies = compilation.fileDependencies;
7069
compilation.compiler._lastCompilationContextDependencies = compilation.contextDependencies;
71-
callback();
7270
});
7371
}
7472
}

lib/CompatibilityPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const NullFactory = require("./NullFactory");
1111
class CompatibilityPlugin {
1212

1313
apply(compiler) {
14-
compiler.plugin("compilation", (compilation, params) => {
14+
compiler.hooks.compilation.tap("CompatibilityPlugin", (compilation, {
15+
normalModuleFactory
16+
}) => {
1517
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
1618
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
1719

18-
params.normalModuleFactory.plugin("parser javascript/auto", (parser, parserOptions) => {
20+
normalModuleFactory.plugin("parser javascript/auto", (parser, parserOptions) => {
1921

2022
if(typeof parserOptions.browserify !== "undefined" && !parserOptions.browserify)
2123
return;

lib/ConstPlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const getQuery = (request) => {
1414

1515
class ConstPlugin {
1616
apply(compiler) {
17-
compiler.plugin("compilation", (compilation, params) => {
17+
compiler.hooks.compilation.tap("ConstPlugin", (compilation, {
18+
normalModuleFactory
19+
}) => {
1820
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
1921
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
2022

21-
params.normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], parser => {
23+
normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], parser => {
2224
parser.plugin("statement if", statement => {
2325
const param = parser.evaluateExpression(statement.test);
2426
const bool = param.asBool();

lib/ContextExclusionPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ContextExclusionPlugin {
66
}
77

88
apply(compiler) {
9-
compiler.plugin("context-module-factory", (cmf) => {
9+
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", (cmf) => {
1010
cmf.plugin("context-module-files", (files) => {
1111
return files.filter(filePath => !this.negativeMatcher.test(filePath));
1212
});

lib/ContextReplacementPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ContextReplacementPlugin {
4545
const newContentRegExp = this.newContentRegExp;
4646
const newContentCreateContextMap = this.newContentCreateContextMap;
4747

48-
compiler.plugin("context-module-factory", (cmf) => {
48+
compiler.hooks.contextModuleFactory.tap("ContextReplacementPlugin", (cmf) => {
4949
cmf.plugin("before-resolve", (result, callback) => {
5050
if(!result) return callback();
5151
if(resourceRegExp.test(result.request)) {

lib/DefinePlugin.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class DefinePlugin {
3232

3333
apply(compiler) {
3434
const definitions = this.definitions;
35-
compiler.plugin("compilation", (compilation, params) => {
35+
compiler.hooks.compilation.tap("DefinePlugin", (compilation, {
36+
normalModuleFactory
37+
}) => {
3638
compilation.dependencyFactories.set(ConstDependency, new NullFactory());
3739
compilation.dependencyTemplates.set(ConstDependency, new ConstDependency.Template());
3840

39-
params.normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], (parser) => {
41+
normalModuleFactory.plugin(["parser javascript/auto", "parser javascript/dynamic", "parser javascript/esm"], (parser) => {
4042
const walkDefinitions = (definitions, prefix) => {
4143
Object.keys(definitions).forEach((key) => {
4244
const code = definitions[key];

lib/DelegatedPlugin.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ class DelegatedPlugin {
1616
}
1717

1818
apply(compiler) {
19-
compiler.plugin("compilation", (compilation, params) => {
20-
compilation.dependencyFactories.set(DelegatedSourceDependency, params.normalModuleFactory);
19+
compiler.hooks.compilation.tap("DelegatedPlugin", (compilation, {
20+
normalModuleFactory
21+
}) => {
22+
compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory);
2123
compilation.dependencyFactories.set(DelegatedExportsDependency, new NullFactory());
2224
});
2325

24-
compiler.plugin("compile", (params) => {
25-
params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin(this.options));
26+
compiler.hooks.compile.tap("DelegatedPlugin", ({
27+
normalModuleFactory
28+
}) => {
29+
normalModuleFactory.apply(new DelegatedModuleFactoryPlugin(this.options));
2630
});
2731
}
2832
}

0 commit comments

Comments
 (0)