From 8758137758ee4e9d8c54d6a235c2c9e04c3e907d Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 18 Jan 2021 16:56:35 +0100 Subject: [PATCH] Fix ts-ignore not being detected --- .../build/webpack/plugins/profiling-plugin.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/next/build/webpack/plugins/profiling-plugin.ts b/packages/next/build/webpack/plugins/profiling-plugin.ts index bd58574ab2d11c2..6dee491cd8499d3 100644 --- a/packages/next/build/webpack/plugins/profiling-plugin.ts +++ b/packages/next/build/webpack/plugins/profiling-plugin.ts @@ -5,6 +5,15 @@ const pluginName = 'ProfilingPlugin' export const spans = new WeakMap() +function getNormalModuleLoaderHook(compilation: any) { + if (isWebpack5) { + // @ts-ignore TODO: Remove ignore when webpack 5 is stable + return webpack.NormalModule.getCompilationHooks(compilation).loader + } + + return compilation.hooks.normalModuleLoader +} + export class ProfilingPlugin { apply(compiler: any) { // Only enabled when instrumentation is loaded @@ -35,14 +44,13 @@ export class ProfilingPlugin { }) }) - const hook = isWebpack5 - ? // @ts-ignore TODO: Webpack 5 types - webpack.NormalModule.getCompilationHooks(compilation).loader - : compilation.hooks.normalModuleLoader - hook.tap(pluginName, (loaderContext: any, module: any) => { - const parentSpan = spans.get(module) - loaderContext.currentTraceSpan = parentSpan - }) + getNormalModuleLoaderHook(compilation).tap( + pluginName, + (loaderContext: any, module: any) => { + const parentSpan = spans.get(module) + loaderContext.currentTraceSpan = parentSpan + } + ) compilation.hooks.succeedModule.tap(pluginName, (module: any) => { spans.get(module).end()