From 1328945c28985c1883cee2ba2b19fbb6f95dd57a Mon Sep 17 00:00:00 2001 From: wang_yue111 <648774160@qq.com> Date: Fri, 28 Aug 2020 15:17:06 +0800 Subject: [PATCH] package init --- nodejs-supports-color.spec | 55 ++++++ nodejs-supports-color.yaml | 5 + supports-color-4.4.0.tgz | Bin 0 -> 2875 bytes test.js | 385 +++++++++++++++++++++++++++++++++++++ 4 files changed, 445 insertions(+) create mode 100644 nodejs-supports-color.spec create mode 100644 nodejs-supports-color.yaml create mode 100644 supports-color-4.4.0.tgz create mode 100644 test.js diff --git a/nodejs-supports-color.spec b/nodejs-supports-color.spec new file mode 100644 index 0000000..640cb1a --- /dev/null +++ b/nodejs-supports-color.spec @@ -0,0 +1,55 @@ +%{?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: http://registry.npmjs.org/supports-color/-/supports-color-%{version}.tgz +Source1: https://raw.githubusercontent.com/chalk/supports-color/master/test.js +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 +%setup -q -n package +cp %{SOURCE1} . +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/supports-color-4.4.0.tgz b/supports-color-4.4.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..bc53a454fef052ff4a7ac81e91b063df10579b28 GIT binary patch literal 2875 zcmV-B3&ivviwFP!000006YW}ibK5o&@4wck*t(rc>d2HRzgqX4RF>(OJz4TlbaENz zA&P_~G!)4aq-{-|?|!=gNs*52=}nvTI%AF}B7uEjcLDqsNaVO5oH=Vp>R0FzOC=-``dbVxBFE`-|lp=t@BqKa^I7R#EH?A zKPyKK28!Q*$n$#*U^8%*Z1Vs%MH)q6oQN$q^uu_wMSWK+7Ca27dq>;RI;z!U!i{;9 zWIe|$VQvD~3zjTc3=SkLUh=^4Ar}cHkv?}>Af(1K(^hRUi$cMZFkVr!yKwvu?fcAe z(qw_}2SA3GOds>Wiy4f=c##T8ik)ofa9<8g_6phg^PE~WH(cgqY5WP1?8e@YQYj1O zJYb@vHT0y`XNNm$D&>(9Rl-CJ_&YE_{eJSr!QKDvcgL5ypXc~vtg2mK= z4R0mO2e!HnW3R-uc1!k=R=(mwTpo>eZy-XS6`wxOU!6b{?;=@|k-3aymA}UGY5v;X z-7Cl!%r7+Dkjk~X<BrjNJ@4};Tld>}27V45kFWnb+xy-1`i~8`{&)3#{b~LG5>Gu93`7!hH>v+r zqlF=XP{1L??6;K1tWgg|y_xsm6gt5fRPN4a6%l1rEVx37C=OjFgoa;5Pd3f5*JoGE zhr?$$&o=lB8rk>ZA#|G5wh^-=jRTlDzFsK8Za62K$qiRJ1cQV zuU^udCyq$GFimLd{JP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cEkAaRZV~cZMYiB+G@sbe9ajit4R|=t~Eb?l!72>iMxogZIZm0h+q7_#<-GN3D+u)AyEtM3}w@OYZx$n=6?Jn(`}zrjlPc zt#@wLYL-0Wkw?svk;D{}7VYp8StL#XjZrD24w!RI%+nOSP)9_F5kdt>M8sS^BbeZ1 z*D?qT@*AQV%2CpiMI5H{1rkj(Nj9Ow9mFEZN+Cg{ixIs=1ZNP|&}9??nys811FBCX z^5-CfaK4N5al z^jTP|nF;!it<(YiWJ{%GCVguwzl53~dN8FM1bV)Y;X;6h$S#h#=P~?RNqz*bv4pn@ z783a*GBr3MJ9&~i3c_8>Yl&2l%hzmK=%Wx};?yVn>UmN=3$Az^287e$%85DMl)$8P z)^~_OLWqiScNyJst+MNs{3a!?Qg`lBBgiIl4Qw?wN~SW$BzFPj8?FzbTwkj0cNfh4 zKu$AmB1Gv3xG}Qrb(j#~qdm%@$~rIeKsg|EtyVa&xX_y@7q_U;z{F2DCdW!s(Y2UQ zl?)~AWp&Nja(%vDL+2Q+bV@bWy$dK2H(^VKU(Os1hdRIEJ~#5m4fkJMdebF=GNsep;*8#X%GhY(*MS9wz3&e6sd^d Zp8)35^YlDDPtTuz{tFj+Lqh;80020gqjUfO literal 0 HcmV?d00001 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); +});