Skip to content

Commit

Permalink
Fix webpack 5 warning + disabling of profiling (#21276)
Browse files Browse the repository at this point in the history
Noticed that there was a specific warning when using webpack 5.
  • Loading branch information
timneutkens committed Jan 18, 2021
1 parent c5b5c43 commit f8fecf5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/next/build/webpack/plugins/profiling-plugin.ts
@@ -1,13 +1,28 @@
import { tracer } from '../../tracer'
import { webpack, isWebpack5 } from 'next/dist/compiled/webpack/webpack'

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
if (!tracer.getCurrentSpan()) {
const currentSpan = tracer.getCurrentSpan()
console.log({
currentSpan,
isRecording: currentSpan?.isRecording(),
})
if (!currentSpan || !currentSpan.isRecording()) {
return
}

Expand All @@ -29,7 +44,7 @@ export class ProfilingPlugin {
})
})

compilation.hooks.normalModuleLoader.tap(
getNormalModuleLoaderHook(compilation).tap(
pluginName,
(loaderContext: any, module: any) => {
const parentSpan = spans.get(module)
Expand Down

0 comments on commit f8fecf5

Please sign in to comment.