Skip to content

Commit 4272578

Browse files
feat: add --verbose flag to deploy command (#7656)
1 parent e232d71 commit 4272578

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

src/commands/base-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export type BaseOptionValues = {
172172
filter?: string
173173
httpProxy?: string
174174
silent?: string
175+
verbose?: boolean
175176
}
176177

177178
/** Base command class that provides tracking and config initialization */
@@ -796,4 +797,4 @@ export default class BaseCommand extends Command {
796797
}
797798

798799
export const getBaseOptionValues = (options: OptionValues): BaseOptionValues =>
799-
pick(options, ['auth', 'cwd', 'debug', 'filter', 'httpProxy', 'silent'])
800+
pick(options, ['auth', 'cwd', 'debug', 'filter', 'httpProxy', 'silent', 'verbose'])

src/commands/deploy/deploy.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,15 @@ const handleBuild = async ({
690690
const { configMutations, exitCode, newConfig, logs } = await runBuild(resolvedOptions)
691691
// Without this, the deploy command fails silently
692692
if (options.json && exitCode !== 0) {
693-
const message = logs?.stderr.length ? `: ${logs.stderr.join('')}` : ''
693+
let message = ''
694+
695+
if (options.verbose && logs?.stdout.length) {
696+
message += `\n\n${logs.stdout.join('')}\n\n`
697+
}
698+
699+
if (logs?.stderr.length) {
700+
message += logs.stderr.join('')
701+
}
694702

695703
logAndThrowError(`Error while running build${message}`)
696704
}

src/commands/deploy/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ For more information about Netlify deploys, see ${terminalLink(docsUrl, docsUrl,
105105
`
106106
})
107107
.action(async (options: DeployOptionValues, command: BaseCommand) => {
108+
if (command.parent?.opts().verbose) {
109+
options.verbose = true
110+
}
111+
108112
if (options.build && command.getOptionValueSource('build') === 'cli') {
109113
warn(`${chalk.cyanBright('--build')} is now the default and can safely be omitted.`)
110114
}

tests/integration/commands/deploy/deploy.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,34 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co
505505
})
506506
})
507507

508+
test('should include stdout and stderr when build fails with --json --verbose options', async (t) => {
509+
await withSiteBuilder(t, async (builder) => {
510+
builder
511+
.withContentFile({
512+
path: 'public/index.html',
513+
content: '<h1>Test content</h1>',
514+
})
515+
.withNetlifyToml({
516+
config: {
517+
build: {
518+
publish: 'public',
519+
command:
520+
"node -e \"process.stdout.write('Build output'); process.stderr.write('Build error'); process.exit(1)\"",
521+
},
522+
},
523+
})
524+
525+
await builder.build()
526+
527+
await expect(
528+
callCli(['deploy', '--json', '--verbose'], {
529+
cwd: builder.directory,
530+
env: { NETLIFY_SITE_ID: context.siteId },
531+
}),
532+
).rejects.toThrow('Build output')
533+
})
534+
})
535+
508536
test('should deploy hidden public folder but ignore hidden/__MACOSX files', { retry: 3 }, async (t) => {
509537
await withSiteBuilder(t, async (builder) => {
510538
builder

0 commit comments

Comments
 (0)