Commit ad4f5ce5 authored by Jude Gao's avatar Jude Gao

improve ux

parent 961fb0ae
...@@ -187,8 +187,8 @@ program ...@@ -187,8 +187,8 @@ program
'Comma-separated glob patterns or explicit paths for selective builds. Examples: "app/*", "app/page.tsx", "app/**/page.tsx"' 'Comma-separated glob patterns or explicit paths for selective builds. Examples: "app/*", "app/page.tsx", "app/**/page.tsx"'
) )
.option( .option(
'--profiler', '--insights',
'Creates a profiler build with source maps enabled, no minification, and React profiling.' 'Creates an insights build with source maps enabled, no minification, and React profiling.'
) )
.action((directory: string, options: NextBuildOptions) => { .action((directory: string, options: NextBuildOptions) => {
if (options.experimentalNextConfigStripTypes) { if (options.experimentalNextConfigStripTypes) {
......
...@@ -96,5 +96,5 @@ export const NextBuildContext: Partial<{ ...@@ -96,5 +96,5 @@ export const NextBuildContext: Partial<{
isCompileMode?: boolean isCompileMode?: boolean
debugPrerender: boolean debugPrerender: boolean
analyze: boolean analyze: boolean
profiler: boolean insights: boolean
}> = {} }> = {}
...@@ -345,7 +345,7 @@ export function getDefineEnv({ ...@@ -345,7 +345,7 @@ export function getDefineEnv({
config.experimental.reactDebugChannel ?? false, config.experimental.reactDebugChannel ?? false,
'process.env.__NEXT_TRANSITION_INDICATOR': 'process.env.__NEXT_TRANSITION_INDICATOR':
config.experimental.transitionIndicator ?? false, config.experimental.transitionIndicator ?? false,
'process.env.__NEXT_PROFILER_BUILD': config.profiler ?? false, 'process.env.__NEXT_INSIGHTS_BUILD': config.insights ?? false,
} }
const userDefines = config.compiler?.define ?? {} const userDefines = config.compiler?.define ?? {}
......
...@@ -891,7 +891,7 @@ export default async function build( ...@@ -891,7 +891,7 @@ export default async function build(
traceUploadUrl: string | undefined, traceUploadUrl: string | undefined,
debugBuildAppPaths?: string[], debugBuildAppPaths?: string[],
debugBuildPagePaths?: string[], debugBuildPagePaths?: string[],
profiler = false insights = false
): Promise<void> { ): Promise<void> {
const isCompileMode = experimentalBuildMode === 'compile' const isCompileMode = experimentalBuildMode === 'compile'
const isGenerateMode = experimentalBuildMode === 'generate' const isGenerateMode = experimentalBuildMode === 'generate'
...@@ -914,7 +914,7 @@ export default async function build( ...@@ -914,7 +914,7 @@ export default async function build(
NextBuildContext.reactProductionProfiling = reactProductionProfiling NextBuildContext.reactProductionProfiling = reactProductionProfiling
NextBuildContext.noMangling = noMangling NextBuildContext.noMangling = noMangling
NextBuildContext.debugPrerender = debugPrerender NextBuildContext.debugPrerender = debugPrerender
NextBuildContext.profiler = profiler NextBuildContext.insights = insights
await nextBuildSpan.traceAsyncFn(async () => { await nextBuildSpan.traceAsyncFn(async () => {
// attempt to load global env values so they are available in next.config.js // attempt to load global env values so they are available in next.config.js
...@@ -934,7 +934,7 @@ export default async function build( ...@@ -934,7 +934,7 @@ export default async function build(
silent: false, silent: false,
reactProductionProfiling, reactProductionProfiling,
debugPrerender, debugPrerender,
profiler, insights,
}), }),
turborepoAccessTraceResult turborepoAccessTraceResult
) )
......
...@@ -230,7 +230,7 @@ export async function workerMain(workerData: { ...@@ -230,7 +230,7 @@ export async function workerMain(workerData: {
{ {
debugPrerender: NextBuildContext.debugPrerender, debugPrerender: NextBuildContext.debugPrerender,
reactProductionProfiling: NextBuildContext.reactProductionProfiling, reactProductionProfiling: NextBuildContext.reactProductionProfiling,
profiler: NextBuildContext.profiler, insights: NextBuildContext.insights,
} }
)) ))
// Matches handling in build/index.ts // Matches handling in build/index.ts
......
...@@ -390,7 +390,7 @@ export async function workerMain(workerData: { ...@@ -390,7 +390,7 @@ export async function workerMain(workerData: {
{ {
debugPrerender: NextBuildContext.debugPrerender, debugPrerender: NextBuildContext.debugPrerender,
reactProductionProfiling: NextBuildContext.reactProductionProfiling, reactProductionProfiling: NextBuildContext.reactProductionProfiling,
profiler: NextBuildContext.profiler, insights: NextBuildContext.insights,
} }
)) ))
await installBindings(config.experimental?.useWasmBinary) await installBindings(config.experimental?.useWasmBinary)
......
...@@ -394,8 +394,8 @@ export default async function getBaseWebpackConfig( ...@@ -394,8 +394,8 @@ export default async function getBaseWebpackConfig(
const hasAppDir = !!appDir const hasAppDir = !!appDir
const disableOptimizedLoading = true const disableOptimizedLoading = true
// Combine reactProductionProfiling with profiler flag for React profiling builds // Combine reactProductionProfiling with insights flag for React profiling builds
const enableReactProfiling = reactProductionProfiling || config.profiler const enableReactProfiling = reactProductionProfiling || config.insights
const bundledReactChannel = needsExperimentalReact(config) const bundledReactChannel = needsExperimentalReact(config)
? '-experimental' ? '-experimental'
: '' : ''
......
...@@ -21,7 +21,7 @@ export type NextBuildOptions = { ...@@ -21,7 +21,7 @@ export type NextBuildOptions = {
debug?: boolean debug?: boolean
debugPrerender?: boolean debugPrerender?: boolean
profile?: boolean profile?: boolean
profiler?: boolean insights?: boolean
mangling: boolean mangling: boolean
turbo?: boolean turbo?: boolean
turbopack?: boolean turbopack?: boolean
...@@ -45,7 +45,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => { ...@@ -45,7 +45,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
debugPrerender, debugPrerender,
experimentalDebugMemoryUsage, experimentalDebugMemoryUsage,
profile, profile,
profiler, insights,
mangling, mangling,
experimentalAppOnly, experimentalAppOnly,
experimentalBuildMode, experimentalBuildMode,
...@@ -86,9 +86,9 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => { ...@@ -86,9 +86,9 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
) )
} }
if (profiler) { if (insights) {
warn( warn(
`Profiler build is enabled. ${italic( `Insights build is enabled. ${italic(
'Note: Source maps are enabled and minification is disabled. This build is not suitable for production.' 'Note: Source maps are enabled and minification is disabled. This build is not suitable for production.'
)}` )}`
) )
...@@ -139,7 +139,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => { ...@@ -139,7 +139,7 @@ const nextBuild = async (options: NextBuildOptions, directory?: string) => {
traceUploadUrl, traceUploadUrl,
resolvedAppPaths, resolvedAppPaths,
resolvedPagePaths, resolvedPagePaths,
profiler insights
) )
.catch((err) => { .catch((err) => {
if (experimentalDebugMemoryUsage) { if (experimentalDebugMemoryUsage) {
......
...@@ -15,11 +15,11 @@ window.next = { ...@@ -15,11 +15,11 @@ window.next = {
appDir: true, appDir: true,
} }
// Log profiler build info at startup // Log insights build info at startup
if (process.env.__NEXT_PROFILER_BUILD) { if (process.env.__NEXT_INSIGHTS_BUILD) {
console.log('') console.log('')
console.log( console.log(
'%c[Next.js Profiler Build]', '%c[Next.js Insights Build]',
'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;', 'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;',
'\n• Source maps: enabled', '\n• Source maps: enabled',
'\n• Minification: disabled', '\n• Minification: disabled',
......
...@@ -50,11 +50,11 @@ import { isNextRouterError } from './components/is-next-router-error' ...@@ -50,11 +50,11 @@ import { isNextRouterError } from './components/is-next-router-error'
/// <reference types="react-dom/experimental" /> /// <reference types="react-dom/experimental" />
// Log profiler build info at startup // Log insights build info at startup
if (process.env.__NEXT_PROFILER_BUILD) { if (process.env.__NEXT_INSIGHTS_BUILD) {
console.log('') console.log('')
console.log( console.log(
'%c[Next.js Profiler Build]', '%c[Next.js Insights Build]',
'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;', 'background: #0070f3; color: white; padding: 2px 6px; border-radius: 3px;',
'\n• Source maps: enabled', '\n• Source maps: enabled',
'\n• Minification: disabled', '\n• Minification: disabled',
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
// Initialize waterfall detector FIRST (before any other code runs) // Initialize waterfall detector FIRST (before any other code runs)
// This must happen before the instrumentation client is loaded to patch fetch early // This must happen before the instrumentation client is loaded to patch fetch early
let disableWaterfallDetector: (() => void) | null = null let disableWaterfallDetector: (() => void) | null = null
if (process.env.__NEXT_PROFILER_BUILD) { if (process.env.__NEXT_INSIGHTS_BUILD) {
const waterfallDetector = const waterfallDetector =
require('../client/waterfall-detector') as typeof import('../client/waterfall-detector') require('../client/waterfall-detector') as typeof import('../client/waterfall-detector')
waterfallDetector.initWaterfallDetector() waterfallDetector.initWaterfallDetector()
......
...@@ -1141,11 +1141,11 @@ export interface NextConfig { ...@@ -1141,11 +1141,11 @@ export interface NextConfig {
reactProductionProfiling?: boolean reactProductionProfiling?: boolean
/** /**
* Enable profiler build with source maps and no minification. * Enable insights build with source maps and no minification.
* This is set automatically when using `next build --profiler`. * This is set automatically when using `next build --insights`.
* @internal * @internal
*/ */
profiler?: boolean insights?: boolean
/** /**
* The Next.js runtime is Strict Mode-compliant. * The Next.js runtime is Strict Mode-compliant.
...@@ -1429,7 +1429,7 @@ export const defaultConfig = Object.freeze({ ...@@ -1429,7 +1429,7 @@ export const defaultConfig = Object.freeze({
productionBrowserSourceMaps: false, productionBrowserSourceMaps: false,
excludeDefaultMomentLocales: true, excludeDefaultMomentLocales: true,
reactProductionProfiling: false, reactProductionProfiling: false,
profiler: false, insights: false,
reactStrictMode: null, reactStrictMode: null,
reactMaxHeadersLength: 6000, reactMaxHeadersLength: 6000,
httpAgentOptions: { httpAgentOptions: {
...@@ -1632,7 +1632,7 @@ export interface NextConfigRuntime { ...@@ -1632,7 +1632,7 @@ export interface NextConfigRuntime {
skipProxyUrlNormalize: NextConfigComplete['skipProxyUrlNormalize'] skipProxyUrlNormalize: NextConfigComplete['skipProxyUrlNormalize']
pageExtensions: NextConfigComplete['pageExtensions'] pageExtensions: NextConfigComplete['pageExtensions']
useFileSystemPublicRoutes: NextConfigComplete['useFileSystemPublicRoutes'] useFileSystemPublicRoutes: NextConfigComplete['useFileSystemPublicRoutes']
profiler?: NextConfigComplete['profiler'] insights?: NextConfigComplete['insights']
experimental: Pick< experimental: Pick<
NextConfigComplete['experimental'], NextConfigComplete['experimental'],
...@@ -1762,7 +1762,7 @@ export function getNextConfigRuntime( ...@@ -1762,7 +1762,7 @@ export function getNextConfigRuntime(
skipProxyUrlNormalize: config.skipProxyUrlNormalize, skipProxyUrlNormalize: config.skipProxyUrlNormalize,
pageExtensions: config.pageExtensions, pageExtensions: config.pageExtensions,
useFileSystemPublicRoutes: config.useFileSystemPublicRoutes, useFileSystemPublicRoutes: config.useFileSystemPublicRoutes,
profiler: config.profiler, insights: config.insights,
experimental, experimental,
} }
......
...@@ -1415,7 +1415,7 @@ function getCacheKey( ...@@ -1415,7 +1415,7 @@ function getCacheKey(
customConfig?: object | null, customConfig?: object | null,
reactProductionProfiling?: boolean, reactProductionProfiling?: boolean,
debugPrerender?: boolean, debugPrerender?: boolean,
profiler?: boolean, insights?: boolean,
pid?: number pid?: number
): string { ): string {
// The next.config.js is unique per project, so we can use the dir as the major key // The next.config.js is unique per project, so we can use the dir as the major key
...@@ -1426,7 +1426,7 @@ function getCacheKey( ...@@ -1426,7 +1426,7 @@ function getCacheKey(
hasCustomConfig: Boolean(customConfig), hasCustomConfig: Boolean(customConfig),
reactProductionProfiling: Boolean(reactProductionProfiling), reactProductionProfiling: Boolean(reactProductionProfiling),
debugPrerender: Boolean(debugPrerender), debugPrerender: Boolean(debugPrerender),
profiler: Boolean(profiler), insights: Boolean(insights),
pid: pid || 0, pid: pid || 0,
}) })
...@@ -1442,7 +1442,7 @@ type LoadConfigOptions = { ...@@ -1442,7 +1442,7 @@ type LoadConfigOptions = {
) => void ) => void
reactProductionProfiling?: boolean reactProductionProfiling?: boolean
debugPrerender?: boolean debugPrerender?: boolean
profiler?: boolean insights?: boolean
} }
export default async function loadConfig( export default async function loadConfig(
...@@ -1471,7 +1471,7 @@ export default async function loadConfig( ...@@ -1471,7 +1471,7 @@ export default async function loadConfig(
reportExperimentalFeatures, reportExperimentalFeatures,
reactProductionProfiling, reactProductionProfiling,
debugPrerender, debugPrerender,
profiler, insights,
}: LoadConfigOptions = {} }: LoadConfigOptions = {}
): Promise<NextConfigComplete> { ): Promise<NextConfigComplete> {
// Generate cache key based on parameters that affect config output // Generate cache key based on parameters that affect config output
...@@ -1482,7 +1482,7 @@ export default async function loadConfig( ...@@ -1482,7 +1482,7 @@ export default async function loadConfig(
customConfig, customConfig,
reactProductionProfiling, reactProductionProfiling,
debugPrerender, debugPrerender,
profiler, insights,
process.pid process.pid
) )
...@@ -1723,7 +1723,7 @@ export default async function loadConfig( ...@@ -1723,7 +1723,7 @@ export default async function loadConfig(
isDefaultConfig: false, isDefaultConfig: false,
configuredExperimentalFeatures, configuredExperimentalFeatures,
debugPrerender, debugPrerender,
profiler, insights,
phase, phase,
}) })
...@@ -1782,7 +1782,7 @@ export default async function loadConfig( ...@@ -1782,7 +1782,7 @@ export default async function loadConfig(
isDefaultConfig: true, isDefaultConfig: true,
configuredExperimentalFeatures, configuredExperimentalFeatures,
debugPrerender, debugPrerender,
profiler, insights,
phase, phase,
}) })
...@@ -1825,14 +1825,14 @@ function enforceExperimentalFeatures( ...@@ -1825,14 +1825,14 @@ function enforceExperimentalFeatures(
isDefaultConfig: boolean isDefaultConfig: boolean
configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined configuredExperimentalFeatures: ConfiguredExperimentalFeature[] | undefined
debugPrerender: boolean | undefined debugPrerender: boolean | undefined
profiler: boolean | undefined insights: boolean | undefined
phase: PHASE_TYPE phase: PHASE_TYPE
} }
) { ) {
const { const {
configuredExperimentalFeatures, configuredExperimentalFeatures,
debugPrerender, debugPrerender,
profiler, insights,
isDefaultConfig, isDefaultConfig,
phase, phase,
} = options } = options
...@@ -1868,9 +1868,9 @@ function enforceExperimentalFeatures( ...@@ -1868,9 +1868,9 @@ function enforceExperimentalFeatures(
) )
} }
// Profiler build: enable source maps (client + server) and disable minification // Insights build: enable source maps (client + server) and disable minification
if ( if (
profiler && insights &&
(phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT) (phase === PHASE_PRODUCTION_BUILD || phase === PHASE_EXPORT)
) { ) {
// Enable client-side source maps // Enable client-side source maps
...@@ -1901,8 +1901,8 @@ function enforceExperimentalFeatures( ...@@ -1901,8 +1901,8 @@ function enforceExperimentalFeatures(
configuredExperimentalFeatures configuredExperimentalFeatures
) )
// Mark this as a profiler build in config for runtime detection // Mark this as a insights build in config for runtime detection
config.profiler = true config.insights = true
} }
// TODO: Remove this once we've made Cache Components the default. // TODO: Remove this once we've made Cache Components the default.
......
...@@ -16,6 +16,7 @@ export function logStartInfo({ ...@@ -16,6 +16,7 @@ export function logStartInfo({
experimentalFeatures, experimentalFeatures,
logBundler, logBundler,
cacheComponents, cacheComponents,
insights,
}: { }: {
networkUrl: string | null networkUrl: string | null
appUrl: string | null appUrl: string | null
...@@ -23,6 +24,7 @@ export function logStartInfo({ ...@@ -23,6 +24,7 @@ export function logStartInfo({
experimentalFeatures?: ConfiguredExperimentalFeature[] experimentalFeatures?: ConfiguredExperimentalFeature[]
logBundler: boolean logBundler: boolean
cacheComponents?: boolean cacheComponents?: boolean
insights?: boolean
}) { }) {
let versionSuffix = '' let versionSuffix = ''
const parts = [] const parts = []
...@@ -41,6 +43,10 @@ export function logStartInfo({ ...@@ -41,6 +43,10 @@ export function logStartInfo({
parts.push('Cache Components') parts.push('Cache Components')
} }
if (insights) {
parts.push('Insights')
}
if (parts.length > 0) { if (parts.length > 0) {
versionSuffix = ` (${parts.join(', ')})` versionSuffix = ` (${parts.join(', ')})`
} }
...@@ -114,9 +120,11 @@ export async function getStartServerInfo({ ...@@ -114,9 +120,11 @@ export async function getStartServerInfo({
envInfo?: string[] envInfo?: string[]
experimentalFeatures?: ConfiguredExperimentalFeature[] experimentalFeatures?: ConfiguredExperimentalFeature[]
cacheComponents?: boolean cacheComponents?: boolean
insights?: boolean
}> { }> {
let experimentalFeatures: ConfiguredExperimentalFeature[] = [] let experimentalFeatures: ConfiguredExperimentalFeature[] = []
let cacheComponents = false let cacheComponents = false
let insights = false
const config = await loadConfig( const config = await loadConfig(
dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD, dev ? PHASE_DEVELOPMENT_SERVER : PHASE_PRODUCTION_BUILD,
dir, dir,
...@@ -132,6 +140,7 @@ export async function getStartServerInfo({ ...@@ -132,6 +140,7 @@ export async function getStartServerInfo({
) )
cacheComponents = !!config.cacheComponents cacheComponents = !!config.cacheComponents
insights = !!config.insights
// we need to reset env if we are going to create // we need to reset env if we are going to create
// the worker process with the esm loader so that the // the worker process with the esm loader so that the
...@@ -146,5 +155,6 @@ export async function getStartServerInfo({ ...@@ -146,5 +155,6 @@ export async function getStartServerInfo({
envInfo, envInfo,
experimentalFeatures, experimentalFeatures,
cacheComponents, cacheComponents,
insights,
} }
} }
...@@ -355,15 +355,22 @@ export async function startServer( ...@@ -355,15 +355,22 @@ export async function startServer(
} }
// Only load env and config in dev to for logging purposes // Only load env and config in dev to for logging purposes
// For production, we still need to check for insights mode
let envInfo: string[] | undefined let envInfo: string[] | undefined
let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined let experimentalFeatures: ConfiguredExperimentalFeature[] | undefined
let cacheComponents: boolean | undefined let cacheComponents: boolean | undefined
let insights: boolean | undefined
try { try {
if (isDev) { if (isDev) {
const startServerInfo = await getStartServerInfo({ dir, dev: isDev }) const startServerInfo = await getStartServerInfo({ dir, dev: isDev })
envInfo = startServerInfo.envInfo envInfo = startServerInfo.envInfo
cacheComponents = startServerInfo.cacheComponents cacheComponents = startServerInfo.cacheComponents
experimentalFeatures = startServerInfo.experimentalFeatures experimentalFeatures = startServerInfo.experimentalFeatures
insights = startServerInfo.insights
} else {
// For production, check if this is an insights build
const startServerInfo = await getStartServerInfo({ dir, dev: false })
insights = startServerInfo.insights
} }
logStartInfo({ logStartInfo({
networkUrl, networkUrl,
...@@ -371,6 +378,7 @@ export async function startServer( ...@@ -371,6 +378,7 @@ export async function startServer(
envInfo, envInfo,
experimentalFeatures, experimentalFeatures,
cacheComponents, cacheComponents,
insights,
logBundler: isDev, logBundler: isDev,
}) })
......
This diff is collapsed.
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