8000 Merge pull request #14698 from webpack/bugfix/profiling-plugin-hook-c… · webpack/webpack@d96f23e · GitHub
[go: up one dir, main page]

Skip to content

Commit d96f23e

Browse files
authored
Merge pull request #14698 from webpack/bugfix/profiling-plugin-hook-check
check hooks for existance before using in ProfilingPlugin
2 parents ac7bd40 + 11bc877 commit d96f23e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/debug/ProfilingPlugin.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,17 @@ class ProfilingPlugin {
203203

204204
// Compiler Hooks
205205
Object.keys(compiler.hooks).forEach(hookName => {
206-
compiler.hooks[hookName].intercept(
207-
makeInterceptorFor("Compiler", tracer)(hookName)
208-
);
206+
const hook = compiler.hooks[hookName];
207+
if (hook) {
208+
hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
209+
}
209210
});
210211

211212
Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
212-
compiler.resolverFactory.hooks[hookName].intercept(
213-
makeInterceptorFor("Resolver", tracer)(hookName)
214-
);
213+
const hook = compiler.resolverFactory.hooks[hookName];
214+
if (hook) {
215+
hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
216+
}
215217
});
216218

217219
compiler.hooks.compilation.tap(
@@ -303,7 +305,7 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
303305
if (Reflect.has(instance, "hooks")) {
304306
Object.keys(instance.hooks).forEach(hookName => {
305307
const hook = instance.hooks[hookName];
306-
if (!hook._fakeHook) {
308+
if (hook && !hook._fakeHook) {
307309
hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
308310
}
309311
});

test/ProfilingPlugin.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ describe("Profiling Plugin", function () {
2525
new webpack.debug.ProfilingPlugin({
2626
outputPath: finalPath
2727
})
28-
]
28+
],
29+
experiments: {
30+
backCompat: false
31+
}
2932
});
3033
compiler.run(err => {
3134
if (err) return done(err);

0 commit comments

Comments
 (0)
0