Skip to content

Commit 736e0ba

Browse files
committed
feat: simplify CI color detection (may fallback to 16 colors or b&w in rare CI environments)
1 parent b36ff87 commit 736e0ba

File tree

6 files changed

+28
-43
lines changed

6 files changed

+28
-43
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ root = true
44
end_of_line = lf
55
insert_final_newline = true
66
trim_trailing_whitespace = true
7+
indent_style = space
8+
indent_size = 2
9+
tab_width = 2
710

811
[{*.cjs,*.js}]
912
indent_size = 2
@@ -15,3 +18,6 @@ tab_width = 2
1518

1619
[{LICENSE,*.json,*.md}]
1720
insert_final_newline = false
21+
22+
[{package.npm.json,dist/**}]
23+
indent_style = tab

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717
"options": {
1818
"tabWidth": 4
1919
}
20+
},
21+
{
22+
"files": [
23+
"dist/**/*.*",
24+
"package.npm.json"
25+
],
26+
"options": {
27+
"useTabs": true
28+
}
2029
}
2130
]
2231
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ansis",
3-
"version": "4.0.0-rc.7",
3+
"version": "4.0.0-rc.8",
44
"description": "A small and fast library for applying ANSI colors in terminal or browser console",
55
"keywords": [
66
"ansi",

package.npm.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name":"ansis",
3-
"version":"4.0.0-rc.7",
3+
"version":"4.0.0-rc.8",
44
"description":"ANSI color lib",
55
"keywords":["ansi","colors","cli"],
66
"license":"ISC",
77
"author":"webdiscus",
88
"repository":"webdiscus/ansis",
9-
"type": "module",
9+
"type":"module",
1010
"exports":{
11-
".":{
12-
"types":"./index.d.ts",
13-
"require":"./index.cjs",
14-
"import":"./index.mjs"
15-
}
11+
".":{
12+
"types":"./index.d.ts",
13+
"require":"./index.cjs",
14+
"import":"./index.mjs"
15+
}
1616
},
1717
"sideEffects":false,
1818
"engines":{"node":">=14"}

src/color-support.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,15 @@ let autoDetectLevel = (env, isTTY, isWin) => {
4545
// 2) Detect color support in CI.
4646
// Note: CI environments are not TTY and often advertise themselves as `dumb` terminals.
4747

48-
// Azure DevOps CI
49-
// https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
50-
if (!!env.TF_BUILD) return LEVEL_16COLORS;
51-
52-
// JetBrains TeamCity support 256 colors since 2020.1.1 (2020-06-23), TEAMCITY_VERSION in env
53-
if (/,TEAMCI/.test(envKeys)) return LEVEL_256COLORS;
54-
5548
// CI tools
5649
// https://github.com/watson/ci-info/blob/master/vendors.json
5750
if (!!env.CI) {
58-
// CI supports truecolor: GITHUB_ACTIONS, GITEA_ACTIONS
59-
if (/,GIT(HUB|EA)/.test(envKeys)) return LEVEL_TRUECOLOR;
51+
// CI supports truecolor: GITHUB_ACTIONS
52+
if (/,GITHUB/.test(envKeys)) return LEVEL_TRUECOLOR;
6053

6154
// others CI supports only 16 colors, e.g. when env contains:
6255
// - CI_NAME === codeship | sourcehut
63-
// - GITLAB_CI | TRAVIS | CIRCLECI |APPVEYOR | BUILDKITE | DRONE
56+
// - GITLAB_CI | CIRCLECI | TRAVIS | APPVEYOR | BUILDKITE | DRONE | BITBUCKET_BUILD_NUMBER | AZURE_HTTP_USER_AGENT
6457

6558
return LEVEL_16COLORS;
6659
}
@@ -138,7 +131,8 @@ export const getLevel = (mockThis) => {
138131
}
139132

140133
// PM2 does not set process.stdout.isTTY, but colors may be supported (depends on actual terminal)
141-
let isPM2 = !!env.PM2_HOME && !!env.pm_id;
134+
// PM2_HOME is always set by PM2, whether running in fork or cluster mode
135+
let isPM2 = !!env.PM2_HOME;
142136

143137
// when Next.JS runtime is `edge`, process.stdout is undefined, but colors output is supported
144138
// runtime values supported colors: `nodejs`, `edge`, `experimental-edge`

test/unit.test.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,30 +226,6 @@ describe('CI tools', () => {
226226
const expected = LEVEL_16COLORS;
227227
expect(expected).toEqual(received);
228228
});
229-
230-
test(`Azure CI`, () => {
231-
const received = getLevel({
232-
process: {
233-
env: { TF_BUILD: true },
234-
argv: [],
235-
},
236-
237-
});
238-
const expected = LEVEL_16COLORS;
239-
expect(expected).toEqual(received);
240-
});
241-
242-
test(`TeamCity`, () => {
243-
const received = getLevel({
244-
process: {
245-
env: { TEAMCITY_VERSION: '2020.1.1' },
246-
argv: [],
247-
},
248-
249-
});
250-
const expected = LEVEL_256COLORS;
251-
expect(expected).toEqual(received);
252-
});
253229
});
254230

255231
describe('flags and options', () => {

0 commit comments

Comments
 (0)