diff --git a/nodejs-supports-color.spec b/nodejs-supports-color.spec new file mode 100644 index 0000000..042a525 --- /dev/null +++ b/nodejs-supports-color.spec @@ -0,0 +1,53 @@ +%{?nodejs_find_provides_and_requires} +%global enable_tests 0 +Name: nodejs-supports-color +Version: 4.4.0 +Release: 1 +Summary: Detect whether a terminal supports color +License: MIT +URL: https://github.com/chalk/supports-color +Source0: https://github.com/chalk/supports-color/archive/v%{version}.tar.gz +BuildArch: noarch +ExclusiveArch: %{nodejs_arches} noarch +BuildRequires: nodejs-packaging >= 6 npm(has-flag) +%if 0%{?enable_tests} +BuildRequires: npm(require-uncached) npm(mocha) +%endif +%description +Detect whether a terminal supports color + +%prep +%autosetup -n supports-color-%{version} +rm -rf node_modules/ +%nodejs_fixdep --caret + +%build + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/supports-color +cp -pr package.json *.js \ + %{buildroot}%{nodejs_sitelib}/supports-color +mkdir -p %{buildroot}/%{_bindir}/ +ln -s %{nodejs_sitelib}/supports-color/cli.js \ + %{buildroot}/%{_bindir}/supports-color +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{_bindir}/mocha -R spec +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + +%files +%{!?_licensedir:%global license %doc} +%license license +%doc readme.md +%{nodejs_sitelib}/supports-color/ +%{_bindir}/supports-color + +%changelog +* Tue Aug 11 2020 wangyue - 4.4.0-1 +- package init diff --git a/nodejs-supports-color.yaml b/nodejs-supports-color.yaml new file mode 100644 index 0000000..7632c5b --- /dev/null +++ b/nodejs-supports-color.yaml @@ -0,0 +1,5 @@ +git_url: https://github.com/chalk/supports-color +version_control: github +src_repo: chalk/supports-color +tag_prefix: "^v" +seperator: "." diff --git a/test.js b/test.js new file mode 100644 index 0000000..271fe4e --- /dev/null +++ b/test.js @@ -0,0 +1,385 @@ +import os from 'os'; +import {serial as test} from 'ava'; +import importFresh from 'import-fresh'; + +const currentNodeVersion = process.versions.node; + +test.beforeEach(() => { + Object.defineProperty(process, 'platform', { + value: 'linux' + }); + + Object.defineProperty(process.versions, 'node', { + value: currentNodeVersion + }); + + process.stdout.isTTY = true; + process.argv = []; + process.env = {}; +}); + +// FIXME +test.failing('return true if `FORCE_COLOR` is in env', t => { + process.stdout.isTTY = false; + process.env.FORCE_COLOR = true; + const result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 1); +}); + +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.stdout); + t.is(result.stdout.level, 2); +}); + +test('return true if `FORCE_COLOR` is in env, but honor 256 #2', t => { + process.argv = ['--color=256']; + process.env.FORCE_COLOR = '1'; + const result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.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.stdout); +}); + +test('return false if not TTY', t => { + process.stdout.isTTY = false; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return false if --no-color flag is used', t => { + process.env = {TERM: 'xterm-256color'}; + process.argv = ['--no-color']; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return false if --no-colors flag is used', t => { + process.env = {TERM: 'xterm-256color'}; + process.argv = ['--no-colors']; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return true if --color flag is used', t => { + process.argv = ['--color']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('return true if --colors flag is used', t => { + process.argv = ['--colors']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('return true if `COLORTERM` is in env', t => { + process.env.COLORTERM = true; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('support `--color=true` flag', t => { + process.argv = ['--color=true']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('support `--color=always` flag', t => { + process.argv = ['--color=always']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('support `--color=false` flag', t => { + process.env = {TERM: 'xterm-256color'}; + process.argv = ['--color=false']; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('support `--color=256` flag', t => { + process.argv = ['--color=256']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('level should be 2 if `--color=256` flag is used', t => { + process.argv = ['--color=256']; + const result = importFresh('.'); + t.is(result.stdout.level, 2); + t.true(result.stdout.has256); +}); + +test('support `--color=16m` flag', t => { + process.argv = ['--color=16m']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('support `--color=full` flag', t => { + process.argv = ['--color=full']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('support `--color=truecolor` flag', t => { + process.argv = ['--color=truecolor']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('level should be 3 if `--color=16m` flag is used', t => { + process.argv = ['--color=16m']; + const result = importFresh('.'); + t.is(result.stdout.level, 3); + t.true(result.stdout.has256); + t.true(result.stdout.has16m); +}); + +test('ignore post-terminator flags', t => { + process.argv = ['--color', '--', '--no-color']; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('allow tests of the properties on false', t => { + process.env = {TERM: 'xterm-256color'}; + process.argv = ['--no-color']; + const result = importFresh('.'); + t.is(result.stdout.hasBasic, undefined); + t.is(result.stdout.has256, undefined); + t.is(result.stdout.has16m, undefined); + t.false(result.stdout.level > 0); +}); + +test('return false if `CI` is in env', t => { + process.env.CI = 'AppVeyor'; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return true if `TRAVIS` is in env', t => { + process.env = {CI: 'Travis', TRAVIS: '1'}; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('return true if `CIRCLECI` is in env', t => { + process.env = {CI: true, CIRCLECI: true}; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('return true if `APPVEYOR` is in env', t => { + process.env = {CI: true, APPVEYOR: true}; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +test('return true if `GITLAB_CI` is in env', t => { + process.env = {CI: true, GITLAB_CI: true}; + const result = importFresh('.'); + t.truthy(result.stdout); +}); + +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)'; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return level 1 if `TEAMCITY_VERSION` is in env and is >= 9.1', t => { + process.env.TEAMCITY_VERSION = '9.1.0 (build 32523)'; + const result = importFresh('.'); + t.is(result.stdout.level, 1); +}); + +test('support rxvt', t => { + process.env = {TERM: 'rxvt'}; + const result = importFresh('.'); + t.is(result.stdout.level, 1); +}); + +test('prefer level 2/xterm over COLORTERM', t => { + process.env = {COLORTERM: '1', TERM: 'xterm-256color'}; + const result = importFresh('.'); + t.is(result.stdout.level, 2); +}); + +test('support screen-256color', t => { + process.env = {TERM: 'screen-256color'}; + const result = importFresh('.'); + t.is(result.stdout.level, 2); +}); + +test('support putty-256color', t => { + process.env = {TERM: 'putty-256color'}; + const result = importFresh('.'); + t.is(result.stdout.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.stdout.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.stdout.level, 2); +}); + +test('return level 1 if on Windows earlier than 10 build 10586', 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.stdout.level, 1); +}); + +test('return level 2 if on Windows 10 build 10586 or later', 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.stdout.level, 2); +}); + +test('return level 3 if on Windows 10 build 14931 or later', t => { + Object.defineProperty(process, 'platform', { + value: 'win32' + }); + Object.defineProperty(process.versions, 'node', { + value: '8.0.0' + }); + os.release = () => '10.0.14931'; + const result = importFresh('.'); + t.is(result.stdout.level, 3); +}); + +test('return level 2 when FORCE_COLOR is set when not TTY in xterm256', t => { + process.stdout.isTTY = false; + process.env.FORCE_COLOR = true; + process.env.TERM = 'xterm-256color'; + const result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 2); +}); + +test('supports setting a color level using FORCE_COLOR', t => { + let result; + process.env.FORCE_COLOR = '1'; + result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 1); + + process.env.FORCE_COLOR = '2'; + result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 2); + + process.env.FORCE_COLOR = '3'; + result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 3); + + process.env.FORCE_COLOR = '0'; + result = importFresh('.'); + t.false(result.stdout); +}); + +test('FORCE_COLOR maxes out at a value of 3', t => { + process.env.FORCE_COLOR = '4'; + const result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 3); +}); + +test('FORCE_COLOR works when set via command line (all values are strings)', t => { + let result; + process.env.FORCE_COLOR = 'true'; + result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 1); + + process.stdout.isTTY = false; + process.env.FORCE_COLOR = 'true'; + process.env.TERM = 'xterm-256color'; + result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 2); + + process.env.FORCE_COLOR = 'false'; + result = importFresh('.'); + t.false(result.stdout); +}); + +test('return false when `TERM` is set to dumb', t => { + process.env.TERM = 'dumb'; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return false when `TERM` is set to dumb when `TERM_PROGRAM` is set', t => { + process.env.TERM = 'dumb'; + process.env.TERM_PROGRAM = 'Apple_Terminal'; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return false when `TERM` is set to dumb when run on Windows', t => { + Object.defineProperty(process, 'platform', { + value: 'win32' + }); + Object.defineProperty(process.versions, 'node', { + value: '10.13.0' + }); + os.release = () => '10.0.14931'; + process.env.TERM = 'dumb'; + const result = importFresh('.'); + t.false(result.stdout); +}); + +test('return level 1 when `TERM` is set to dumb when `FORCE_COLOR` is set', t => { + process.env.FORCE_COLOR = '1'; + process.env.TERM = 'dumb'; + const result = importFresh('.'); + t.truthy(result.stdout); + t.is(result.stdout.level, 1); +}); diff --git a/v4.4.0.tar.gz b/v4.4.0.tar.gz new file mode 100644 index 0000000..07b021f Binary files /dev/null and b/v4.4.0.tar.gz differ