Skip to content

Commit

Permalink
feat(cli): Disable only header/footer in nested commands, not all out…
Browse files Browse the repository at this point in the history
…put (yarnpkg#4811)

**Summary**

Fixes yarnpkg#4615. Disabling all Yarn output in nested commands with `YARN_SILENT` is a bit much, we usually want to see the output. This pull request introduces a new environment variable `YARN_WRAP_OUTPUT` that can be set to `0` to disable the header and footer Yarn normally displays.

Disabling the header/footer might also be useful in other situations, like other tools calling Yarn, so the `YARN_WRAP_OUTPUT` variable has general use.

**Test plan**

Existing integration tests.
  • Loading branch information
sth authored and terra-incognita committed Nov 9, 2017
1 parent ce2fd05 commit e686e9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
}

if (cmds.length) {
// propagate YARN_SILENT env variable to executed commands
process.env.YARN_SILENT = '1';
// Disable wrapper in executed commands
process.env.YARN_WRAP_OUTPUT = 'false';
for (const [stage, cmd] of cmds) {
// only tack on trailing arguments for default script, ignore for pre and post - #1595
const cmdWithArgs = stage === action ? sh`${unquoted(cmd)} ${args}` : cmd;
Expand Down
15 changes: 12 additions & 3 deletions src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ function findProjectRoot(base: string): string {

const boolify = val => val.toString().toLowerCase() !== 'false' && val !== '0';

function boolifyWithDefault(val: any, defaultResult: boolean): boolean {
if (val === undefined || val === null || val === '') {
return defaultResult;
} else {
return boolify(val);
}
}

export function main({
startArgs,
args,
Expand Down Expand Up @@ -207,9 +215,10 @@ export function main({
reporter.initPeakMemoryCounter();

const config = new Config(reporter);
const outputWrapper = !commander.json && command.hasWrapper(commander, commander.args);
const outputWrapperEnabled = boolifyWithDefault(process.env.YARN_WRAP_OUTPUT, true);
const shouldWrapOutput = outputWrapperEnabled && !commander.json && command.hasWrapper(commander, commander.args);

if (outputWrapper) {
if (shouldWrapOutput) {
reporter.header(commandName, {name: 'yarn', version});
}

Expand Down Expand Up @@ -243,7 +252,7 @@ export function main({
}

return command.run(config, reporter, commander, commander.args).then(exitCode => {
if (outputWrapper) {
if (shouldWrapOutput) {
reporter.footer(false);
}
return exitCode;
Expand Down

0 comments on commit e686e9f

Please sign in to comment.