Don't use ANSI codes if stdout isn't a TTY#2903
Conversation
|
About the |
|
What if we printed the progress information to stderr instead? |
|
I'm concerned that printing to stderr might flag the run as an error in some CI servers... Also, I personally would prefer the name |
|
Warnings are usually printed to stderr, and I have not seen CI failures because of warnings. As far as I know, only the exit code matters. |
|
|
|
Can we use |
|
Will change it to |
b372624 to
1f3ca64
Compare
Signed-off-by: Joern Bernhardt <[email protected]>
1f3ca64 to
4d79b74
Compare
|
Should be updated now and use |
lydell
left a comment
There was a problem hiding this comment.
Looks good! I made a few small comments, though.
|
|
||
| const runPrettier = require("../runPrettier"); | ||
|
|
||
| test("output with --list-different + unformated differs when piped", () => { |
There was a problem hiding this comment.
Typo: "formated" → "formatted"
There are more instances of this below, including some file names.
There was a problem hiding this comment.
I've copied the texts from the write.js tests. Shall I rename the files in there as well or do you want to just have the string typos fixed and the file changes in another PR?
There was a problem hiding this comment.
I see. Let's do it in another PR (if you feel like it).
| exports[`no file diffs with --list-different + formated file 2`] = `Array []`; | ||
|
|
||
| exports[`output with --list-different + unformated differs when piped 1`] = ` | ||
| "unformated.js[2K[1Gunformated.js |
There was a problem hiding this comment.
Can you add --no-color to these tests? We've had CI failures because of this before. (Also, the tests become more readable.)
Signed-off-by: Joern Bernhardt <[email protected]>
| exports[`no file diffs with --list-different + formatted file 2`] = `Array []`; | ||
|
|
||
| exports[`output with --list-different + unformatted differs when piped 1`] = ` | ||
| "unformated.js[2K[1Gunformated.js |
There was a problem hiding this comment.
I thought this was a color code. Oh well, --no-color doesn't hurt anyway. I guess it's from moving the cursor.
There was a problem hiding this comment.
Yes, and that's exactly the problem I had when piping the output: The next command in the pipe complained about that... :)
|
I'd rename |
|
|
||
| process.chdir(normalizeDir(dir)); | ||
| process.stdin.isTTY = !!options.isTTY; | ||
| process.stdout.isTTY = !!options.stdoutIsTTY; |
There was a problem hiding this comment.
I think we can just use the existing isTTY here; I don't know of any real-world situations where stdin is a tty and stdout isn't (or vice-versa)
There was a problem hiding this comment.
https://nodejs.org/api/process.html
$ node -p "Boolean(process.stdin.isTTY)" true $ echo "foo" | node -p "Boolean(process.stdin.isTTY)" false $ node -p "Boolean(process.stdout.isTTY)" true $ node -p "Boolean(process.stdout.isTTY)" | cat false
I think it is correct to use process.stdout.isTTY here.
|
Would this issue also solve something like this prettier/vim-prettier#59? Having issues now with prettier 1.7.1 since we are printting the message
Sad :( |
I don't think so. That warning should be printed with |
|
If const child_process = require("child_process");
const pathToPrettierCli = "node_modules/.bin/prettier";
const result = child_process.spawnSync(pathToPrettierCli, ["--parser", "postcss"], {
encoding: "utf8",
input: ".test { display: none; }"
});
console.log('stdout', result.stdout);
console.log('stderr', result.stderr);
console.log('status', result.status);Should we add some kind of logger system so that they can easily get what they want and we can also log some debug information so as to trace what the root cause is? e.g. |
|
Sounds good to me. |
|
Renamed the PR and merged. Thanks! |
|
This broke this build. |
|
I have no idea. After fetching again, I see that my branch diverged from yours. Probably some git issue? |
I've tried to pipe the output of
--list-differencesintoxargs git add, but due to the progress information, the stdout is not really usable.This commit could fix that by suppressing output information. I think it might make sense to change
process.stdout/console.logtoprocess.stderr/console.errorin case of errors, but I did not want to put multiple things into one PR.Doing
yarndid not work for me as it currently cannot find the Git commit ofpostcss-values-parserreferenced in thepackage.json. I've installed thelatestversion of it to get it to run, but this is probably the cause why thecss_numbers/jsfmt.spec.jstest fails for me locally.Edit: Forgot
yarn lintinitially, which is now fixed :)