[Pkg-javascript-commits] [node-supports-color] 01/04: New upstream version 4.4.0
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Fri Sep 8 14:19:28 UTC 2017
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-supports-color.
commit c888bed739741f3d002bcf63a2fed241619f2481
Author: Pirate Praveen <praveen at debian.org>
Date: Fri Sep 8 19:34:38 2017 +0530
New upstream version 4.4.0
---
.editorconfig | 5 +-
.gitattributes | 1 +
.npmrc | 1 +
.travis.yml | 12 +--
index.js | 59 +++++++++---
license | 20 +---
package.json | 29 ++----
readme.md | 20 ++--
test.js | 293 +++++++++++++++++++++++++++++++++++++++++----------------
9 files changed, 286 insertions(+), 154 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 8f9d77e..1c6314a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
-[{package.json,*.yml}]
+[*.yml]
indent_style = space
indent_size = 2
-
-[*.md]
-trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
index 176a458..391f0a4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
* text=auto
+*.js text eol=lf
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/.travis.yml b/.travis.yml
index 97baceb..7d69d74 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,11 +1,5 @@
-sudo: false
language: node_js
node_js:
- - 'stable'
- - '0.12'
- - '0.10'
- - '0.8'
-before_install:
- - npm install -g npm at 2
-script:
- - npm run travis
+ - '8'
+ - '6'
+ - '4'
diff --git a/index.js b/index.js
index 2571c73..a5d9331 100644
--- a/index.js
+++ b/index.js
@@ -1,20 +1,23 @@
'use strict';
-var hasFlag = require('has-flag');
+const os = require('os');
+const hasFlag = require('has-flag');
-var support = function (level) {
+const env = process.env;
+
+const support = level => {
if (level === 0) {
return false;
}
return {
- level: level,
+ level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3
};
};
-var supportLevel = (function () {
+let supportLevel = (() => {
if (hasFlag('no-color') ||
hasFlag('no-colors') ||
hasFlag('color=false')) {
@@ -43,42 +46,70 @@ var supportLevel = (function () {
}
if (process.platform === 'win32') {
+ // Node.js 7.5.0 is the first version of Node.js to include a patch to
+ // libuv that enables 256 color output on Windows. Anything earlier and it
+ // won't work. However, here we target Node.js 8 at minimum as it is an LTS
+ // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
+ // release that supports 256 colors.
+ const osRelease = os.release().split('.');
+ if (
+ Number(process.versions.node.split('.')[0]) >= 8 &&
+ Number(osRelease[0]) >= 10 &&
+ Number(osRelease[2]) >= 10586
+ ) {
+ return 2;
+ }
+
return 1;
}
- if ('CI' in process.env) {
- if ('TRAVIS' in process.env || process.env.CI === 'Travis') {
+ if ('CI' in env) {
+ if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
return 1;
}
return 0;
}
- if ('TEAMCITY_VERSION' in process.env) {
- return process.env.TEAMCITY_VERSION.match(/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/) === null ? 0 : 1;
+ if ('TEAMCITY_VERSION' in env) {
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
+ }
+
+ if ('TERM_PROGRAM' in env) {
+ const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
+
+ switch (env.TERM_PROGRAM) {
+ case 'iTerm.app':
+ return version >= 3 ? 3 : 2;
+ case 'Hyper':
+ return 3;
+ case 'Apple_Terminal':
+ return 2;
+ // No default
+ }
}
- if (/^(screen|xterm)-256(?:color)?/.test(process.env.TERM)) {
+ if (/-256(color)?$/i.test(env.TERM)) {
return 2;
}
- if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
+ if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(env.TERM)) {
return 1;
}
- if ('COLORTERM' in process.env) {
+ if ('COLORTERM' in env) {
return 1;
}
- if (process.env.TERM === 'dumb') {
+ if (env.TERM === 'dumb') {
return 0;
}
return 0;
})();
-if (supportLevel === 0 && 'FORCE_COLOR' in process.env) {
- supportLevel = 1;
+if ('FORCE_COLOR' in env) {
+ supportLevel = parseInt(env.FORCE_COLOR, 10) === 0 ? 0 : (supportLevel || 1);
}
module.exports = process && support(supportLevel);
diff --git a/license b/license
index 654d0bf..e7af2f7 100644
--- a/license
+++ b/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/package.json b/package.json
index 0cc4b38..ad73247 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "supports-color",
- "version": "3.2.3",
+ "version": "4.4.0",
"description": "Detect whether a terminal supports color",
"license": "MIT",
"repository": "chalk/supports-color",
@@ -9,18 +9,11 @@
"email": "sindresorhus at gmail.com",
"url": "sindresorhus.com"
},
- "maintainers": [
- "Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)",
- "Joshua Boy Nicolai Appelman <joshua at jbna.nl> (jbna.nl)",
- "JD Ballard <i.am.qix at gmail.com> (github.com/qix-)"
- ],
- "browser": "browser.js",
"engines": {
- "node": ">=0.8.0"
+ "node": ">=4"
},
"scripts": {
- "test": "xo && mocha",
- "travis": "mocha"
+ "test": "xo && ava"
},
"files": [
"index.js",
@@ -46,21 +39,15 @@
"capability",
"detect",
"truecolor",
- "16m",
- "million"
+ "16m"
],
"dependencies": {
- "has-flag": "^1.0.0"
+ "has-flag": "^2.0.0"
},
"devDependencies": {
- "mocha": "*",
- "require-uncached": "^1.0.2",
+ "ava": "*",
+ "import-fresh": "^2.0.0",
"xo": "*"
},
- "xo": {
- "envs": [
- "node",
- "mocha"
- ]
- }
+ "browser": "browser.js"
}
diff --git a/readme.md b/readme.md
index f7bae4c..3bef57d 100644
--- a/readme.md
+++ b/readme.md
@@ -6,14 +6,14 @@
## Install
```
-$ npm install --save supports-color
+$ npm install supports-color
```
## Usage
```js
-var supportsColor = require('supports-color');
+const supportsColor = require('supports-color');
if (supportsColor) {
console.log('Terminal supports color');
@@ -31,22 +31,22 @@ if (supportsColor.has16m) {
## API
-Returns an `object`, or `false` if color is not supported.
+Returns an `Object`, or `false` if color is not supported.
The returned object specifies a level of support for color through a `.level` property and a corresponding flag:
- `.level = 1` and `.hasBasic = true`: Basic color support (16 colors)
- `.level = 2` and `.has256 = true`: 256 color support
-- `.level = 3` and `.has16m = true`: 16 million (truecolor) support
+- `.level = 3` and `.has16m = true`: Truecolor support (16 million colors)
## Info
It obeys the `--color` and `--no-color` CLI flags.
-For situations where using `--color` is not possible, add an environment variable `FORCE_COLOR` with any value to force color. Trumps `--no-color`.
+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.
-Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
+Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
## Related
@@ -55,6 +55,12 @@ Explicit 256/truecolor mode can be enabled using the `--color=256` and `--color=
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
+## Maintainers
+
+- [Sindre Sorhus](https://github.com/sindresorhus)
+- [Josh Junon](https://github.com/qix-)
+
+
## License
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT
diff --git a/test.js b/test.js
index b9d7984..eb62c2a 100644
--- a/test.js
+++ b/test.js
@@ -1,164 +1,291 @@
-'use strict';
-var assert = require('assert');
-var requireUncached = require('require-uncached');
+import os from 'os';
+import {serial as test} from 'ava';
+import importFresh from 'import-fresh';
-beforeEach(function () {
+test.beforeEach(() => {
+ Object.defineProperty(process, 'platform', {
+ value: 'linux'
+ });
process.stdout.isTTY = true;
process.argv = [];
process.env = {};
});
-it('should return true if `FORCE_COLOR` is in env', function () {
+test('return true if `FORCE_COLOR` is in env', t => {
process.env.FORCE_COLOR = true;
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
- assert.equal(result.level, 1);
+ const result = importFresh('.');
+ t.truthy(result);
+ t.is(result.level, 1);
});
-it('should return false if not TTY', function () {
+test('return true if `FORCE_COLOR` is in env, but honor 256', t => {
+ process.argv = ['--color=256'];
+ process.env.FORCE_COLOR = true;
+ const result = importFresh('.');
+ t.truthy(result);
+ t.is(result.level, 2);
+});
+
+test('return true if `FORCE_COLOR` is in env, but honor 256', t => {
+ process.argv = ['--color=256'];
+ process.env.FORCE_COLOR = '1';
+ const result = importFresh('.');
+ t.truthy(result);
+ t.is(result.level, 2);
+});
+
+test('return false if `FORCE_COLOR` is in env and is 0', t => {
+ process.env.FORCE_COLOR = '0';
+ const result = importFresh('.');
+ t.false(result);
+});
+
+test('return false if not TTY', t => {
process.stdout.isTTY = false;
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should return false if --no-color flag is used', function () {
+test('return false if --no-color flag is used', t => {
process.env = {TERM: 'xterm-256color'};
process.argv = ['--no-color'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should return false if --no-colors flag is used', function () {
+test('return false if --no-colors flag is used', t => {
process.env = {TERM: 'xterm-256color'};
process.argv = ['--no-colors'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should return true if --color flag is used', function () {
+test('return true if --color flag is used', t => {
process.argv = ['--color'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should return true if --colors flag is used', function () {
+test('return true if --colors flag is used', t => {
process.argv = ['--colors'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should return true if `COLORTERM` is in env', function () {
+test('return true if `COLORTERM` is in env', t => {
process.env.COLORTERM = true;
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should support `--color=true` flag', function () {
+test('support `--color=true` flag', t => {
process.argv = ['--color=true'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should support `--color=always` flag', function () {
+test('support `--color=always` flag', t => {
process.argv = ['--color=always'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should support `--color=false` flag', function () {
+test('support `--color=false` flag', t => {
process.env = {TERM: 'xterm-256color'};
process.argv = ['--color=false'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should support `--color=256` flag', function () {
+test('support `--color=256` flag', t => {
process.argv = ['--color=256'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('level should be 2 if `--color=256` flag is used', function () {
+test('level should be 2 if `--color=256` flag is used', t => {
process.argv = ['--color=256'];
- var result = requireUncached('./');
- assert.equal(result.level, 2);
- assert.equal(result.has256, true);
+ const result = importFresh('.');
+ t.is(result.level, 2);
+ t.true(result.has256);
});
-it('should support `--color=16m` flag', function () {
+test('support `--color=16m` flag', t => {
process.argv = ['--color=16m'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should support `--color=full` flag', function () {
+test('support `--color=full` flag', t => {
process.argv = ['--color=full'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should support `--color=truecolor` flag', function () {
+test('support `--color=truecolor` flag', t => {
process.argv = ['--color=truecolor'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('level should be 3 if `--color=16m` flag is used', function () {
+test('level should be 3 if `--color=16m` flag is used', t => {
process.argv = ['--color=16m'];
- var result = requireUncached('./');
- assert.equal(result.level, 3);
- assert.equal(result.has256, true);
- assert.equal(result.has16m, true);
+ const result = importFresh('.');
+ t.is(result.level, 3);
+ t.true(result.has256);
+ t.true(result.has16m);
});
-it('should ignore post-terminator flags', function () {
+test('ignore post-terminator flags', t => {
process.argv = ['--color', '--', '--no-color'];
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should allow tests of the properties on false', function () {
+test('allow tests of the properties on false', t => {
process.env = {TERM: 'xterm-256color'};
process.argv = ['--no-color'];
- var result = requireUncached('./');
- assert.equal(Boolean(result.hasBasic), false);
- assert.equal(Boolean(result.has256), false);
- assert.equal(Boolean(result.has16m), false);
- assert.equal(result.level > 0, false);
+ const result = importFresh('.');
+ t.is(result.hasBasic, undefined);
+ t.is(result.has256, undefined);
+ t.is(result.has16m, undefined);
+ t.false(result.level > 0);
});
-it('should return false if `CI` is in env', function () {
+test('return false if `CI` is in env', t => {
process.env.CI = 'AppVeyor';
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should return true if `TRAVIS` is in env', function () {
+test('return true if `TRAVIS` is in env', t => {
process.env = {CI: 'Travis', TRAVIS: '1'};
- var result = requireUncached('./');
- assert.equal(Boolean(result), true);
+ const result = importFresh('.');
+ t.truthy(result);
+});
+
+test('return true if `CIRCLECI` is in env', t => {
+ process.env = {CI: true, CIRCLECI: true};
+ const result = importFresh('.');
+ t.truthy(result);
+});
+
+test('return true if `APPVEYOR` is in env', t => {
+ process.env = {CI: true, APPVEYOR: true};
+ const result = importFresh('.');
+ t.truthy(result);
+});
+
+test('return true if `GITLAB_CI` is in env', t => {
+ process.env = {CI: true, GITLAB_CI: true};
+ const result = importFresh('.');
+ t.truthy(result);
});
-it('should return false if `TEAMCITY_VERSION` is in env and is < 9.1', function () {
+test('return true if Codeship is in env', t => {
+ process.env = {CI: true, CI_NAME: 'codeship'};
+ const result = importFresh('.');
+ t.truthy(result);
+});
+
+test('return false if `TEAMCITY_VERSION` is in env and is < 9.1', t => {
process.env.TEAMCITY_VERSION = '9.0.5 (build 32523)';
- var result = requireUncached('./');
- assert.equal(Boolean(result), false);
+ const result = importFresh('.');
+ t.false(result);
});
-it('should return level 1 if `TEAMCITY_VERSION` is in env and is >= 9.1', function () {
+test('return level 1 if `TEAMCITY_VERSION` is in env and is >= 9.1', t => {
process.env.TEAMCITY_VERSION = '9.1.0 (build 32523)';
- var result = requireUncached('./');
- assert.equal(result.level, 1);
+ const result = importFresh('.');
+ t.is(result.level, 1);
});
-it('should prefer level 2/xterm over COLORTERM', function () {
+test('prefer level 2/xterm over COLORTERM', t => {
process.env = {COLORTERM: '1', TERM: 'xterm-256color'};
- var result = requireUncached('./');
- assert.equal(result.level, 2);
+ const result = importFresh('.');
+ t.is(result.level, 2);
});
-it('should support screen-256color', function () {
+test('support screen-256color', t => {
process.env = {TERM: 'screen-256color'};
- var result = requireUncached('./');
- assert.equal(result.level, 2);
+ const result = importFresh('.');
+ t.is(result.level, 2);
+});
+
+test('support putty-256color', t => {
+ process.env = {TERM: 'putty-256color'};
+ const result = importFresh('.');
+ t.is(result.level, 2);
+});
+
+test('level should be 3 when using iTerm 3.0', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'darwin'
+ });
+ process.env = {
+ TERM_PROGRAM: 'iTerm.app',
+ TERM_PROGRAM_VERSION: '3.0.10'
+ };
+ const result = importFresh('.');
+ t.is(result.level, 3);
+});
+
+test('level should be 2 when using iTerm 2.9', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'darwin'
+ });
+ process.env = {
+ TERM_PROGRAM: 'iTerm.app',
+ TERM_PROGRAM_VERSION: '2.9.3'
+ };
+ const result = importFresh('.');
+ t.is(result.level, 2);
+});
+
+test('return level 1 if on Windows earlier than 10 build 10586 and Node version is < 8.0.0', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'win32'
+ });
+ Object.defineProperty(process.versions, 'node', {
+ value: '7.5.0'
+ });
+ os.release = () => '10.0.10240';
+ const result = importFresh('.');
+ t.is(result.level, 1);
+});
+
+test('return level 1 if on Windows 10 build 10586 or later and Node version is < 8.0.0', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'win32'
+ });
+ Object.defineProperty(process.versions, 'node', {
+ value: '7.5.0'
+ });
+ os.release = () => '10.0.10586';
+ const result = importFresh('.');
+ t.is(result.level, 1);
+});
+
+test('return level 1 if on Windows earlier than 10 build 10586 and Node version is >= 8.0.0', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'win32'
+ });
+ Object.defineProperty(process.versions, 'node', {
+ value: '8.0.0'
+ });
+ os.release = () => '10.0.10240';
+ const result = importFresh('.');
+ t.is(result.level, 1);
+});
+
+test('return level 2 if on Windows 10 build 10586 or later and Node version is >= 8.0.0', t => {
+ Object.defineProperty(process, 'platform', {
+ value: 'win32'
+ });
+ Object.defineProperty(process.versions, 'node', {
+ value: '8.0.0'
+ });
+ os.release = () => '10.0.10586';
+ const result = importFresh('.');
+ t.is(result.level, 2);
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-supports-color.git
More information about the Pkg-javascript-commits
mailing list