Skip to content

Commit 7443e9f

Browse files
authored
Update supports-color dependency (#579)
1 parent a027e3c commit 7443e9f

3 files changed

Lines changed: 40 additions & 20 deletions

File tree

source/vendor/supports-color/browser.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
/* eslint-env browser */
22

3-
const isBlinkBasedBrowser = navigator.userAgentData
4-
? navigator.userAgentData.brands.some(({brand}) => brand === 'Chromium')
5-
: /\b(Chrome|Chromium)\//.test(navigator.userAgent);
3+
const level = (() => {
4+
if (navigator.userAgentData) {
5+
const brand = navigator.userAgentData.brands.find(({brand}) => brand === 'Chromium');
6+
if (brand && brand.version > 93) {
7+
return 3;
8+
}
9+
}
610

7-
const colorSupport = isBlinkBasedBrowser ? {
8-
level: 1,
11+
if (/\b(Chrome|Chromium)\//.test(navigator.userAgent)) {
12+
return 1;
13+
}
14+
15+
return 0;
16+
})();
17+
18+
const colorSupport = level !== 0 && {
19+
level,
920
hasBasic: true,
10-
has256: false,
11-
has16m: false,
12-
} : false;
21+
has256: level >= 2,
22+
has16m: level >= 3,
23+
};
1324

1425
const supportsColor = {
1526
stdout: colorSupport,

source/vendor/supports-color/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import {WriteStream} from 'node:tty';
1+
import type {WriteStream} from 'node:tty';
22

3-
export interface Options {
3+
export type Options = {
44
/**
55
Whether `process.argv` should be sniffed for `--color` and `--no-color` flags.
66
77
@default true
88
*/
99
readonly sniffFlags?: boolean;
10-
}
10+
};
1111

1212
/**
1313
Levels:
@@ -21,7 +21,7 @@ export type ColorSupportLevel = 0 | 1 | 2 | 3;
2121
/**
2222
Detect whether the terminal supports color.
2323
*/
24-
export interface ColorSupport {
24+
export type ColorSupport = {
2525
/**
2626
The color level.
2727
*/
@@ -41,11 +41,11 @@ export interface ColorSupport {
4141
Whether Truecolor 16 million colors are supported.
4242
*/
4343
has16m: boolean;
44-
}
44+
};
4545

4646
export type ColorInfo = ColorSupport | false;
4747

48-
export function createSupportsColor(stream: WriteStream, options?: Options): ColorInfo;
48+
export function createSupportsColor(stream?: WriteStream, options?: Options): ColorInfo;
4949

5050
declare const supportsColor: {
5151
stdout: ColorInfo;

source/vendor/supports-color/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import os from 'node:os';
33
import tty from 'node:tty';
44

55
// From: https://github.com/sindresorhus/has-flag/blob/main/index.js
6-
function hasFlag(flag, argv = process.argv) {
6+
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : process.argv) {
77
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
88
const position = argv.indexOf(prefix + flag);
99
const terminatorPosition = argv.indexOf('--');
@@ -80,6 +80,12 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
8080
}
8181
}
8282

83+
// Check for Azure DevOps pipelines.
84+
// Has to be above the `!streamIsTTY` check.
85+
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
86+
return 1;
87+
}
88+
8389
if (haveStream && !streamIsTTY && forceColor === undefined) {
8490
return 0;
8591
}
@@ -105,7 +111,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
105111
}
106112

107113
if ('CI' in env) {
108-
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
114+
if ('GITHUB_ACTIONS' in env) {
115+
return 3;
116+
}
117+
118+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'BUILDKITE', 'DRONE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
109119
return 1;
110120
}
111121

@@ -116,12 +126,11 @@ function _supportsColor(haveStream, {streamIsTTY, sniffFlags = true} = {}) {
116126
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
117127
}
118128

119-
// Check for Azure DevOps pipelines
120-
if ('TF_BUILD' in env && 'AGENT_NAME' in env) {
121-
return 1;
129+
if (env.COLORTERM === 'truecolor') {
130+
return 3;
122131
}
123132

124-
if (env.COLORTERM === 'truecolor') {
133+
if (env.TERM === 'xterm-kitty') {
125134
return 3;
126135
}
127136

0 commit comments

Comments
 (0)