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

Add support for CI envs in colour support check #62

Merged
merged 2 commits into from
Aug 4, 2021

Conversation

kibertoad
Copy link
Collaborator

fixes #61

index.js Outdated
Comment on lines 1 to 15
const {env} = process;

const isDisabled = "NO_COLOR" in env
const isForced = "FORCE_COLOR" in env
const isWindows = process.platform === "win32"

const isCompatibleTerminal = (process.stdout != null &&
process.stdout.isTTY &&
env.TERM &&
env.TERM !== "dumb")

const isCI = ('CI' in env && ['CIRCLECI', 'GITLAB_CI', 'GITHUB_ACTIONS'].some(sign => sign in env))

let enabled = (!isDisabled) &&
(isForced || isWindows || isCompatibleTerminal || isCI)
Copy link
Owner

Choose a reason for hiding this comment

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

Can we do without the destructuring assignment (I know it's a bit strange, but we technically still support pre Node 6) and format the expression to this:

const env = process.env

const isDisabled = "NO_COLOR" in env
const isForced = "FORCE_COLOR" in env
const isWindows = process.platform === "win32"

const isCompatibleTerminal =
  process.stdout != null &&
  process.stdout.isTTY &&
  env.TERM &&
  env.TERM !== "dumb"

  const isCI =
  "CI" in env &&
  ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env)

let enabled =
  !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Owner

Choose a reason for hiding this comment

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

Thank you!

@jorgebucaran jorgebucaran added the enhancement New feature or request label Aug 3, 2021
@jorgebucaran jorgebucaran merged commit c16eaf3 into jorgebucaran:main Aug 4, 2021
@jorgebucaran
Copy link
Owner

@kibertoad Just checking, but does it make sense to automatically enable color inside a CI? I thought we'd want to disable it instead. Maybe I'm having a time-lapse.

@kibertoad kibertoad deleted the feat/ci-support branch August 5, 2021 21:26
@kibertoad
Copy link
Collaborator Author

@jorgebucaran It makes reading logs in CI console easier, and also this is a default behaviour for support-colours, so I would say that this is what the majority of users are actually expecting.

@jorgebucaran
Copy link
Owner

Gotcha. 👍

@fisker fisker mentioned this pull request Sep 8, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for CI environments is lacking
2 participants