Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Disable only header/footer in nested commands, not all output #4811

Merged
merged 4 commits into from
Nov 1, 2017
Merged

feat(cli): Disable only header/footer in nested commands, not all output #4811

merged 4 commits into from
Nov 1, 2017

Conversation

sth
Copy link
Contributor

@sth sth commented Oct 31, 2017

Summary

Fixes #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.

sth added 2 commits October 31, 2017 03:12
This is done instead of disabling all output, which was a bit
too much (see issue #4615).
Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very simple and elegant solution, I love it.

Added a comment to make the detection and code a bit better. Will merge after you address that.

Thanks!

src/cli/index.js Outdated
@@ -207,7 +207,8 @@ export function main({
reporter.initPeakMemoryCounter();

const config = new Config(reporter);
const outputWrapper = !commander.json && command.hasWrapper(commander, commander.args);
const outputWrapperEnv = process.env.YARN_WRAPOUTPUT === undefined || process.env.YARN_WRAPOUTPUT == '1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with the following:

const disableOutputWrapper = process.env.YARN_WRAPOUTPUT === '0' || process.env.YARN_WRAPOUTPUT === 'false';
const shouldWrapOutput = !disableOutputWrapper && !commander.json && command.hasWrapper(commander, commander.args);

if (shouldWrapOutput) {

@buildsize
Copy link

buildsize bot commented Oct 31, 2017

This change will increase the build size from 9.94 MB to 9.94 MB, an increase of 448 bytes (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 859.9 KB 859.91 KB 13 bytes (0%)
yarn-[version].js 3.78 MB 3.78 MB 272 bytes (0%)
yarn-legacy-[version].js 3.83 MB 3.83 MB 272 bytes (0%)
yarn-v[version].tar.gz 865.5 KB 865.55 KB 47 bytes (0%)
yarn_[version]all.deb 654.58 KB 654.42 KB -156 bytes (0%)

@sth
Copy link
Contributor Author

sth commented Oct 31, 2017

I moved the boolification of the environment variable into a separate function. This function can then also be used for other variables, like YARN_SILENCE, to make sure they all accept the same values as true/false.

The functionality of boolifyWithDefault() could get integrated directly into boolify(), but it seemed clearer to me as a separate function.

Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the refactoring, thanks a lot!

// propagate YARN_SILENT env variable to executed commands
process.env.YARN_SILENT = '1';
// Disable wrapper in executed commands
process.env.YARN_WRAP_OUTPUT = 'false';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: do not mutate process.env in any way.

@BYK BYK changed the title Disable only header/footer in nested commands, not all output. feat(cli): Disable only header/footer in nested commands, not all output Nov 1, 2017
@BYK BYK merged commit 6cb226f into yarnpkg:master Nov 1, 2017
@edmorley
Copy link
Contributor

edmorley commented Nov 1, 2017

Many thanks for this! :-)

@sth sth deleted the issue-4615-no-nested-wrapper branch November 1, 2017 14:32
BYK pushed a commit that referenced this pull request Nov 2, 2017
**Summary**

Use `boolifyWithDefault()` to determine if environment variable values are `true` or `false`. This ensures that all environment variables interpret the same values the same way.

This changes the behavior of `YARN_SILENT` and `YARN_IGNORE_PATH` if they have "unexpected" values, all nonempty stings beside `"0"` and `"false"` are now interpreted as `true`. For example `YARN_SILENT=hello` was interpreted as `false` before, now it is `true`. This makes some sense since those values are truthy in Javascript, but generally makes things more predictable if it works like that for all yarn environment variables.

`YARN_SILENT=true` was also interpreted as `false`. This now definitely makes more sense since it will be interpreted as `true`.

See also [#4811](#4811 (comment)).

**Test plan**

There should be no change to the existing intended functionality and the existing tests still pass.
BYK added a commit that referenced this pull request Nov 3, 2017
**Summary**

Tests started failing on Travis after #4811, somewhat randomly, due to the mexpecting the unwrapped
output. This PR fixes those expectations and moves normalize-manifest tests to snapshots since
that's easier than updating 40+ JSON files by hand.

**Test plan**

Tests should pass on all platforms and CI and locally.
BYK added a commit that referenced this pull request Nov 6, 2017
**Summary**

Tests started failing on Travis after #4811, somewhat randomly, due to them expecting the unwrapped
output. This PR fixes those expectations and moves normalize-manifest tests to snapshots since
that's easier than updating 40+ JSON files by hand.

**Test plan**

Tests should pass on all platforms and CI and locally.
calvinhuang pushed a commit to calvinhuang/yarn that referenced this pull request Nov 9, 2017
…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.
calvinhuang pushed a commit to calvinhuang/yarn that referenced this pull request Nov 9, 2017
…npkg#4823)

**Summary**

Use `boolifyWithDefault()` to determine if environment variable values are `true` or `false`. This ensures that all environment variables interpret the same values the same way.

This changes the behavior of `YARN_SILENT` and `YARN_IGNORE_PATH` if they have "unexpected" values, all nonempty stings beside `"0"` and `"false"` are now interpreted as `true`. For example `YARN_SILENT=hello` was interpreted as `false` before, now it is `true`. This makes some sense since those values are truthy in Javascript, but generally makes things more predictable if it works like that for all yarn environment variables.

`YARN_SILENT=true` was also interpreted as `false`. This now definitely makes more sense since it will be interpreted as `true`.

See also [yarnpkg#4811](yarnpkg#4811 (comment)).

**Test plan**

There should be no change to the existing intended functionality and the existing tests still pass.
calvinhuang pushed a commit to calvinhuang/yarn that referenced this pull request Nov 9, 2017
…pkg#4852)

**Summary**

Tests started failing on Travis after yarnpkg#4811, somewhat randomly, due to them expecting the unwrapped
output. This PR fixes those expectations and moves normalize-manifest tests to snapshots since
that's easier than updating 40+ JSON files by hand.

**Test plan**

Tests should pass on all platforms and CI and locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants