Skip to content

Commit

Permalink
Fix ts-ignore not being detected
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jan 18, 2021
1 parent 1b79027 commit 8758137
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/next/build/webpack/plugins/profiling-plugin.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 8758137

Please sign in to comment.