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