Merge pull request #14698 from webpack/bugfix/profiling-plugin-hook-check

check hooks for existance before using in ProfilingPlugin
This commit is contained in:
Tobias Koppers 2021-11-11 08:30:37 +01:00 committed by GitHub
commit d96f23e9b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -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(
@ -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));
}
});

View File

@ -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);