Skip to content

Commit

Permalink
Make the watched filename that triggers webpack compilation be relati…
Browse files Browse the repository at this point in the history
…ve to project directory
  • Loading branch information
mknichel committed Dec 7, 2023
1 parent 1a429b6 commit 2a7b0e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ export default async function getBaseWebpackConfig(
exportRuntime: true,
appDirEnabled: hasAppDir,
}),
new ProfilingPlugin({ runWebpackSpan }),
new ProfilingPlugin({ runWebpackSpan, rootDir: dir }),
config.optimizeFonts &&
!dev &&
isNodeServer &&
Expand Down
15 changes: 13 additions & 2 deletions packages/next/src/build/webpack/plugins/profiling-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NormalModule } from 'next/dist/compiled/webpack/webpack'
import type { Span } from '../../../trace'
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import path from 'path'

const pluginName = 'ProfilingPlugin'
export const spans = new WeakMap<webpack.Compilation | webpack.Compiler, Span>()
Expand All @@ -27,9 +28,17 @@ function inTraceLabelsSeal(label: string) {
export class ProfilingPlugin {
compiler: any
runWebpackSpan: Span
rootDir: string

constructor({ runWebpackSpan }: { runWebpackSpan: Span }) {
constructor({
runWebpackSpan,
rootDir,
}: {
runWebpackSpan: Span
rootDir: string
}) {
this.runWebpackSpan = runWebpackSpan
this.rootDir = rootDir
}
apply(compiler: any) {
this.traceTopLevelHooks(compiler)
Expand Down Expand Up @@ -105,7 +114,9 @@ export class ProfilingPlugin {
onStart: (span) => webpackInvalidSpans.set(compiler, span),
onStop: () => webpackInvalidSpans.delete(compiler),
attrs: (fileName: any) => ({
trigger: fileName || 'manual',
trigger: fileName
? path.relative(this.rootDir, fileName).replaceAll(path.sep, '/')
: 'manual',
}),
}
)
Expand Down

0 comments on commit 2a7b0e9

Please sign in to comment.