From 0d2144904b9b5769076106aa67583273e160f801 Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 30 Jan 2017 04:10:02 -0500 Subject: [PATCH 1/3] check parent builder object for enabled status (#142) --- index.js | 14 +++++++++++++- test.js | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 00bd366..ab458f7 100644 --- a/index.js +++ b/index.js @@ -36,8 +36,20 @@ function build(_styles) { return applyStyle.apply(builder, arguments); }; + var self = this; + builder._styles = _styles; - builder.enabled = this.enabled; + + Object.defineProperty(builder, 'enabled', { + enumerable: true, + get: function () { + return self.enabled; + }, + set: function (v) { + self.enabled = v; + } + }); + // __proto__ is used because we must return a function, but there is // no way to create a function with a different prototype. /* eslint-disable no-proto */ diff --git a/test.js b/test.js index 9dddc2f..9805f95 100644 --- a/test.js +++ b/test.js @@ -138,6 +138,28 @@ describe('chalk.enabled', function () { assert.equal(chalk.red('foo'), 'foo'); chalk.enabled = true; }); + + it('should enable/disable colors based on overall chalk enabled property, not individual instances', function () { + chalk.enabled = true; + var red = chalk.red; + assert.equal(red.enabled, true); + chalk.enabled = false; + assert.equal(red.enabled, chalk.enabled); + chalk.enabled = true; + }); + + it('should propagate enable/disable changes from child colors', function () { + chalk.enabled = true; + var red = chalk.red; + assert.equal(red.enabled, true); + assert.equal(chalk.enabled, true); + red.enabled = false; + assert.equal(red.enabled, false); + assert.equal(chalk.enabled, false); + chalk.enabled = true; + assert.equal(red.enabled, true); + assert.equal(chalk.enabled, true); + }); }); describe('chalk.constructor', function () { From 9b60021fa605a6ebf62fbfd42d02c45597b10e6e Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 21 May 2017 23:28:38 +0700 Subject: [PATCH 2/3] Drop support for Node.js 0.10 and 0.12 --- .editorconfig | 2 +- .gitattributes | 1 + .travis.yml | 2 -- example.js | 4 ++-- package.json | 8 ++++---- test.js | 14 +++++++------- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.editorconfig b/.editorconfig index 98a761d..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,*.yml}] +[*.yml] indent_style = space indent_size = 2 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/.travis.yml b/.travis.yml index ed76b65..f3a8e90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,4 @@ language: node_js node_js: - '6' - '4' - - '0.12' - - '0.10' after_success: npm run coveralls diff --git a/example.js b/example.js index 3b23690..e2bf751 100644 --- a/example.js +++ b/example.js @@ -1,7 +1,7 @@ 'use strict'; -const chalk = require('./'); +const chalk = require('.'); -// generates screenshot +// Generates screenshot for (const key of Object.keys(chalk.styles)) { let ret = key; diff --git a/package.json b/package.json index 49b9ec5..7008e0f 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "JD Ballard (github.com/qix-)" ], "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && nyc mocha", @@ -50,11 +50,11 @@ }, "devDependencies": { "coveralls": "^2.11.2", + "import-fresh": "^2.0.0", "matcha": "^0.7.0", "mocha": "*", - "nyc": "^6.1.1", - "require-uncached": "^1.0.2", - "resolve-from": "^2.0.0", + "nyc": "^10.3.2", + "resolve-from": "^3.0.0", "semver": "^5.1.0", "xo": "^0.16.0" }, diff --git a/test.js b/test.js index 9805f95..b802684 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,9 @@ 'use strict'; var assert = require('assert'); -var requireUncached = require('require-uncached'); +var importFresh = require('import-fresh'); var resolveFrom = require('resolve-from'); var semver = require('semver'); -var chalk = require('./'); +var chalk = require('.'); describe('chalk', function () { it('should style string', function () { @@ -103,31 +103,31 @@ describe('chalk on windows', function () { it('should replace blue foreground color in cmd.exe', function () { process.env.TERM = 'dumb'; - var chalkCtx = requireUncached('./'); + var chalkCtx = importFresh('.'); assert.equal(chalkCtx.blue('foo'), '\u001b[94mfoo\u001b[39m'); }); it('shouldn\'t replace blue foreground color in xterm based terminals', function () { process.env.TERM = 'xterm-256color'; - var chalkCtx = requireUncached('./'); + var chalkCtx = importFresh('.'); assert.equal(chalkCtx.blue('foo'), '\u001b[34mfoo\u001b[39m'); }); it('should not apply dimmed styling on gray strings, see https://github.com/chalk/chalk/issues/58', function () { process.env.TERM = 'dumb'; - var chalkCtx = requireUncached('./'); + var chalkCtx = importFresh('.'); assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90mfoo\u001b[22m\u001b[39m'); }); it('should apply dimmed styling on xterm compatible terminals', function () { process.env.TERM = 'xterm'; - var chalkCtx = requireUncached('./'); + var chalkCtx = importFresh('.'); assert.equal(chalkCtx.gray.dim('foo'), '\u001b[90m\u001b[2mfoo\u001b[22m\u001b[39m'); }); it('should apply dimmed styling on strings of other colors', function () { process.env.TERM = 'dumb'; - var chalkCtx = requireUncached('./'); + var chalkCtx = importFresh('.'); assert.equal(chalkCtx.blue.dim('foo'), '\u001b[94m\u001b[2mfoo\u001b[22m\u001b[39m'); }); }); From dbae68d623270e86300b9e066bf960b42961b820 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Wed, 31 May 2017 11:55:22 +0200 Subject: [PATCH 3/3] Update dependent package count in the readme (#154) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c80946b..3785043 100644 --- a/readme.md +++ b/readme.md @@ -27,7 +27,7 @@ - Clean and focused - Auto-detects color support - Actively maintained -- [Used by ~10,000 modules](https://www.npmjs.com/browse/depended/chalk) as of August 2nd, 2016 +- [Used by ~16,000 modules](https://www.npmjs.com/browse/depended/chalk) as of May 31st, 2017 ## Install