From 3fae3f0838bf1dd0bb2b3ca1b0b6e3c2afcd63ae Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Mon, 2 Aug 2021 14:04:22 +0300 Subject: [PATCH 1/2] Refactor colour support check, add CI support --- .gitignore | 3 ++- index.js | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 8b16100..8dd563f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ package-lock.json node_modules -coverage \ No newline at end of file +coverage +/.idea/ diff --git a/index.js b/index.js index d3f7713..6bacdb3 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,18 @@ -let enabled = - !("NO_COLOR" in process.env) && - ("FORCE_COLOR" in process.env || - process.platform === "win32" || - (process.stdout != null && - process.stdout.isTTY && - process.env.TERM && - process.env.TERM !== "dumb")) +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) const raw = (open, close, searchRegex, replaceValue) => (s) => enabled From fab0aad97db56249aec98f74ff5d8c7fcdd8343f Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Tue, 3 Aug 2021 22:03:49 +0300 Subject: [PATCH 2/2] Address comments --- index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 6bacdb3..fcdfacf 100644 --- a/index.js +++ b/index.js @@ -1,18 +1,21 @@ -const {env} = process; +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 && +const isCompatibleTerminal = + process.stdout != null && process.stdout.isTTY && env.TERM && - env.TERM !== "dumb") + env.TERM !== "dumb" -const isCI = ('CI' in env && ['CIRCLECI', 'GITLAB_CI', 'GITHUB_ACTIONS'].some(sign => sign in env)) +const isCI = + "CI" in env && + ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env) -let enabled = (!isDisabled) && - (isForced || isWindows || isCompatibleTerminal || isCI) +let enabled = + !isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI) const raw = (open, close, searchRegex, replaceValue) => (s) => enabled