Unverified Commit 6d7cf2a9 authored by Darsh Patel's avatar Darsh Patel Committed by GitHub

Convert profiling mode from configuration option to CLI switch (#14920)

Removed Option to enable `ReactProductionProfiling` from configuration and added a CLI switch for the same.
Users can now do `next build --profile`  to enable react production profiling. 
Also added a warning to notify users about the performance impact

Fixes: #14688
parent 8cd149c3
...@@ -97,7 +97,11 @@ export type PrerenderManifest = { ...@@ -97,7 +97,11 @@ export type PrerenderManifest = {
preview: __ApiPreviewProps preview: __ApiPreviewProps
} }
export default async function build(dir: string, conf = null): Promise<void> { export default async function build(
dir: string,
conf = null,
reactProductionProfiling = false
): Promise<void> {
if (!(await isWriteable(dir))) { if (!(await isWriteable(dir))) {
throw new Error( throw new Error(
'> Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable' '> Build directory is not writeable. https://err.sh/vercel/next.js/build-dir-not-writeable'
...@@ -312,6 +316,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -312,6 +316,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
tracer, tracer,
buildId, buildId,
reactProductionProfiling,
isServer: false, isServer: false,
config, config,
target, target,
...@@ -321,6 +326,7 @@ export default async function build(dir: string, conf = null): Promise<void> { ...@@ -321,6 +326,7 @@ export default async function build(dir: string, conf = null): Promise<void> {
getBaseWebpackConfig(dir, { getBaseWebpackConfig(dir, {
tracer, tracer,
buildId, buildId,
reactProductionProfiling,
isServer: true, isServer: true,
config, config,
target, target,
......
...@@ -149,6 +149,7 @@ export default async function getBaseWebpackConfig( ...@@ -149,6 +149,7 @@ export default async function getBaseWebpackConfig(
pagesDir, pagesDir,
tracer, tracer,
target = 'server', target = 'server',
reactProductionProfiling = false,
entrypoints, entrypoints,
}: { }: {
buildId: string buildId: string
...@@ -158,6 +159,7 @@ export default async function getBaseWebpackConfig( ...@@ -158,6 +159,7 @@ export default async function getBaseWebpackConfig(
pagesDir: string pagesDir: string
target?: string target?: string
tracer?: any tracer?: any
reactProductionProfiling?: boolean
entrypoints: WebpackEntrypoints entrypoints: WebpackEntrypoints
} }
): Promise<webpack.Configuration> { ): Promise<webpack.Configuration> {
...@@ -273,7 +275,7 @@ export default async function getBaseWebpackConfig( ...@@ -273,7 +275,7 @@ export default async function getBaseWebpackConfig(
} }
function getReactProfilingInProduction() { function getReactProfilingInProduction() {
if (config.reactProductionProfiling) { if (reactProductionProfiling) {
return { return {
'react-dom$': 'react-dom/profiling', 'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling', 'scheduler/tracing': 'scheduler/tracing-profiling',
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { existsSync } from 'fs' import { existsSync } from 'fs'
import arg from 'next/dist/compiled/arg/index.js' import arg from 'next/dist/compiled/arg/index.js'
import { resolve } from 'path' import { resolve } from 'path'
import * as Log from '../build/output/log'
import { cliCommand } from '../bin/next' import { cliCommand } from '../bin/next'
import build from '../build' import build from '../build'
import { printAndExit } from '../server/lib/utils' import { printAndExit } from '../server/lib/utils'
...@@ -12,6 +12,7 @@ const nextBuild: cliCommand = (argv) => { ...@@ -12,6 +12,7 @@ const nextBuild: cliCommand = (argv) => {
{ {
// Types // Types
'--help': Boolean, '--help': Boolean,
'--profile': Boolean,
// Aliases // Aliases
'-h': '--help', '-h': '--help',
}, },
...@@ -29,11 +30,15 @@ const nextBuild: cliCommand = (argv) => { ...@@ -29,11 +30,15 @@ const nextBuild: cliCommand = (argv) => {
<dir> represents the directory of the Next.js application. <dir> represents the directory of the Next.js application.
If no directory is provided, the current directory will be used. If no directory is provided, the current directory will be used.
--profile can be used to enable React Production Profiling
`, `,
0 0
) )
} }
if (args['--profile']) {
Log.warn('Profiling is enabled. Note: This may affect performance')
}
const dir = resolve(args._[0] || '.') const dir = resolve(args._[0] || '.')
// Check if the provided directory exists // Check if the provided directory exists
...@@ -41,7 +46,7 @@ const nextBuild: cliCommand = (argv) => { ...@@ -41,7 +46,7 @@ const nextBuild: cliCommand = (argv) => {
printAndExit(`> No such directory exists as the project root: ${dir}`) printAndExit(`> No such directory exists as the project root: ${dir}`)
} }
build(dir) build(dir, null, args['--profile'])
.then(() => process.exit(0)) .then(() => process.exit(0))
.catch((err) => { .catch((err) => {
console.error('') console.error('')
......
...@@ -49,7 +49,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -49,7 +49,6 @@ const defaultConfig: { [key: string]: any } = {
profiling: false, profiling: false,
sprFlushToDisk: true, sprFlushToDisk: true,
reactMode: 'legacy', reactMode: 'legacy',
reactProductionProfiling: false,
workerThreads: false, workerThreads: false,
pageEnv: false, pageEnv: false,
productionBrowserSourceMaps: false, productionBrowserSourceMaps: false,
......
...@@ -40,7 +40,7 @@ describe('React Profiling Mode', () => { ...@@ -40,7 +40,7 @@ describe('React Profiling Mode', () => {
} }
` `
) )
await nextBuild(appDir) await nextBuild(appDir, ['--profile'])
appPort = await findPort() appPort = await findPort()
app = await nextStart(appDir, appPort) app = await nextStart(appDir, appPort)
}) })
......
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