-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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(colors): add options for forcing color/no-color #990
Conversation
Someone is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
613d9c5
to
eda1b78
Compare
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/vercel/turbo-site/4eYh7sUmmf9eM8Y2VGkqJksmun4u |
18160dd
to
e4b563d
Compare
run: pnpm turbo run test --scope=cli | ||
run: pnpm turbo -- run test --scope=cli --color |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the positional arguments were being passed in before:
./turbow.sh "run" "test"
This now gets sent as:
./turbow.sh "run" "test" "--scope=cli" "--color"
Likely a change in behavior when switching to pnpm from yarn
e4b563d
to
9bc2bac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where this is going!
cd811a1
to
c16f6d1
Compare
Thanks for your review @gsoltis I believe I have addressed all of your feedback. I mostly used your suggested naming, I think the only thing that was unspecified was the function to construct the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, just a couple minor things and I think this should be good to go
cli/internal/ui/ui.go
Outdated
} | ||
|
||
func (into *stripAnsiWriter) Write(src []byte) (n int, err error) { | ||
into.wrappedWriter.Write(ansiRegex.ReplaceAll(src, []byte{})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it is losing the return values?
I think in general we prefer not to use named return variables for this reason and general readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was somewhat intentional (ignoring the return value), but the named return variables was an oversight, I copied that out of the interface definition in io.go.
This is still a little bit weird because if there was no error writing, we actually need to return len(src), nil
. Since the n
returned from wrappedWriter.Write
may be smaller than the number of bytes passed in, that is expected to be an error.
I changed things around so that if the wrapped call returns an error, we return that error and the associated number of bytes written instead of just ignoring the error completely, but the number of bytes written doesn't necessarily correlate to the source bytes in a way someone could meaningfully handle the error. My assumption is that Stdout and Stderr are very unlikely to produce an error when writing.
I added the reasoning above as a code comment as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that works.
This change checks for --color / --no-color as command-line arguments as a mechanism for forcing color in non-TTY situations, or forcing --no-color for TTY. Additionally, this change hooks into the FORCED_COLOR environment variable that is used by the [`supports-color` npm package](https://www.npmjs.com/package/supports-color) that is used by a variety of packages in the node ecosystem. The intention of this PR is to alleviate some of the concerns from Issue vercel#897 by allowing users of turborepo to enable color output on CI runners such as Github Actions which support color output (as mentioned in the [fatih/color documentation](https://github.com/fatih/color/tree/master#github-actions)). With github actions and local builds are both running in color, then the cached output should be consistently in color, compared to the current situation where its a mix of color and non-color output with a remote shared between CI and users building interactively. The FORCED_COLOR environment variable is something that I find myself already setting when running turbo so that the streamed output is in color for the build and testing tools that I am running with it, so it seemed like a natural way to provide this argument without needing to modify the CLI parameters being passed to turbo. In the event multiple methods are being used, the precedence is: * isTTY or not (provided by fatih/color) * $NO_COLOR (if set, then color is disabled) * $FORCED_COLOR ("1", "2", "3", "true" will enable color, "0", or "false" will disable color) * --color/--no-color (the last argument wins if both exist)
2ef6389
to
93d10e5
Compare
733acda
to
09a855f
Compare
I also made an attempt at writing some documentation for the new flags |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks for submitting this!
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This change checks for --color / --no-color as command-line arguments as a mechanism for forcing color in non-TTY situations, or forcing --no-color for TTY. Additionally, this change hooks into the
FORCED_COLOR
environment variable that is used by thesupports-color
npm package which is used by a variety of packages in the node ecosystem.The intention of this PR is to alleviate some of the concerns from Issue #897 by allowing users of turborepo to enable color output on CI runners such as Github Actions which support color output (as mentioned in the fatih/color documentation). When github actions and local builds are both running in color, then the cached output should be consistently in color, compared to the current situation where its a mix of color and non-color output with a remote cache shared between CI and users building interactively.
The
FORCED_COLOR
environment variable is something that I find myself already setting when running turbo so that the streamed output is in color for the build and testing tools that I am running with it, so it seemed like a natural way to provide this argument without needing to modify the CLI parameters being passed to turbo.In the event multiple methods are being used, the precidence is: