Unverified Commit 5de4f668 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update to use project dir for file tracing base (#30857)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 95182480
......@@ -1418,6 +1418,7 @@ export default async function getBaseWebpackConfig(
appDir: dir,
esmExternals: config.experimental.esmExternals,
staticImageImports: !config.images.disableStaticImages,
outputFileTracingRoot: config.experimental.outputFileTracingRoot,
}),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
......
......@@ -22,7 +22,6 @@ const TRACE_IGNORES = [
'**/*/next/dist/server/next.js',
'**/*/next/dist/bin/next',
]
const root = nodePath.parse(process.cwd()).root
function getModuleFromDependency(
compilation: any,
......@@ -81,6 +80,7 @@ function getFilesMapFromReasons(
export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
private appDir: string
private tracingRoot: string
private entryTraces: Map<string, Set<string>>
private excludeFiles: string[]
private esmExternals?: NextConfigComplete['experimental']['esmExternals']
......@@ -91,10 +91,12 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
excludeFiles,
esmExternals,
staticImageImports,
outputFileTracingRoot,
}: {
appDir: string
excludeFiles?: string[]
staticImageImports: boolean
outputFileTracingRoot?: string
esmExternals?: NextConfigComplete['experimental']['esmExternals']
}) {
this.appDir = appDir
......@@ -102,6 +104,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
this.esmExternals = esmExternals
this.excludeFiles = excludeFiles || []
this.staticImageImports = staticImageImports
this.tracingRoot = outputFileTracingRoot || appDir
}
// Here we output all traced assets and webpack chunks to a
......@@ -141,7 +144,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
}
const result = await nodeFileTrace([...chunksToTrace], {
base: root,
base: this.tracingRoot,
processCwd: this.appDir,
readFile: async (path) => {
if (chunksToTrace.has(path)) {
......@@ -193,9 +196,9 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
entryFiles.forEach((file) => {
parentFilesMap
.get(nodePath.relative(root, file))
.get(nodePath.relative(this.tracingRoot, file))
?.forEach((child) => {
allEntryFiles.add(nodePath.join(root, child))
allEntryFiles.add(nodePath.join(this.tracingRoot, child))
})
})
// don't include the entry itself in the trace
......@@ -326,7 +329,7 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
})
.traceAsyncFn(async () => {
const result = await nodeFileTrace(entriesToTrace, {
base: root,
base: this.tracingRoot,
processCwd: this.appDir,
readFile,
readlink,
......@@ -355,25 +358,28 @@ export class TraceEntryPointsPlugin implements webpack5.WebpackPluginInstance {
const parentFilesMap = getFilesMapFromReasons(fileList, reasons)
entryPaths.forEach((entry) => {
const entryName = entryNameMap.get(entry)!
const normalizedEntry = nodePath.relative(root, entry)
const normalizedEntry = nodePath.relative(
this.tracingRoot,
entry
)
const curExtraEntries = additionalEntries.get(entryName)
const finalDeps = new Set<string>()
parentFilesMap.get(normalizedEntry)?.forEach((dep) => {
finalDeps.add(nodePath.join(root, dep))
finalDeps.add(nodePath.join(this.tracingRoot, dep))
})
if (curExtraEntries) {
for (const extraEntry of curExtraEntries.keys()) {
const normalizedExtraEntry = nodePath.relative(
root,
this.tracingRoot,
extraEntry
)
finalDeps.add(extraEntry)
parentFilesMap
.get(normalizedExtraEntry)
?.forEach((dep) => {
finalDeps.add(nodePath.join(root, dep))
finalDeps.add(nodePath.join(this.tracingRoot, dep))
})
}
}
......
......@@ -155,6 +155,7 @@ export type NextConfig = { [key: string]: any } & {
serverComponents?: boolean
fullySpecified?: boolean
urlImports?: NonNullable<webpack5.Configuration['experiments']>['buildHttp']
outputFileTracingRoot?: string
}
}
......@@ -236,6 +237,7 @@ export const defaultConfig: NextConfig = {
concurrentFeatures: false,
serverComponents: false,
fullySpecified: false,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
},
future: {
strictPostcssConfiguration: false,
......
......@@ -132,6 +132,7 @@ export function runNextCommand(argv, options = {}) {
...options.env,
NODE_ENV: '',
__NEXT_TEST_MODE: 'true',
NEXT_PRIVATE_OUTPUT_TRACE_ROOT: path.join(__dirname, '../../'),
}
return new Promise((resolve, reject) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment