supports-color 5.5.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +31 -23
  2. package/package.json +6 -6
  3. package/readme.md +13 -3
package/index.js CHANGED
@@ -1,22 +1,31 @@
1
1
  'use strict';
2
2
  const os = require('os');
3
+ const tty = require('tty');
3
4
  const hasFlag = require('has-flag');
4
5
 
5
- const env = process.env;
6
+ const {env} = process;
6
7
 
7
8
  let forceColor;
8
9
  if (hasFlag('no-color') ||
9
10
  hasFlag('no-colors') ||
10
- hasFlag('color=false')) {
11
- forceColor = false;
11
+ hasFlag('color=false') ||
12
+ hasFlag('color=never')) {
13
+ forceColor = 0;
12
14
  } else if (hasFlag('color') ||
13
15
  hasFlag('colors') ||
14
16
  hasFlag('color=true') ||
15
17
  hasFlag('color=always')) {
16
- forceColor = true;
18
+ forceColor = 1;
17
19
  }
20
+
18
21
  if ('FORCE_COLOR' in env) {
19
- forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
22
+ if (env.FORCE_COLOR === 'true') {
23
+ forceColor = 1;
24
+ } else if (env.FORCE_COLOR === 'false') {
25
+ forceColor = 0;
26
+ } else {
27
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
28
+ }
20
29
  }
21
30
 
22
31
  function translateLevel(level) {
@@ -32,8 +41,8 @@ function translateLevel(level) {
32
41
  };
33
42
  }
34
43
 
35
- function supportsColor(stream) {
36
- if (forceColor === false) {
44
+ function supportsColor(haveStream, streamIsTTY) {
45
+ if (forceColor === 0) {
37
46
  return 0;
38
47
  }
39
48
 
@@ -47,22 +56,21 @@ function supportsColor(stream) {
47
56
  return 2;
48
57
  }
49
58
 
50
- if (stream && !stream.isTTY && forceColor !== true) {
59
+ if (haveStream && !streamIsTTY && forceColor === undefined) {
51
60
  return 0;
52
61
  }
53
62
 
54
- const min = forceColor ? 1 : 0;
63
+ const min = forceColor || 0;
64
+
65
+ if (env.TERM === 'dumb') {
66
+ return min;
67
+ }
55
68
 
56
69
  if (process.platform === 'win32') {
57
- // Node.js 7.5.0 is the first version of Node.js to include a patch to
58
- // libuv that enables 256 color output on Windows. Anything earlier and it
59
- // won't work. However, here we target Node.js 8 at minimum as it is an LTS
60
- // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
61
- // release that supports 256 colors. Windows 10 build 14931 is the first release
62
- // that supports 16m/TrueColor.
70
+ // Windows 10 build 10586 is the first Windows release that supports 256 colors.
71
+ // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
63
72
  const osRelease = os.release().split('.');
64
73
  if (
65
- Number(process.versions.node.split('.')[0]) >= 8 &&
66
74
  Number(osRelease[0]) >= 10 &&
67
75
  Number(osRelease[2]) >= 10586
68
76
  ) {
@@ -84,6 +92,10 @@ function supportsColor(stream) {
84
92
  return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
85
93
  }
86
94
 
95
+ if ('GITHUB_ACTIONS' in env) {
96
+ return 1;
97
+ }
98
+
87
99
  if (env.COLORTERM === 'truecolor') {
88
100
  return 3;
89
101
  }
@@ -112,20 +124,16 @@ function supportsColor(stream) {
112
124
  return 1;
113
125
  }
114
126
 
115
- if (env.TERM === 'dumb') {
116
- return min;
117
- }
118
-
119
127
  return min;
120
128
  }
121
129
 
122
130
  function getSupportLevel(stream) {
123
- const level = supportsColor(stream);
131
+ const level = supportsColor(stream, stream && stream.isTTY);
124
132
  return translateLevel(level);
125
133
  }
126
134
 
127
135
  module.exports = {
128
136
  supportsColor: getSupportLevel,
129
- stdout: getSupportLevel(process.stdout),
130
- stderr: getSupportLevel(process.stderr)
137
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
138
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
131
139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supports-color",
3
- "version": "5.5.0",
3
+ "version": "7.1.0",
4
4
  "description": "Detect whether a terminal supports color",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/supports-color",
@@ -10,7 +10,7 @@
10
10
  "url": "sindresorhus.com"
11
11
  },
12
12
  "engines": {
13
- "node": ">=4"
13
+ "node": ">=8"
14
14
  },
15
15
  "scripts": {
16
16
  "test": "xo && ava"
@@ -42,12 +42,12 @@
42
42
  "16m"
43
43
  ],
44
44
  "dependencies": {
45
- "has-flag": "^3.0.0"
45
+ "has-flag": "^4.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "ava": "^0.25.0",
49
- "import-fresh": "^2.0.0",
50
- "xo": "^0.20.0"
48
+ "ava": "^1.4.1",
49
+ "import-fresh": "^3.0.0",
50
+ "xo": "^0.24.0"
51
51
  },
52
52
  "browser": "browser.js"
53
53
  }
package/readme.md CHANGED
@@ -44,7 +44,7 @@ The `stdout`/`stderr` objects specifies a level of support for color through a `
44
44
 
45
45
  It obeys the `--color` and `--no-color` CLI flags.
46
46
 
47
- Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, add the environment variable `FORCE_COLOR=1` to forcefully enable color or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
47
+ For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
48
48
 
49
49
  Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
50
50
 
@@ -61,6 +61,16 @@ Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=
61
61
  - [Josh Junon](https://github.com/qix-)
62
62
 
63
63
 
64
- ## License
64
+ ---
65
65
 
66
- MIT
66
+ <div align="center">
67
+ <b>
68
+ <a href="https://tidelift.com/subscription/pkg/npm-supports-color?utm_source=npm-supports-color&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
69
+ </b>
70
+ <br>
71
+ <sub>
72
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
73
+ </sub>
74
+ </div>
75
+
76
+ ---