From 5318f00298d35dd26a4227d3b3166d6ba8d26e98 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 1 May 2019 10:24:21 +0200 Subject: [PATCH] fix(schematics): print additional error info with `--verbose` flag in affected command --- docs/api-npmscripts/affected.md | 4 ++++ packages/workspace/src/command-line/affected.ts | 14 ++++++++++---- packages/workspace/src/command-line/nx-commands.ts | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/api-npmscripts/affected.md b/docs/api-npmscripts/affected.md index 4621df46ca9b9..1ccd8eafcb6fc 100644 --- a/docs/api-npmscripts/affected.md +++ b/docs/api-npmscripts/affected.md @@ -64,6 +64,10 @@ Uncommitted changes Untracked changes +### verbose + +Print additional error stack trace on failure + ### version Show version number diff --git a/packages/workspace/src/command-line/affected.ts b/packages/workspace/src/command-line/affected.ts index f01c2771de8e9..fbc3c41228ec1 100644 --- a/packages/workspace/src/command-line/affected.ts +++ b/packages/workspace/src/command-line/affected.ts @@ -39,6 +39,7 @@ export interface AffectedOptions extends GlobalNxArgs { onlyFailed?: boolean; 'only-failed'?: boolean; 'max-parallel'?: boolean; + verbose?: boolean; } // Commands that can do `ng [command]` @@ -110,7 +111,7 @@ export function affected(parsedArgs: YargsAffectedOptions): void { break; } } catch (e) { - printError(e); + printError(e, parsedArgs.verbose); process.exit(1); } } @@ -132,8 +133,12 @@ function getProjects( ); } -function printError(e: any) { - console.error(e.message); +function printError(e: any, verbose?: boolean) { + if (verbose && e.stack) { + console.error(e.stack); + } else { + console.error(e.message); + } } async function runCommand( @@ -333,7 +338,8 @@ const dummyOptions: AffectedOptions = { base: 'base', head: 'head', exclude: ['exclude'], - files: [''] + files: [''], + verbose: false }; const nxSpecificFlags = Object.keys(dummyOptions); diff --git a/packages/workspace/src/command-line/nx-commands.ts b/packages/workspace/src/command-line/nx-commands.ts index 557799ae0d3e6..7baf0ed27cd98 100644 --- a/packages/workspace/src/command-line/nx-commands.ts +++ b/packages/workspace/src/command-line/nx-commands.ts @@ -201,6 +201,9 @@ function withAffectedOptions(yargs: yargs.Argv): yargs.Argv { type: 'boolean', default: false }) + .option('verbose', { + describe: 'Print additional error stack trace on failure' + }) .conflicts({ files: ['uncommitted', 'untracked', 'base', 'head', 'all'], untracked: ['uncommitted', 'files', 'base', 'head', 'all'],