From a1c8d9619e996491af6dee3cdfba0addb72b4c3a Mon Sep 17 00:00:00 2001 From: Will Binns-Smith Date: Wed, 29 Jan 2025 17:05:15 -0800 Subject: [PATCH] cleanup --- packages/next/src/build/handle-entrypoints.ts | 83 ++++------------ packages/next/src/build/index.ts | 94 +++++-------------- 2 files changed, 46 insertions(+), 131 deletions(-) diff --git a/packages/next/src/build/handle-entrypoints.ts b/packages/next/src/build/handle-entrypoints.ts index df3ea65ff8d23..89f4cac624017 100644 --- a/packages/next/src/build/handle-entrypoints.ts +++ b/packages/next/src/build/handle-entrypoints.ts @@ -1,4 +1,3 @@ -import type { CustomRoutes } from '../lib/load-custom-routes' import type { TurbopackManifestLoader } from '../shared/lib/turbopack/manifest-loader' import type { Entrypoints, @@ -9,40 +8,29 @@ import type { import { getEntryKey } from '../shared/lib/turbopack/entry-key' import * as Log from './output/log' -export async function handleEntrypoints( - entrypointsOp: RawEntrypoints, - manifestLoader: TurbopackManifestLoader +export async function rawEntrypointsToEntrypoints( + entrypointsOp: RawEntrypoints ): Promise { - const { middleware, instrumentation } = entrypointsOp - - const entrypoints = { - global: { - app: entrypointsOp.pagesAppEndpoint, - document: entrypointsOp.pagesDocumentEndpoint, - error: entrypointsOp.pagesErrorEndpoint, - instrumentation: entrypointsOp.instrumentation, - }, - page: new Map(), - app: new Map(), - } as Entrypoints + const page = new Map() + const app = new Map() for (const [pathname, route] of entrypointsOp.routes) { switch (route.type) { case 'page': case 'page-api': - entrypoints.page.set(pathname, route) + page.set(pathname, route) break case 'app-page': { - route.pages.forEach((page) => { - entrypoints.app.set(page.originalName, { + for (const p of route.pages) { + app.set(p.originalName, { type: 'app-page', - ...page, + ...p, }) - }) + } break } case 'app-route': { - entrypoints.app.set(route.originalName, route) + app.set(route.originalName, route) break } default: @@ -51,44 +39,17 @@ export async function handleEntrypoints( } } - if (instrumentation) { - await manifestLoader.loadMiddlewareManifest( - 'instrumentation', - 'instrumentation' - ) - } - - if (middleware) { - await manifestLoader.loadMiddlewareManifest('middleware', 'middleware') + return { + global: { + app: entrypointsOp.pagesAppEndpoint, + document: entrypointsOp.pagesDocumentEndpoint, + error: entrypointsOp.pagesErrorEndpoint, + instrumentation: entrypointsOp.instrumentation, + middleware: entrypointsOp.middleware, + }, + page, + app, } - - return entrypoints -} - -export async function handlePagesErrorRoute({ - entrypoints, - manifestLoader, - productionRewrites, -}: { - entrypoints: Entrypoints - manifestLoader: TurbopackManifestLoader - productionRewrites: CustomRoutes['rewrites'] | undefined -}) { - await manifestLoader.loadBuildManifest('_app') - await manifestLoader.loadPagesManifest('_app') - await manifestLoader.loadFontManifest('_app') - - await manifestLoader.loadPagesManifest('_document') - - await manifestLoader.loadBuildManifest('_error') - await manifestLoader.loadPagesManifest('_error') - await manifestLoader.loadFontManifest('_error') - - await manifestLoader.writeManifests({ - devRewrites: undefined, - productionRewrites, - entrypoints, - }) } export async function handleRouteType({ @@ -106,10 +67,6 @@ export async function handleRouteType({ case 'page': { const serverKey = getEntryKey('pages', 'server', page) - await manifestLoader.loadBuildManifest('_app') - await manifestLoader.loadPagesManifest('_app') - await manifestLoader.loadPagesManifest('_document') - const type = await route.htmlEndpoint.runtime() await manifestLoader.loadBuildManifest(page) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index fed7940fbea42..993b965167012 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -208,9 +208,8 @@ import { InvariantError } from '../shared/lib/invariant-error' import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot' import type { UseCacheTrackerKey } from './webpack/plugins/telemetry-plugin/use-cache-tracker-utils' import { - handleEntrypoints, - handlePagesErrorRoute, handleRouteType, + rawEntrypointsToEntrypoints, } from './handle-entrypoints' import { formatIssue, @@ -1453,13 +1452,6 @@ export default async function build( continue } - console.log( - 'pushing issue with severity', - issue.severity, - 'msg', - formatIssue(issue).slice(0, 40) - ) - topLevelErrors.push({ message: formatIssue(issue), }) @@ -1473,11 +1465,8 @@ export default async function build( ) } - const currentEntrypoints = await handleEntrypoints( - entrypoints, - manifestLoader - // customRoutes.rewrites - ) + const currentEntrypoints = + await rawEntrypointsToEntrypoints(entrypoints) const progress = createProgress( currentEntrypoints.page.size + currentEntrypoints.app.size + 1, @@ -1533,13 +1522,29 @@ export default async function build( ) } - enqueue(() => - handlePagesErrorRoute({ - entrypoints: currentEntrypoints, - manifestLoader, - productionRewrites: customRoutes.rewrites, - }) - ) + enqueue(() => manifestLoader.loadBuildManifest('_app')) + enqueue(() => manifestLoader.loadPagesManifest('_app')) + enqueue(() => manifestLoader.loadFontManifest('_app')) + enqueue(() => manifestLoader.loadPagesManifest('_document')) + enqueue(() => manifestLoader.loadBuildManifest('_error')) + enqueue(() => manifestLoader.loadPagesManifest('_error')) + enqueue(() => manifestLoader.loadFontManifest('_error')) + + if (entrypoints.instrumentation) { + enqueue(() => + manifestLoader.loadMiddlewareManifest( + 'instrumentation', + 'instrumentation' + ) + ) + } + + if (entrypoints.middleware) { + enqueue(() => + manifestLoader.loadMiddlewareManifest('middleware', 'middleware') + ) + } + await Promise.all(promises) await manifestLoader.writeManifests({ @@ -1548,54 +1553,7 @@ export default async function build( entrypoints: currentEntrypoints, }) - // const errors: { - // page: string - // message: string - // }[] = [] - // const warnings: { - // page: string - // message: string - // }[] = [] - // for (const [page, entryIssues] of currentEntryIssues) { - // for (const issue of entryIssues.values()) { - // if (issue.severity !== 'warning') { - // errors.push({ - // page, - // message: formatIssue(issue), - // }) - // } else { - // if (isRelevantWarning(issue)) { - // warnings.push({ - // page, - // message: formatIssue(issue), - // }) - // } - // } - // } - // } - const shutdownPromise = project.shutdown() - - // if (warnings.length > 0) { - // Log.warn( - // `Turbopack build collected ${warnings.length} warnings:\n${warnings - // .map((e) => { - // return 'Page: ' + e.page + '\n' + e.message - // }) - // .join('\n')}` - // ) - // } - - // if (errors.length > 0) { - // throw new Error( - // `Turbopack build failed with ${errors.length} errors:\n${errors - // .map((e) => { - // return 'Page: ' + e.page + '\n' + e.message - // }) - // .join('\n')}` - // ) - // } - const time = process.hrtime(startTime) return { duration: time[0] + time[1] / 1e9,