Yarn: Add `--silent` flag to CLI run command

77

Do you want to request a _feature_ or report a _bug_?

feature

What is the current behavior?

I use the npm test command in my ember cli projects to run my tests. I was happy to see that yarn test works the same way as npm test but it's missing one feature that I use: the --silent flag.

When I run yarn test --silent (or yarn run test --silent) it prints out the yarn version and command it runs:

$ yarn run test --silent
yarn run v0.15.1
$ ember test
...

What is the expected behavior?

I would expect that when I run yarn run <cmd> --silent it would suppress the output of the yarn version and the command it is running, similar to how npm run --silent works.

Please mention your node.js, yarn and operating system version.

Node: v4.6.0
Yarn: v0.15.1
OS: MacOS Sierra 10.12.0

pgrippi picture pgrippi  ·  12 Oct 2016

Most helpful comment

68

Ah, but I do care about the output. My use case here is that I'm running the test on a CI server and the output is an xml file. My command looks something like this:

yarn test --silent -- --other-args > junit.xml

Since yarn prints out the version and command the xml file generated by my test script has that in it before the xml output and I'm left with an invalid xml file.

pgrippi picture pgrippi  ·  12 Oct 2016

All comments

-38

Talked a bit with @cpojer on discord about exactly how silent something like this should be and he convinced me at least that this might not be a necessary thing for a cli to provide. Nothing that I could think of can't be handled by a >/dev/null 2>&1 if you _really_ don't care about the output.

Counterpoints?

FLGMwt picture FLGMwt  ·  12 Oct 2016
68

Ah, but I do care about the output. My use case here is that I'm running the test on a CI server and the output is an xml file. My command looks something like this:

yarn test --silent -- --other-args > junit.xml

Since yarn prints out the version and command the xml file generated by my test script has that in it before the xml output and I'm left with an invalid xml file.

pgrippi picture pgrippi  ·  12 Oct 2016
13

Also, terminal colors mess up the output when doing deploys here. Maybe it's something that should be addressed in the way my deploys are done but a simple --silent flag would avoid stuff like:

[2Kyarn install v0.15.1
[1/4] Resolving packages...
[2/4] Fetching packages...
 0/790 5/790 226/790 745/790warning [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning Unmet peer dependency "[email protected] || 0.20.x || 0.22.x".
 0/32 0/2095 131/2095 332/2095 524/2095 759/2095 976/2095 1229/2095 1493/2095 1733/2095 1877/2095 2031/2095 0/32[4/4] Building fresh packages...




success Saved lockfile.
Done in 2.64s.

With npm you can do npm install --progress false --color false to ease things a bit.

robotvert picture robotvert  ·  12 Oct 2016
14

If stdout is not connected to a terminal then it should not use _any_ control characters; just like npm does

jacott picture jacott  ·  13 Oct 2016
6

We would love to see this on many more of the yarn commands -- install, upgrade, and outdated come to mind. We use a bunch of private, internal modules, and to determine whether they are up-to-date, we run npm/yarn outdated on each module inside our modules folder. npm outdated outputs nothing if there are no outdated package dependencies, so with npm, the output of our recursive outdated command looks like this (simplified):

/modules/button
/modules/sortable-list
Package             Current  Wanted  Latest  Location
react-sortable-hoc   0.0.11  0.0.11   0.1.0  sortable-list
/modules/tabs
/modules/textbox
/modules/tooltip

The equivalent output in yarn looks like this:

/modules/button
yarn outdated v0.16.1
Done in 0.30s.
/modules/sortable-list
yarn outdated v0.16.1
Package            Current Wanted Latest
react-sortable-hoc 0.0.11  0.0.11 0.1.0
Done in 0.41s.
/modules/tabs
yarn outdated v0.16.1
Done in 0.32s.
/modules/textbox
yarn outdated v0.16.1
Done in 0.37s.
/modules/tooltip
yarn outdated v0.16.1
Done in 0.20s.

The signal/noise ratio in the second example is much lower. We most definitely care about relevant output (in this case, outdated packages), and a way to silence the surrounding yarn front- and back-matter would be really helpful.

chrisvasz picture chrisvasz  ·  21 Oct 2016
5

I found a really terrible way to work around this:

"scripts": {
  "command-that-captures-output": "cat $(yarn run command-that-yields-output 2>&1 >/dev/null)",
  "command-that-yields-output": ">&2 echo ./path-to-a-file-we-care-about"
}

The order of redirects is really important here. For command-that-yields-output, I'm sticking the output I care about in stderr, then in command-that-captures-output, I'm pointing stderr to the tty that stdout is currently connected to, I'm then pointing stdout to /dev/null. This results in stderr going to the tty that cat is connected to, and silencing the builtin yarn output.

Hope this helps!

minasmart picture minasmart  ·  19 Jan 2017
5

Status on this? When using Yarn for build scripts, it gets really noisy really fast. This is what happens when I run multiple scripts through watchers:

image

And I'm just getting started. Every time I change a watched file, it reruns the yarn command with a bunch of output that makes it hard to read the stuff I care about—all the non-yarn output.

Update I see that it's being worked on in #2420 w00t!

arxpoetica picture arxpoetica  ·  9 Feb 2017
9

fixed in #2420

joscha picture joscha  ·  11 Apr 2017
2

@bestander this is fixed. we can close it!

voxsim picture voxsim  ·  28 Apr 2017
5

Thanks guys. this CHANGED MY LIFE. 😂

arxpoetica picture arxpoetica  ·  28 Apr 2017
0

Did this get removed in 1.0?

contra picture contra  ·  10 Sep 2017
0

Did this get removed in 1.0?

Nope, this is a bug from #4152. Filed #4383 to track it.

BYK picture BYK  ·  10 Sep 2017
0

I'm not seeing the --silent option documented: https://yarnpkg.com/en/docs/cli/install

Did it get removed?

lmj0011 picture lmj0011  ·  19 Sep 2017
0

@lmj0011 sorry, it is there. Just not documented. Filed https://github.com/yarnpkg/website/issues/653 to track.

BYK picture BYK  ·  19 Sep 2017
6

yarn upgrade --silent does output. Or this command was not changed?
yarn version - 1.2.1

ruslan-polutsygan picture ruslan-polutsygan  ·  20 Oct 2017
2

The lack of a quiet option in Yarn is probably my least favorite thing about Yarn. I can get all my other commands in CI to be quiet (aside from errors) except for Yarn. It always wants to make noise, and it's totally unnecessary.

mojavelinux picture mojavelinux  ·  5 Feb 2018
1

@mojavelinux use the --silent flag. I use it all the time. It works.

arxpoetica picture arxpoetica  ·  5 Feb 2018
0

Sorry, but it doesn't. Yarn still makes all kinds of noise. What does work is to pipe to /dev/null.

yarn add package-name > /dev/null

That only outputs warnings and errors, which is exactly what I expect a --quiet flag to do.

mojavelinux picture mojavelinux  ·  5 Feb 2018
5

Are you putting the --silent flag in the right place? This is what it looks like for me:

image

Note the blank space beneath the command. Nada. Nothing. What version of yarn are you running? Here it is without the silent flag:

image

arxpoetica picture arxpoetica  ·  5 Feb 2018
0

For me, the noisy part is really that yarn outputs the whole first level of the dependency tree. This does not change with --silent which I think is wrong...

mastertinner picture mastertinner  ·  27 Feb 2018
0

Chiming in since I was the one that implemented --silent for yarn. Your expectations are correct for this feature. Have you tried what @arxpoetica proposed? I know it's kind of annoying but the flag positions matters for yarn.

@bestander If this is a valid issue and you would like me to tackle it, feel free to create an issue and assign it to me.

rafaelrinaldi picture rafaelrinaldi  ·  23 Mar 2018
0

@arxpoetica You are talking about a script. I'm talking about Yarn add or install.

I'll be honest, I've sort of given up on this feature since discovering I can just pipe to /dev/null. What I'm looking for is no output. That my understanding of what a --silent flag should deliver (is there another definition of silent?). But apparently, the Yarn project views the purpose of this flag differently. Fortunately, /dev/null fills that void.

mojavelinux picture mojavelinux  ·  23 Mar 2018
5

Ah. Yes. Well, that would be different than what this ticket mentions which is CLI run. Open a new ticket! I think I agree with you: --silent should be applied universally, not just with the run command.

arxpoetica picture arxpoetica  ·  23 Mar 2018