Fix next phase for next build (#60969)

In both dev server and production build we both use `getStartServerInfo`
to log the basic info but for prod build we should always respect to use
"build" phase

Fixes #57927 
Closes NEXT-2179
This commit is contained in:
Jiachi Liu 2024-01-22 15:37:04 +01:00 committed by GitHub
parent c754d9fb6e
commit 92265ccbe9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 67 additions and 14 deletions

View file

@ -803,7 +803,7 @@ export default async function build(
)
// Always log next version first then start rest jobs
const { envInfo, expFeatureInfo } = await getStartServerInfo(dir)
const { envInfo, expFeatureInfo } = await getStartServerInfo(dir, false)
logStartInfo({
networkUrl: null,
appUrl: null,

View file

@ -1,7 +1,10 @@
import { loadEnvConfig } from '@next/env'
import * as Log from '../../build/output/log'
import { bold, purple } from '../../lib/picocolors'
import { PHASE_DEVELOPMENT_SERVER } from '../../shared/lib/constants'
import {
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_BUILD,
} from '../../shared/lib/constants'
import loadConfig, { getEnabledExperimentalFeatures } from '../config'
export function logStartInfo({
@ -50,21 +53,28 @@ export function logStartInfo({
Log.info('')
}
export async function getStartServerInfo(dir: string): Promise<{
export async function getStartServerInfo(
dir: string,
dev: boolean
): Promise<{
envInfo?: string[]
expFeatureInfo?: string[]
}> {
let expFeatureInfo: string[] = []
await loadConfig(PHASE_DEVELOPMENT_SERVER, dir, {
onLoadUserConfig(userConfig) {
const userNextConfigExperimental = getEnabledExperimentalFeatures(
userConfig.experimental
)
expFeatureInfo = userNextConfigExperimental.sort(
(a, b) => a.length - b.length
)
},
})
await loadConfig(
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
dir,
{
onLoadUserConfig(userConfig) {
const userNextConfigExperimental = getEnabledExperimentalFeatures(
userConfig.experimental
)
expFeatureInfo = userNextConfigExperimental.sort(
(a, b) => a.length - b.length
)
},
}
)
// we need to reset env if we are going to create
// the worker process with the esm loader so that the

View file

@ -251,7 +251,7 @@ export async function startServer(
let envInfo: string[] | undefined
let expFeatureInfo: string[] | undefined
if (isDev) {
const startServerInfo = await getStartServerInfo(dir)
const startServerInfo = await getStartServerInfo(dir, isDev)
envInfo = startServerInfo.envInfo
expFeatureInfo = startServerInfo.expFeatureInfo
}

View file

@ -0,0 +1,43 @@
import { createNextDescribe } from 'e2e-utils'
createNextDescribe(
'next-phase',
{
files: {
'app/layout.js': `export default function Layout({ children }) {
return <html><body>{children}</body></html>
}`,
'app/page.js': `export default function Page() { return <p>{'app'}</p> }`,
'pages/foo.js': `export default function Page() { return <p>{'pages'}</p> }`,
'next.config.js': `
module.exports = (phase, { defaultConfig }) => {
console.log(phase)
return defaultConfig
}
`,
},
},
({ next, isNextDev }) => {
it('should render page with next phase correctly', async () => {
const phases = {
dev: 'phase-development-server',
build: 'phase-production-build',
start: 'phase-production-server',
}
const currentPhase = isNextDev ? phases.dev : phases.build
const nonExistedPhase = isNextDev ? phases.build : phases.dev
expect(next.cliOutput).toContain(currentPhase)
expect(next.cliOutput).not.toContain(nonExistedPhase)
await next.fetch('/')
await next.fetch('/foo')
if (isNextDev) {
expect(next.cliOutput).not.toContain(phases.start)
} else {
expect(next.cliOutput).toContain(phases.start)
}
})
}
)