Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Turbopack build runs when experimental-compile option is used #67049

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 90 additions & 69 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
)
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1016,15 +1016,13 @@
"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 </body></html> 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)",
"app dir - basic should include document html and body",
"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",
Expand All @@ -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",
Expand All @@ -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"
],
Expand Down
Loading