Skip to content

Commit 49e3522

Browse files
committed
cleanup
1 parent 5793ba2 commit 49e3522

File tree

2 files changed

+46
-131
lines changed

2 files changed

+46
-131
lines changed

packages/next/src/build/handle-entrypoints.ts

+20-63
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { CustomRoutes } from '../lib/load-custom-routes'
21
import type { TurbopackManifestLoader } from '../shared/lib/turbopack/manifest-loader'
32
import type {
43
Entrypoints,
@@ -9,40 +8,29 @@ import type {
98
import { getEntryKey } from '../shared/lib/turbopack/entry-key'
109
import * as Log from './output/log'
1110

12-
export async function handleEntrypoints(
13-
entrypointsOp: RawEntrypoints,
14-
manifestLoader: TurbopackManifestLoader
11+
export async function rawEntrypointsToEntrypoints(
12+
entrypointsOp: RawEntrypoints
1513
): Promise<Entrypoints> {
16-
const { middleware, instrumentation } = entrypointsOp
17-
18-
const entrypoints = {
19-
global: {
20-
app: entrypointsOp.pagesAppEndpoint,
21-
document: entrypointsOp.pagesDocumentEndpoint,
22-
error: entrypointsOp.pagesErrorEndpoint,
23-
instrumentation: entrypointsOp.instrumentation,
24-
},
25-
page: new Map(),
26-
app: new Map(),
27-
} as Entrypoints
14+
const page = new Map()
15+
const app = new Map()
2816

2917
for (const [pathname, route] of entrypointsOp.routes) {
3018
switch (route.type) {
3119
case 'page':
3220
case 'page-api':
33-
entrypoints.page.set(pathname, route)
21+
page.set(pathname, route)
3422
break
3523
case 'app-page': {
36-
route.pages.forEach((page) => {
37-
entrypoints.app.set(page.originalName, {
24+
for (const p of route.pages) {
25+
app.set(p.originalName, {
3826
type: 'app-page',
39-
...page,
27+
...p,
4028
})
41-
})
29+
}
4230
break
4331
}
4432
case 'app-route': {
45-
entrypoints.app.set(route.originalName, route)
33+
app.set(route.originalName, route)
4634
break
4735
}
4836
default:
@@ -51,44 +39,17 @@ export async function handleEntrypoints(
5139
}
5240
}
5341

54-
if (instrumentation) {
55-
await manifestLoader.loadMiddlewareManifest(
56-
'instrumentation',
57-
'instrumentation'
58-
)
59-
}
60-
61-
if (middleware) {
62-
await manifestLoader.loadMiddlewareManifest('middleware', 'middleware')
42+
return {
43+
global: {
44+
app: entrypointsOp.pagesAppEndpoint,
45+
document: entrypointsOp.pagesDocumentEndpoint,
46+
error: entrypointsOp.pagesErrorEndpoint,
47+
instrumentation: entrypointsOp.instrumentation,
48+
middleware: entrypointsOp.middleware,
49+
},
50+
page,
51+
app,
6352
}
64-
65-
return entrypoints
66-
}
67-
68-
export async function handlePagesErrorRoute({
69-
entrypoints,
70-
manifestLoader,
71-
productionRewrites,
72-
}: {
73-
entrypoints: Entrypoints
74-
manifestLoader: TurbopackManifestLoader
75-
productionRewrites: CustomRoutes['rewrites'] | undefined
76-
}) {
77-
await manifestLoader.loadBuildManifest('_app')
78-
await manifestLoader.loadPagesManifest('_app')
79-
await manifestLoader.loadFontManifest('_app')
80-
81-
await manifestLoader.loadPagesManifest('_document')
82-
83-
await manifestLoader.loadBuildManifest('_error')
84-
await manifestLoader.loadPagesManifest('_error')
85-
await manifestLoader.loadFontManifest('_error')
86-
87-
await manifestLoader.writeManifests({
88-
devRewrites: undefined,
89-
productionRewrites,
90-
entrypoints,
91-
})
9253
}
9354

9455
export async function handleRouteType({
@@ -106,10 +67,6 @@ export async function handleRouteType({
10667
case 'page': {
10768
const serverKey = getEntryKey('pages', 'server', page)
10869

109-
await manifestLoader.loadBuildManifest('_app')
110-
await manifestLoader.loadPagesManifest('_app')
111-
await manifestLoader.loadPagesManifest('_document')
112-
11370
const type = await route.htmlEndpoint.runtime()
11471

11572
await manifestLoader.loadBuildManifest(page)

packages/next/src/build/index.ts

+26-68
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ import { InvariantError } from '../shared/lib/invariant-error'
208208
import { HTML_LIMITED_BOT_UA_RE_STRING } from '../shared/lib/router/utils/is-bot'
209209
import type { UseCacheTrackerKey } from './webpack/plugins/telemetry-plugin/use-cache-tracker-utils'
210210
import {
211-
handleEntrypoints,
212-
handlePagesErrorRoute,
213211
handleRouteType,
212+
rawEntrypointsToEntrypoints,
214213
} from './handle-entrypoints'
215214
import {
216215
formatIssue,
@@ -1453,13 +1452,6 @@ export default async function build(
14531452
continue
14541453
}
14551454

1456-
console.log(
1457-
'pushing issue with severity',
1458-
issue.severity,
1459-
'msg',
1460-
formatIssue(issue).slice(0, 40)
1461-
)
1462-
14631455
topLevelErrors.push({
14641456
message: formatIssue(issue),
14651457
})
@@ -1473,11 +1465,8 @@ export default async function build(
14731465
)
14741466
}
14751467

1476-
const currentEntrypoints = await handleEntrypoints(
1477-
entrypoints,
1478-
manifestLoader
1479-
// customRoutes.rewrites
1480-
)
1468+
const currentEntrypoints =
1469+
await rawEntrypointsToEntrypoints(entrypoints)
14811470

14821471
const progress = createProgress(
14831472
currentEntrypoints.page.size + currentEntrypoints.app.size + 1,
@@ -1533,13 +1522,29 @@ export default async function build(
15331522
)
15341523
}
15351524

1536-
enqueue(() =>
1537-
handlePagesErrorRoute({
1538-
entrypoints: currentEntrypoints,
1539-
manifestLoader,
1540-
productionRewrites: customRoutes.rewrites,
1541-
})
1542-
)
1525+
enqueue(() => manifestLoader.loadBuildManifest('_app'))
1526+
enqueue(() => manifestLoader.loadPagesManifest('_app'))
1527+
enqueue(() => manifestLoader.loadFontManifest('_app'))
1528+
enqueue(() => manifestLoader.loadPagesManifest('_document'))
1529+
enqueue(() => manifestLoader.loadBuildManifest('_error'))
1530+
enqueue(() => manifestLoader.loadPagesManifest('_error'))
1531+
enqueue(() => manifestLoader.loadFontManifest('_error'))
1532+
1533+
if (entrypoints.instrumentation) {
1534+
enqueue(() =>
1535+
manifestLoader.loadMiddlewareManifest(
1536+
'instrumentation',
1537+
'instrumentation'
1538+
)
1539+
)
1540+
}
1541+
1542+
if (entrypoints.middleware) {
1543+
enqueue(() =>
1544+
manifestLoader.loadMiddlewareManifest('middleware', 'middleware')
1545+
)
1546+
}
1547+
15431548
await Promise.all(promises)
15441549

15451550
await manifestLoader.writeManifests({
@@ -1548,54 +1553,7 @@ export default async function build(
15481553
entrypoints: currentEntrypoints,
15491554
})
15501555

1551-
// const errors: {
1552-
// page: string
1553-
// message: string
1554-
// }[] = []
1555-
// const warnings: {
1556-
// page: string
1557-
// message: string
1558-
// }[] = []
1559-
// for (const [page, entryIssues] of currentEntryIssues) {
1560-
// for (const issue of entryIssues.values()) {
1561-
// if (issue.severity !== 'warning') {
1562-
// errors.push({
1563-
// page,
1564-
// message: formatIssue(issue),
1565-
// })
1566-
// } else {
1567-
// if (isRelevantWarning(issue)) {
1568-
// warnings.push({
1569-
// page,
1570-
// message: formatIssue(issue),
1571-
// })
1572-
// }
1573-
// }
1574-
// }
1575-
// }
1576-
15771556
const shutdownPromise = project.shutdown()
1578-
1579-
// if (warnings.length > 0) {
1580-
// Log.warn(
1581-
// `Turbopack build collected ${warnings.length} warnings:\n${warnings
1582-
// .map((e) => {
1583-
// return 'Page: ' + e.page + '\n' + e.message
1584-
// })
1585-
// .join('\n')}`
1586-
// )
1587-
// }
1588-
1589-
// if (errors.length > 0) {
1590-
// throw new Error(
1591-
// `Turbopack build failed with ${errors.length} errors:\n${errors
1592-
// .map((e) => {
1593-
// return 'Page: ' + e.page + '\n' + e.message
1594-
// })
1595-
// .join('\n')}`
1596-
// )
1597-
// }
1598-
15991557
const time = process.hrtime(startTime)
16001558
return {
16011559
duration: time[0] + time[1] / 1e9,

0 commit comments

Comments
 (0)