Skip to content

Commit

Permalink
fix(cli): use stderr for logs when using --json option (#4044)
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Jan 11, 2021
1 parent fa7003e commit 452a101
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cli/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import type { Answers, PromptObject } from 'prompts';
import c from './colors';
import { isInteractive } from './util/term';

const options = { colors: c, stream: process.stdout };
const options = {
colors: c,
stream: process.argv.includes('--json') ? process.stderr : process.stdout,
};

export const output = isInteractive()
? new TTYOutputStrategy(options)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function configCommand(
const evaluatedConfig = await deepAwait(config);

if (json) {
output.write(JSON.stringify(evaluatedConfig));
process.stdout.write(`${JSON.stringify(evaluatedConfig)}\n`);
} else {
output.write(
`${util.inspect(evaluatedConfig, { depth: Infinity, colors: true })}\n`,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/tasks/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export async function runCommand(

// TODO: make hidden commander option (https://github.com/tj/commander.js/issues/1106)
if (process.argv.includes('--json')) {
output.write(JSON.stringify(outputTargets));
process.stdout.write(`${JSON.stringify(outputTargets)}\n`);
} else {
const rows = outputTargets.map(t => [t.name, t.api, t.id]);

Expand Down

0 comments on commit 452a101

Please sign in to comment.