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:
parent
c754d9fb6e
commit
92265ccbe9
4 changed files with 67 additions and 14 deletions
|
@ -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,
|
||||
|
|
|
@ -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,12 +53,18 @@ 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, {
|
||||
await loadConfig(
|
||||
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
|
||||
dir,
|
||||
{
|
||||
onLoadUserConfig(userConfig) {
|
||||
const userNextConfigExperimental = getEnabledExperimentalFeatures(
|
||||
userConfig.experimental
|
||||
|
@ -64,7 +73,8 @@ export async function getStartServerInfo(dir: string): Promise<{
|
|||
(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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
43
test/e2e/next-phase/index.test.ts
Normal file
43
test/e2e/next-phase/index.test.ts
Normal 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue