Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wbinnssmith committed Jan 30, 2025
1 parent 5793ba2 commit a1c8d96
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 131 deletions.
83 changes: 20 additions & 63 deletions packages/next/src/build/handle-entrypoints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { CustomRoutes } from '../lib/load-custom-routes'
import type { TurbopackManifestLoader } from '../shared/lib/turbopack/manifest-loader'
import type {
Entrypoints,
Expand All @@ -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<Entrypoints> {
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:
Expand All @@ -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({
Expand All @@ -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)
Expand Down
94 changes: 26 additions & 68 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
})
Expand All @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down

0 comments on commit a1c8d96

Please sign in to comment.