Skip to content

Commit

Permalink
Add debug flag for extra build output (#16399)
Browse files Browse the repository at this point in the history
This adds a `-d` or `--debug` flag which enables outputting additional build output information like the rewrites, redirects, and headers

Fixes #15281
  • Loading branch information
ijjk authored Aug 20, 2020
1 parent c210154 commit 3dec500
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export type PrerenderManifest = {
export default async function build(
dir: string,
conf = null,
reactProductionProfiling = false
reactProductionProfiling = false,
debugOutput = false
): Promise<void> {
if (!(await isWriteable(dir))) {
throw new Error(
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion packages/next/cli/next-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const nextBuild: cliCommand = (argv) => {
// Types
'--help': Boolean,
'--profile': Boolean,
'--debug': Boolean,
// Aliases
'-h': '--help',
'-d': '--debug',
}

let args: arg.Result<arg.Spec>
Expand Down Expand Up @@ -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('')
Expand Down
6 changes: 3 additions & 3 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3dec500

Please sign in to comment.