diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 6729c182a510e..b99d232c5215a 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1581,86 +1581,107 @@ export default async function build( traceMemoryUsage('Starting build', nextBuildSpan) if (!isGenerateMode) { - if (runServerAndEdgeInParallel || collectServerBuildTracesInParallel) { - let durationInSeconds = 0 - - const serverBuildPromise = webpackBuild(useBuildWorker, [ - 'server', - ]).then((res) => { - traceMemoryUsage('Finished server compilation', nextBuildSpan) - buildTraceContext = res.buildTraceContext - durationInSeconds += res.duration - - if (collectServerBuildTracesInParallel) { - const buildTraceWorker = new Worker( - require.resolve('./collect-build-traces'), - { - numWorkers: 1, - exposedMethods: ['collectBuildTraces'], - } - ) as Worker & typeof import('./collect-build-traces') - - buildTracesPromise = buildTraceWorker - .collectBuildTraces({ - dir, - config, - distDir, - // Serialize Map as this is sent to the worker. - edgeRuntimeRoutes: collectRoutesUsingEdgeRuntime(new Map()), - staticPages: [], - hasSsrAmpPages: false, - buildTraceContext, - outputFileTracingRoot, - isFlyingShuttle: !!config.experimental.flyingShuttle, - }) - .catch((err) => { - console.error(err) - process.exit(1) - }) - } - }) - if (!runServerAndEdgeInParallel) { - await serverBuildPromise - } - - const edgeBuildPromise = webpackBuild(useBuildWorker, [ - 'edge-server', - ]).then((res) => { - durationInSeconds += res.duration - traceMemoryUsage('Finished edge-server compilation', nextBuildSpan) - }) - if (runServerAndEdgeInParallel) { - await serverBuildPromise - } - await edgeBuildPromise - - await webpackBuild(useBuildWorker, ['client']).then((res) => { - durationInSeconds += res.duration - traceMemoryUsage('Finished client compilation', nextBuildSpan) - }) + if (turboNextBuild) { + const { duration: compilerDuration, ...rest } = await turbopackBuild() + traceMemoryUsage('Finished build', nextBuildSpan) - Log.event('Compiled successfully') + buildTraceContext = rest.buildTraceContext telemetry.record( eventBuildCompleted(pagesPaths, { - durationInSeconds, + durationInSeconds: compilerDuration, totalAppPagesCount, }) ) } else { - const { duration: compilerDuration, ...rest } = turboNextBuild - ? await turbopackBuild() - : await webpackBuild(useBuildWorker, null) - traceMemoryUsage('Finished build', nextBuildSpan) + if ( + runServerAndEdgeInParallel || + collectServerBuildTracesInParallel + ) { + let durationInSeconds = 0 + + const serverBuildPromise = webpackBuild(useBuildWorker, [ + 'server', + ]).then((res) => { + traceMemoryUsage('Finished server compilation', nextBuildSpan) + buildTraceContext = res.buildTraceContext + durationInSeconds += res.duration + + if (collectServerBuildTracesInParallel) { + const buildTraceWorker = new Worker( + require.resolve('./collect-build-traces'), + { + numWorkers: 1, + exposedMethods: ['collectBuildTraces'], + } + ) as Worker & typeof import('./collect-build-traces') + + buildTracesPromise = buildTraceWorker + .collectBuildTraces({ + dir, + config, + distDir, + // Serialize Map as this is sent to the worker. + edgeRuntimeRoutes: collectRoutesUsingEdgeRuntime(new Map()), + staticPages: [], + hasSsrAmpPages: false, + buildTraceContext, + outputFileTracingRoot, + isFlyingShuttle: !!config.experimental.flyingShuttle, + }) + .catch((err) => { + console.error(err) + process.exit(1) + }) + } + }) + if (!runServerAndEdgeInParallel) { + await serverBuildPromise + } - buildTraceContext = rest.buildTraceContext + const edgeBuildPromise = webpackBuild(useBuildWorker, [ + 'edge-server', + ]).then((res) => { + durationInSeconds += res.duration + traceMemoryUsage( + 'Finished edge-server compilation', + nextBuildSpan + ) + }) + if (runServerAndEdgeInParallel) { + await serverBuildPromise + } + await edgeBuildPromise - telemetry.record( - eventBuildCompleted(pagesPaths, { - durationInSeconds: compilerDuration, - totalAppPagesCount, + await webpackBuild(useBuildWorker, ['client']).then((res) => { + durationInSeconds += res.duration + traceMemoryUsage('Finished client compilation', nextBuildSpan) }) - ) + + Log.event('Compiled successfully') + + telemetry.record( + eventBuildCompleted(pagesPaths, { + durationInSeconds, + totalAppPagesCount, + }) + ) + } else { + const { duration: compilerDuration, ...rest } = await webpackBuild( + useBuildWorker, + null + ) + traceMemoryUsage('Finished build', nextBuildSpan) + + buildTraceContext = rest.buildTraceContext + + telemetry.record( + eventBuildCompleted(pagesPaths, { + durationInSeconds: compilerDuration, + totalAppPagesCount, + }) + ) + } } } diff --git a/test/turbopack-build-tests-manifest.json b/test/turbopack-build-tests-manifest.json index db9b91f4ebbe7..7876f3a85abc4 100644 --- a/test/turbopack-build-tests-manifest.json +++ b/test/turbopack-build-tests-manifest.json @@ -1016,7 +1016,6 @@ "app dir - basic server components should serve client component should serve server-side", "app dir - basic server components should serve shared component", "app dir - basic should ensure the suffix is at the end of the stream", - "app dir - basic should generate build traces correctly", "app dir - basic should handle hash in initial url", "app dir - basic should have correct searchParams and params (client)", "app dir - basic should have correct searchParams and params (server)", @@ -1024,7 +1023,6 @@ "app dir - basic should include layouts when no direct parent layout", "app dir - basic should include parent document when no direct parent layout", "app dir - basic should match redirects in pages correctly $path", - "app dir - basic should not apply client router filter on shallow", "app dir - basic should not create new root layout when nested (optional)", "app dir - basic should not include parent when not in parent directory", "app dir - basic should not rerender layout when navigating between routes in the same layout", @@ -1043,7 +1041,6 @@ "app dir - basic should serve from public", "app dir - basic should serve nested parent", "app dir - basic should serve page as a segment name correctly", - "app dir - basic should successfully detect app route during prefetch", "app dir - basic should use new root layout when provided", "app dir - basic should use text/x-component for flight", "app dir - basic should use text/x-component for flight with edge runtime", @@ -1052,6 +1049,9 @@ "app dir - basic template component should render the template that is a server component and rerender on navigation" ], "failed": [ + "app dir - basic should successfully detect app route during prefetch", + "app dir - basic should not apply client router filter on shallow", + "app dir - basic should generate build traces correctly", "app dir - basic should encode chunk path correctly", "app dir - basic should serve polyfills for browsers that do not support modules" ],