From 655653bb0c88fb05f839d5027f79751449771ec4 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 12 Jul 2019 13:51:07 +0700 Subject: [PATCH] Meta tweaks --- index.d.ts | 2 ++ package.json | 5 ++--- readme.md | 4 ++-- index.js => source/index.js | 5 ++--- templates.js => source/templates.js | 0 {lib => source}/util.js | 2 ++ test/_fixture.js | 2 +- test/chalk.js | 2 +- test/constructor.js | 2 +- test/enabled.js | 2 +- test/instance.js | 2 +- test/level.js | 2 +- test/no-color-support.js | 2 +- test/template-literal.js | 2 +- test/visible.js | 2 +- tsconfig.json | 7 ------- 16 files changed, 19 insertions(+), 24 deletions(-) rename index.js => source/index.js (98%) rename templates.js => source/templates.js (100%) rename {lib => source}/util.js (98%) delete mode 100644 tsconfig.json diff --git a/index.d.ts b/index.d.ts index 0f5d885..9ccc725 100644 --- a/index.d.ts +++ b/index.d.ts @@ -78,6 +78,8 @@ declare namespace chalk { @example ``` + import chalk = require('chalk'); + log(chalk` CPU: {red ${cpu.totalPercent}%} RAM: {green ${ram.used / ram.total * 100}%} diff --git a/package.json b/package.json index 48712eb..764bcbf 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Terminal string styling done right", "license": "MIT", "repository": "chalk/chalk", + "main": "source", "engines": { "node": ">=8" }, @@ -12,8 +13,7 @@ "bench": "matcha benchmark.js" }, "files": [ - "index.js", - "templates.js", + "source", "index.d.ts" ], "keywords": [ @@ -44,7 +44,6 @@ "supports-color": "^6.1.0" }, "devDependencies": { - "@sindresorhus/tsconfig": "^0.3.0", "ava": "^1.4.1", "coveralls": "^3.0.3", "execa": "^1.0.0", diff --git a/readme.md b/readme.md index d403085..d99b712 100644 --- a/readme.md +++ b/readme.md @@ -220,8 +220,8 @@ const miles = 18; const calculateFeet = miles => miles * 5280; console.log(chalk` - There are {bold 5280 feet} in a mile. - In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}. + There are {bold 5280 feet} in a mile. + In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}. `); ``` diff --git a/index.js b/source/index.js similarity index 98% rename from index.js rename to source/index.js index 21d3a83..0519720 100644 --- a/index.js +++ b/source/index.js @@ -1,12 +1,11 @@ 'use strict'; const ansiStyles = require('ansi-styles'); const {stdout: stdoutColor} = require('supports-color'); -const template = require('./templates.js'); - +const template = require('./templates'); const { stringReplaceAll, stringEncaseCRLFWithFirstIndex -} = require('./lib/util'); +} = require('./util'); // `supportsColor.level` → `ansiStyles.color[name]` mapping const levelMapping = [ diff --git a/templates.js b/source/templates.js similarity index 100% rename from templates.js rename to source/templates.js diff --git a/lib/util.js b/source/util.js similarity index 98% rename from lib/util.js rename to source/util.js index 8ce1166..aaf3d79 100644 --- a/lib/util.js +++ b/source/util.js @@ -1,3 +1,5 @@ +'use strict'; + const stringReplaceAll = (string, substring, replacer) => { let index = string.indexOf(substring); if (index === -1) { diff --git a/test/_fixture.js b/test/_fixture.js index 5f1771d..214a86c 100644 --- a/test/_fixture.js +++ b/test/_fixture.js @@ -1,4 +1,4 @@ 'use strict'; -const chalk = require('..'); +const chalk = require('../source'); console.log(chalk.hex('#ff6159')('test')); diff --git a/test/chalk.js b/test/chalk.js index 3f90ba6..92091cb 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -3,7 +3,7 @@ import test from 'ava'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); console.log('TERM:', process.env.TERM || '[none]'); console.log('platform:', process.platform || '[unknown]'); diff --git a/test/constructor.js b/test/constructor.js index 188001a..f4e9ca1 100644 --- a/test/constructor.js +++ b/test/constructor.js @@ -1,6 +1,6 @@ import test from 'ava'; -const chalk = require('..'); +const chalk = require('../source'); test('Chalk.constructor should throw an expected error', t => { const expectedError = t.throws(() => { diff --git a/test/enabled.js b/test/enabled.js index e596621..3d9c55f 100644 --- a/test/enabled.js +++ b/test/enabled.js @@ -3,7 +3,7 @@ import test from 'ava'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); test('don\'t output colors when manually disabled', t => { chalk.enabled = false; diff --git a/test/instance.js b/test/instance.js index e34bea7..8d2c4e1 100644 --- a/test/instance.js +++ b/test/instance.js @@ -3,7 +3,7 @@ import test from 'ava'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); test('create an isolated context where colors can be disabled (by level)', t => { const instance = new chalk.Instance({level: 0, enabled: true}); diff --git a/test/level.js b/test/level.js index 06fdb59..36df016 100644 --- a/test/level.js +++ b/test/level.js @@ -5,7 +5,7 @@ import execa from 'execa'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); test('don\'t output colors when manually disabled', t => { const oldLevel = chalk.level; diff --git a/test/no-color-support.js b/test/no-color-support.js index 90d934d..dae9bda 100644 --- a/test/no-color-support.js +++ b/test/no-color-support.js @@ -8,7 +8,7 @@ require('./_supports-color')(__dirname, { has16m: false }); -const chalk = require('..'); +const chalk = require('../source'); test.failing('colors can be forced by using chalk.enabled', t => { chalk.enabled = true; diff --git a/test/template-literal.js b/test/template-literal.js index ae4a0bc..ece1428 100644 --- a/test/template-literal.js +++ b/test/template-literal.js @@ -4,7 +4,7 @@ import test from 'ava'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); test('return an empty string for an empty literal', t => { const instance = new chalk.Instance(); diff --git a/test/visible.js b/test/visible.js index 01eb087..14ecc3c 100644 --- a/test/visible.js +++ b/test/visible.js @@ -3,7 +3,7 @@ import test from 'ava'; // Spoof supports-color require('./_supports-color')(__dirname); -const chalk = require('..'); +const chalk = require('../source'); test('visible: normal output when enabled', t => { const instance = new chalk.Instance({level: 3, enabled: true}); diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 3d73ee9..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "@sindresorhus/tsconfig", - "compilerOptions": { - "noEmit": true, - "allowJs": true - } -}