Skip to content

Commit

Permalink
Merge pull request #14698 from webpack/bugfix/profiling-plugin-hook-c…
Browse files Browse the repository at this point in the history
…heck

check hooks for existance before using in ProfilingPlugin
  • Loading branch information
sokra committed Nov 11, 2021
2 parents ac7bd40 + 11bc877 commit d96f23e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 9 additions & 7 deletions lib/debug/ProfilingPlugin.js
Expand Up @@ -203,15 +203,17 @@ class ProfilingPlugin {

// Compiler Hooks
Object.keys(compiler.hooks).forEach(hookName => {
compiler.hooks[hookName].intercept(
makeInterceptorFor("Compiler", tracer)(hookName)
);
const hook = compiler.hooks[hookName];
if (hook) {
hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
}
});

Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
compiler.resolverFactory.hooks[hookName].intercept(
makeInterceptorFor("Resolver", tracer)(hookName)
);
const hook = compiler.resolverFactory.hooks[hookName];
if (hook) {
hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
}
});

compiler.hooks.compilation.tap(
Expand Down Expand Up @@ -303,7 +305,7 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
if (Reflect.has(instance, "hooks")) {
Object.keys(instance.hooks).forEach(hookName => {
const hook = instance.hooks[hookName];
if (!hook._fakeHook) {
if (hook && !hook._fakeHook) {
hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
}
});
Expand Down
5 changes: 4 additions & 1 deletion test/ProfilingPlugin.test.js
Expand Up @@ -25,7 +25,10 @@ describe("Profiling Plugin", function () {
new webpack.debug.ProfilingPlugin({
outputPath: finalPath
})
]
],
experiments: {
backCompat: false
}
});
compiler.run(err => {
if (err) return done(err);
Expand Down

0 comments on commit d96f23e

Please sign in to comment.