Unverified Commit b1f154d8 authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

misc: move entrypoints creation into webpack build step (3/6) (#45456)

During build, entrypoint creation is only useful for the webpack build
process. Since I extracted it to another file, it makes sense to also
move it there.

Note: the way the params are added sucks, this is corrected in the next
diff.


<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 85ec9c5d
...@@ -133,7 +133,7 @@ export function createPagesMapping({ ...@@ -133,7 +133,7 @@ export function createPagesMapping({
} }
} }
interface CreateEntrypointsParams { export interface CreateEntrypointsParams {
buildId: string buildId: string
config: NextConfigComplete config: NextConfigComplete
envFiles: LoadedEnvFiles envFiles: LoadedEnvFiles
......
import '../lib/setup-exception-listeners' import '../lib/setup-exception-listeners'
import type { webpack } from 'next/dist/compiled/webpack/webpack'
import { loadEnvConfig } from '@next/env' import { loadEnvConfig } from '@next/env'
import chalk from 'next/dist/compiled/chalk' import chalk from 'next/dist/compiled/chalk'
import crypto from 'crypto' import crypto from 'crypto'
...@@ -82,7 +81,7 @@ import { ...@@ -82,7 +81,7 @@ import {
} from '../telemetry/events' } from '../telemetry/events'
import { Telemetry } from '../telemetry/storage' import { Telemetry } from '../telemetry/storage'
import { getPageStaticInfo } from './analysis/get-page-static-info' import { getPageStaticInfo } from './analysis/get-page-static-info'
import { createEntrypoints, createPagesMapping } from './entries' import { createPagesMapping } from './entries'
import { generateBuildId } from './generate-build-id' import { generateBuildId } from './generate-build-id'
import { isWriteable } from './is-writeable' import { isWriteable } from './is-writeable'
import * as Log from './output/log' import * as Log from './output/log'
...@@ -149,12 +148,6 @@ export const NextBuildContext: Partial<{ ...@@ -149,12 +148,6 @@ export const NextBuildContext: Partial<{
telemetryPlugin: TelemetryPlugin telemetryPlugin: TelemetryPlugin
buildSpinner: any buildSpinner: any
nextBuildSpan: Span nextBuildSpan: Span
entrypoints: {
client: webpack.EntryObject
server: webpack.EntryObject
edgeServer: webpack.EntryObject
middlewareMatchers: undefined
}
dir: string dir: string
}> = {} }> = {}
...@@ -565,26 +558,6 @@ export default async function build( ...@@ -565,26 +558,6 @@ export default async function build(
}) })
} }
const entrypoints = await nextBuildSpan
.traceChild('create-entrypoints')
.traceAsyncFn(() =>
createEntrypoints({
buildId,
config,
envFiles: loadedEnvFiles,
isDev: false,
pages: mappedPages,
pagesDir,
previewMode: previewProps,
rootDir: dir,
rootPaths: mappedRootPaths,
appDir,
appPaths: mappedAppPages,
pageExtensions: config.pageExtensions,
})
)
NextBuildContext.entrypoints = entrypoints
const pagesPageKeys = Object.keys(mappedPages) const pagesPageKeys = Object.keys(mappedPages)
const conflictingAppPagePaths: [pagePath: string, appPath: string][] = [] const conflictingAppPagePaths: [pagePath: string, appPath: string][] = []
...@@ -947,17 +920,32 @@ export default async function build( ...@@ -947,17 +920,32 @@ export default async function build(
ignore: [] as string[], ignore: [] as string[],
})) }))
const webpackBuildDuration = await webpackBuild({ const webpackBuildDuration = await webpackBuild(
buildId, {
config, buildId,
pagesDir, config,
reactProductionProfiling, pagesDir,
rewrites, reactProductionProfiling,
target, rewrites,
appDir, target,
noMangling, appDir,
middlewareMatchers: entrypoints.middlewareMatchers, noMangling,
}) },
{
buildId,
config,
envFiles: loadedEnvFiles,
isDev: false,
pages: mappedPages,
pagesDir,
previewMode: previewProps,
rootDir: dir,
rootPaths: mappedRootPaths,
appDir,
appPaths: mappedAppPages,
pageExtensions: config.pageExtensions,
}
)
telemetry.record( telemetry.record(
eventBuildCompleted(pagesPaths, { eventBuildCompleted(pagesPaths, {
......
...@@ -15,8 +15,8 @@ import { injectedClientEntries } from './webpack/plugins/flight-client-entry-plu ...@@ -15,8 +15,8 @@ import { injectedClientEntries } from './webpack/plugins/flight-client-entry-plu
import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin' import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin'
import { Rewrite } from '../lib/load-custom-routes' import { Rewrite } from '../lib/load-custom-routes'
import { NextConfigComplete } from '../server/config-shared' import { NextConfigComplete } from '../server/config-shared'
import { MiddlewareMatcher } from './analysis/get-page-static-info'
import { NextBuildContext } from '.' import { NextBuildContext } from '.'
import { CreateEntrypointsParams, createEntrypoints } from './entries'
type CompilerResult = { type CompilerResult = {
errors: webpack.StatsError[] errors: webpack.StatsError[]
...@@ -34,21 +34,23 @@ function isTelemetryPlugin(plugin: unknown): plugin is TelemetryPlugin { ...@@ -34,21 +34,23 @@ function isTelemetryPlugin(plugin: unknown): plugin is TelemetryPlugin {
return plugin instanceof TelemetryPlugin return plugin instanceof TelemetryPlugin
} }
export async function webpackBuild(commonWebpackOptions: { export async function webpackBuild(
buildId: string commonWebpackOptions: {
config: NextConfigComplete buildId: string
pagesDir: string | undefined config: NextConfigComplete
reactProductionProfiling: boolean pagesDir: string | undefined
rewrites: { reactProductionProfiling: boolean
fallback: Rewrite[] rewrites: {
afterFiles: Rewrite[] fallback: Rewrite[]
beforeFiles: Rewrite[] afterFiles: Rewrite[]
} beforeFiles: Rewrite[]
target: string }
appDir: string | undefined target: string
noMangling: boolean appDir: string | undefined
middlewareMatchers: MiddlewareMatcher[] | undefined noMangling: boolean
}): Promise<number> { },
entrypointsParams: CreateEntrypointsParams
): Promise<number> {
let result: CompilerResult | null = { let result: CompilerResult | null = {
warnings: [], warnings: [],
errors: [], errors: [],
...@@ -62,7 +64,10 @@ export async function webpackBuild(commonWebpackOptions: { ...@@ -62,7 +64,10 @@ export async function webpackBuild(commonWebpackOptions: {
// IIFE to isolate locals and avoid retaining memory too long // IIFE to isolate locals and avoid retaining memory too long
const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler') const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler')
const entrypoints = NextBuildContext.entrypoints! const entrypoints = await nextBuildSpan
.traceChild('create-entrypoints')
.traceAsyncFn(() => createEntrypoints(entrypointsParams))
const configs = await runWebpackSpan const configs = await runWebpackSpan
.traceChild('generate-webpack-config') .traceChild('generate-webpack-config')
.traceAsyncFn(() => .traceAsyncFn(() =>
...@@ -70,18 +75,21 @@ export async function webpackBuild(commonWebpackOptions: { ...@@ -70,18 +75,21 @@ export async function webpackBuild(commonWebpackOptions: {
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
...commonWebpackOptions, ...commonWebpackOptions,
runWebpackSpan, runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.client, compilerType: COMPILER_NAMES.client,
entrypoints: entrypoints.client, entrypoints: entrypoints.client,
}), }),
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
...commonWebpackOptions, ...commonWebpackOptions,
runWebpackSpan, runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.server, compilerType: COMPILER_NAMES.server,
entrypoints: entrypoints.server, entrypoints: entrypoints.server,
}), }),
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
...commonWebpackOptions, ...commonWebpackOptions,
runWebpackSpan, runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.edgeServer, compilerType: COMPILER_NAMES.edgeServer,
entrypoints: entrypoints.edgeServer, entrypoints: entrypoints.edgeServer,
}), }),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment