Skip to content

Commit

Permalink
refactor(turbopack): wrap manifest loading in helper class
Browse files Browse the repository at this point in the history
  • Loading branch information
ForsakenHarmony committed Feb 15, 2024
1 parent f24c322 commit 8ec86a3
Show file tree
Hide file tree
Showing 5 changed files with 855 additions and 1,064 deletions.
133 changes: 39 additions & 94 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,12 @@ import { isInterceptionRouteAppPath } from '../server/future/helpers/interceptio
import {
getTurbopackJsConfig,
handleEntrypoints,
type GlobalEntrypoints,
type CurrentEntrypoints,
type CurrentIssues,
handleRouteType,
handlePagesErrorRoute,
} from '../server/dev/turbopack-utils'
import {
type BuildManifests,
type AppBuildManifests,
type PagesManifests,
type AppPathsManifests,
type MiddlewareManifests,
type ActionManifests,
type FontManifests,
type LoadableManifests,
writeManifests,
} from '../server/dev/turbopack/manifest-loader'
import { TurbopackManifestLoader } from '../server/dev/turbopack/manifest-loader'
import type { Entrypoints } from '../server/dev/turbopack/types'

import { buildCustomRoute } from '../lib/build-custom-route'

Expand Down Expand Up @@ -1336,9 +1325,10 @@ export default async function build(
duration: number
buildTraceContext: undefined
}> {
if (!process.env.TURBOPACK || !process.env.TURBOPACK_BUILD) {
if (!(process.env.TURBOPACK && process.env.TURBOPACK_BUILD)) {
throw new Error("next build doesn't support turbopack yet")
}

// TODO: Without NODE_ENV=development React will error that the RSC payload was rendered using development React while renderToHTML is called on the production React.
// This is caused by Turbopack not having the production build option yet.
// @ts-expect-error
Expand Down Expand Up @@ -1386,22 +1376,21 @@ export default async function build(

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const entrypointsSubscription = project.entrypointsSubscribe()
const globalEntrypoints: GlobalEntrypoints = {
app: undefined,
document: undefined,
error: undefined,
const currentEntrypoints: Entrypoints = {
global: {
app: undefined,
document: undefined,
error: undefined,

middleware: undefined,
instrumentation: undefined,
},
routes: new Map(),
}
const currentEntrypoints: CurrentEntrypoints = new Map()

const currentIssues: CurrentIssues = new Map()

const buildManifests: BuildManifests = new Map()
const appBuildManifests: AppBuildManifests = new Map()
const pagesManifests: PagesManifests = new Map()
const appPathsManifests: AppPathsManifests = new Map()
const middlewareManifests: MiddlewareManifests = new Map()
const actionManifests: ActionManifests = new Map()
const fontManifests: FontManifests = new Map()
const loadableManifests: LoadableManifests = new Map()
const manifestLoader = new TurbopackManifestLoader({ buildId, distDir })

// TODO: implement this
const emptyRewritesObjToBeImplemented = {
Expand All @@ -1412,102 +1401,58 @@ export default async function build(

for await (const entrypoints of entrypointsSubscription) {
await handleEntrypoints({
rewrites: emptyRewritesObjToBeImplemented,
nextConfig: config,
entrypoints,
serverFields: undefined,
propagateServerField: undefined,
distDir,
buildId,
globalEntrypoints,

currentEntrypoints,
changeSubscriptions: undefined,
changeSubscription: undefined,
clearChangeSubscription: undefined,
sendHmr: undefined,
startBuilding: undefined,
handleRequireCacheClearing: undefined,
prevMiddleware: undefined,

currentIssues,
buildManifests,
appBuildManifests,
pagesManifests,
appPathsManifests,
middlewareManifests,
actionManifests,
fontManifests,
loadableManifests,
manifestLoader,
nextConfig: config,
rewrites: emptyRewritesObjToBeImplemented,

hooks: {},
})

const promises = []
for (const [page, route] of currentEntrypoints) {
for (const [page, route] of currentEntrypoints.routes) {
promises.push(
handleRouteType({
rewrites: emptyRewritesObjToBeImplemented,
distDir,
buildId,
globalEntrypoints,
currentIssues,
buildManifests,
appBuildManifests,
pagesManifests,
appPathsManifests,
middlewareManifests,
actionManifests,
fontManifests,
loadableManifests,
currentEntrypoints,
handleRequireCacheClearing: undefined,
changeSubscription: undefined,
readyIds: undefined,
page,
route,

currentIssues,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,

hooks: {},
})
)
}

promises.push(
handlePagesErrorRoute({
rewrites: emptyRewritesObjToBeImplemented,
globalEntrypoints,
currentIssues,
distDir,
buildId,
buildManifests,
pagesManifests,
fontManifests,
appBuildManifests,
appPathsManifests,
middlewareManifests,
actionManifests,
loadableManifests,
currentEntrypoints,
handleRequireCacheClearing: undefined,
changeSubscription: undefined,
entrypoints: currentEntrypoints,
manifestLoader,
rewrites: emptyRewritesObjToBeImplemented,

hooks: {},
})
)
await Promise.all(promises)
break
}
await writeManifests({
await manifestLoader.writeManifests({
rewrites: emptyRewritesObjToBeImplemented,
distDir,
buildId,
buildManifests,
appBuildManifests,
pagesManifests,
appPathsManifests,
middlewareManifests,
actionManifests,
fontManifests,
loadableManifests,
currentEntrypoints,
routes: currentEntrypoints.routes,
})
return {
duration: process.hrtime(startTime)[0],
buildTraceContext: undefined,
}
}

let buildTraceContext: undefined | BuildTraceContext
let buildTracesPromise: Promise<any> | undefined = undefined

Expand Down
Loading

0 comments on commit 8ec86a3

Please sign in to comment.