From 3dec50001e34894379e0b14ef9bad9379c44d7b7 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Thu, 20 Aug 2020 10:43:38 -0500 Subject: [PATCH] Add debug flag for extra build output (#16399) This adds a `-d` or `--debug` flag which enables outputting additional build output information like the rewrites, redirects, and headers Fixes #15281 --- packages/next/build/index.ts | 8 ++++++-- packages/next/cli/next-build.ts | 4 +++- test/integration/custom-routes/test/index.test.js | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 40b44eddad..93ca9cf52f 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -102,7 +102,8 @@ export type PrerenderManifest = { export default async function build( dir: string, conf = null, - reactProductionProfiling = false + reactProductionProfiling = false, + debugOutput = false ): Promise { if (!(await isWriteable(dir))) { throw new Error( @@ -1024,7 +1025,10 @@ export default async function build( isModern: config.experimental.modern, } ) - printCustomRoutes({ redirects, rewrites, headers }) + + if (debugOutput) { + printCustomRoutes({ redirects, rewrites, headers }) + } if (tracer) { const parsedResults = await tracer.profiler.stopProfiling() diff --git a/packages/next/cli/next-build.ts b/packages/next/cli/next-build.ts index ff8d0bfdbd..1453ac7547 100755 --- a/packages/next/cli/next-build.ts +++ b/packages/next/cli/next-build.ts @@ -12,8 +12,10 @@ const nextBuild: cliCommand = (argv) => { // Types '--help': Boolean, '--profile': Boolean, + '--debug': Boolean, // Aliases '-h': '--help', + '-d': '--debug', } let args: arg.Result @@ -53,7 +55,7 @@ const nextBuild: cliCommand = (argv) => { printAndExit(`> No such directory exists as the project root: ${dir}`) } - build(dir, null, args['--profile']) + build(dir, null, args['--profile'], args['--debug']) .then(() => process.exit(0)) .catch((err) => { console.error('') diff --git a/test/integration/custom-routes/test/index.test.js b/test/integration/custom-routes/test/index.test.js index d3acb92fa4..af3ca95058 100644 --- a/test/integration/custom-routes/test/index.test.js +++ b/test/integration/custom-routes/test/index.test.js @@ -988,7 +988,7 @@ const runTests = (isDev = false) => { }) }) - it('should have redirects/rewrites in build output', async () => { + it('should have redirects/rewrites in build output with debug flag', async () => { const manifest = await fs.readJSON( join(appDir, '.next/routes-manifest.json') ) @@ -1073,7 +1073,7 @@ describe('Custom routes', () => { describe('server mode', () => { beforeAll(async () => { - const { stdout: buildStdout } = await nextBuild(appDir, [], { + const { stdout: buildStdout } = await nextBuild(appDir, ['-d'], { stdout: true, }) stdout = buildStdout @@ -1093,7 +1093,7 @@ describe('Custom routes', () => { nextConfigContent.replace(/\/\/ target/, 'target'), 'utf8' ) - const { stdout: buildStdout } = await nextBuild(appDir, [], { + const { stdout: buildStdout } = await nextBuild(appDir, ['-d'], { stdout: true, }) stdout = buildStdout