diff --git a/src/commands/base-command.ts b/src/commands/base-command.ts index 7317ead9b8d..99e1eb360e5 100644 --- a/src/commands/base-command.ts +++ b/src/commands/base-command.ts @@ -172,6 +172,7 @@ export type BaseOptionValues = { filter?: string httpProxy?: string silent?: string + verbose?: boolean } /** Base command class that provides tracking and config initialization */ @@ -796,4 +797,4 @@ export default class BaseCommand extends Command { } export const getBaseOptionValues = (options: OptionValues): BaseOptionValues => - pick(options, ['auth', 'cwd', 'debug', 'filter', 'httpProxy', 'silent']) + pick(options, ['auth', 'cwd', 'debug', 'filter', 'httpProxy', 'silent', 'verbose']) diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 258baa8f17f..d3a13193fc4 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -690,7 +690,15 @@ const handleBuild = async ({ const { configMutations, exitCode, newConfig, logs } = await runBuild(resolvedOptions) // Without this, the deploy command fails silently if (options.json && exitCode !== 0) { - const message = logs?.stderr.length ? `: ${logs.stderr.join('')}` : '' + let message = '' + + if (options.verbose && logs?.stdout.length) { + message += `\n\n${logs.stdout.join('')}\n\n` + } + + if (logs?.stderr.length) { + message += logs.stderr.join('') + } logAndThrowError(`Error while running build${message}`) } diff --git a/src/commands/deploy/index.ts b/src/commands/deploy/index.ts index 886de83367c..4b7423a03f8 100644 --- a/src/commands/deploy/index.ts +++ b/src/commands/deploy/index.ts @@ -105,6 +105,10 @@ For more information about Netlify deploys, see ${terminalLink(docsUrl, docsUrl, ` }) .action(async (options: DeployOptionValues, command: BaseCommand) => { + if (command.parent?.opts().verbose) { + options.verbose = true + } + if (options.build && command.getOptionValueSource('build') === 'cli') { warn(`${chalk.cyanBright('--build')} is now the default and can safely be omitted.`) } diff --git a/tests/integration/commands/deploy/deploy.test.ts b/tests/integration/commands/deploy/deploy.test.ts index b398c1e9587..0035de49922 100644 --- a/tests/integration/commands/deploy/deploy.test.ts +++ b/tests/integration/commands/deploy/deploy.test.ts @@ -505,6 +505,34 @@ describe.skipIf(process.env.NETLIFY_TEST_DISABLE_LIVE === 'true').concurrent('co }) }) + test('should include stdout and stderr when build fails with --json --verbose options', async (t) => { + await withSiteBuilder(t, async (builder) => { + builder + .withContentFile({ + path: 'public/index.html', + content: '