From 625a2857722fb86cfe98f22c9c12888238e36f51 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 30 Jul 2021 17:30:19 +0200 Subject: [PATCH] Add `types` field to package.json Fixes #500 --- examples/rainbow.js | 2 +- package.json | 14 +++++----- index.d.ts => source/index.d.ts | 0 source/index.js | 22 ++++++++-------- index.test-d.ts => source/index.test-d.ts | 0 source/templates.js | 2 +- test/chalk.js | 6 ++--- test/level.js | 2 +- test/template-literal.js | 32 +++++++++++------------ 9 files changed, 41 insertions(+), 39 deletions(-) rename index.d.ts => source/index.d.ts (100%) rename index.test-d.ts => source/index.test-d.ts (100%) diff --git a/examples/rainbow.js b/examples/rainbow.js index 9ea1d72..3501dab 100644 --- a/examples/rainbow.js +++ b/examples/rainbow.js @@ -1,7 +1,7 @@ -import chalk from '../source/index.js'; import convertColor from 'color-convert'; import updateLog from 'log-update'; import delay from 'yoctodelay'; +import chalk from '../source/index.js'; const ignoreChars = /[^!-~]/g; diff --git a/package.json b/package.json index a205ed7..3ad50b2 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "files": [ "source", - "index.d.ts" + "!source/index.test-d.ts" ], "keywords": [ "color", @@ -43,20 +43,22 @@ ], "dependencies": { "ansi-styles": "^6.1.0", - "supports-color": "^9.0.0" + "supports-color": "^9.0.2" }, "devDependencies": { "ava": "^3.15.0", "color-convert": "^2.0.1", - "coveralls": "^3.1.0", - "execa": "^5.0.0", + "coveralls": "^3.1.1", + "execa": "^5.1.1", "log-update": "^4.0.0", "matcha": "^0.7.0", "nyc": "^15.1.0", - "tsd": "^0.14.0", - "xo": "^0.39.1", + "tsd": "^0.17.0", + "typescript": "^4.3.5", + "xo": "^0.42.0", "yoctodelay": "^1.2.0" }, + "types": "./source/index.d.ts", "xo": { "rules": { "unicorn/prefer-string-slice": "off", diff --git a/index.d.ts b/source/index.d.ts similarity index 100% rename from index.d.ts rename to source/index.d.ts diff --git a/source/index.js b/source/index.js index 8a3785b..88c7528 100644 --- a/source/index.js +++ b/source/index.js @@ -2,7 +2,7 @@ import ansiStyles from 'ansi-styles'; import supportsColor from 'supports-color'; import { stringReplaceAll, - stringEncaseCRLFWithFirstIndex + stringEncaseCRLFWithFirstIndex, } from './util.js'; import template from './templates.js'; @@ -18,7 +18,7 @@ const levelMapping = [ 'ansi', 'ansi', 'ansi256', - 'ansi16m' + 'ansi16m', ]; const styles = Object.create(null); @@ -66,7 +66,7 @@ for (const [styleName, style] of Object.entries(ansiStyles)) { const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]); Object.defineProperty(this, styleName, {value: builder}); return builder; - } + }, }; } @@ -75,7 +75,7 @@ styles.visible = { const builder = createBuilder(this, this[STYLER], true); Object.defineProperty(this, 'visible', {value: builder}); return builder; - } + }, }; const getModelAnsi = (model, level, type, ...arguments_) => { @@ -108,7 +108,7 @@ for (const model of usedModels) { const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansiStyles.color.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; - } + }, }; const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); @@ -119,7 +119,7 @@ for (const model of usedModels) { const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansiStyles.bgColor.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; - } + }, }; } @@ -132,8 +132,8 @@ const proto = Object.defineProperties(() => {}, { }, set(level) { this[GENERATOR].level = level; - } - } + }, + }, }); const createStyler = (open, close, parent) => { @@ -152,7 +152,7 @@ const createStyler = (open, close, parent) => { close, openAll, closeAll, - parent + parent, }; }; @@ -228,7 +228,7 @@ const chalkTag = (chalk, ...strings) => { for (let i = 1; i < firstString.length; i++) { parts.push( String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), - String(firstString.raw[i]) + String(firstString.raw[i]), ); } @@ -242,7 +242,7 @@ export const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : export { stdoutColor as supportsColor, - stderrColor as supportsColorStderr + stderrColor as supportsColorStderr, }; export default chalk; diff --git a/index.test-d.ts b/source/index.test-d.ts similarity index 100% rename from index.test-d.ts rename to source/index.test-d.ts diff --git a/source/templates.js b/source/templates.js index 1a2f95c..590223f 100644 --- a/source/templates.js +++ b/source/templates.js @@ -13,7 +13,7 @@ const ESCAPES = new Map([ ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], - ['a', '\u0007'] + ['a', '\u0007'], ]); function unescape(c) { diff --git a/test/chalk.js b/test/chalk.js index af43558..32b57c6 100644 --- a/test/chalk.js +++ b/test/chalk.js @@ -20,7 +20,7 @@ test('support automatic casting to string', t => { t.is(chalk(123), '123'); t.is(chalk.bold(['foo', 'bar']), '\u001B[1mfoo,bar\u001B[22m'); - t.is(chalk.green(98765), '\u001B[32m98765\u001B[39m'); + t.is(chalk.green(98_765), '\u001B[32m98765\u001B[39m'); }); test('style string', t => { @@ -37,14 +37,14 @@ test('support applying multiple styles at once', t => { test('support nesting styles', t => { t.is( chalk.red('foo' + chalk.underline.bgBlue('bar') + '!'), - '\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m' + '\u001B[31mfoo\u001B[4m\u001B[44mbar\u001B[49m\u001B[24m!\u001B[39m', ); }); test('support nesting styles of the same type (color, underline, bg)', t => { t.is( chalk.red('a' + chalk.yellow('b' + chalk.green('c') + 'b') + 'c'), - '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m' + '\u001B[31ma\u001B[33mb\u001B[32mc\u001B[39m\u001B[31m\u001B[33mb\u001B[39m\u001B[31mc\u001B[39m', ); }); diff --git a/test/level.js b/test/level.js index 4aab162..5fed269 100644 --- a/test/level.js +++ b/test/level.js @@ -1,4 +1,4 @@ -import {fileURLToPath} from 'url'; +import {fileURLToPath} from 'node:url'; import test from 'ava'; import execa from 'execa'; import chalk from '../source/index.js'; diff --git a/test/template-literal.js b/test/template-literal.js index e8d5950..5e737a5 100644 --- a/test/template-literal.js +++ b/test/template-literal.js @@ -42,22 +42,22 @@ test('correctly perform nested template substitutions', t => { instance.strikethrough.cyanBright.bgBlack('Works with ' + instance.reset.bold('numbers') + ' ' + instance.bold.red(1))); t.is(chalk.bold`Also works on the shared {bgBlue chalk} object`, - '\u001B[1mAlso works on the shared \u001B[1m' + - '\u001B[44mchalk\u001B[49m\u001B[22m' + - '\u001B[1m object\u001B[22m'); + '\u001B[1mAlso works on the shared \u001B[1m' + + '\u001B[44mchalk\u001B[49m\u001B[22m' + + '\u001B[1m object\u001B[22m'); }); test('correctly parse and evaluate color-convert functions', t => { const instance = new Chalk({level: 3}); t.is(instance`{bold.rgb(144,10,178).inverse Hello, {~inverse there!}}`, - '\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, ' + - '\u001B[27m\u001B[39m\u001B[22m\u001B[1m' + - '\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m'); + '\u001B[1m\u001B[38;2;144;10;178m\u001B[7mHello, ' + + '\u001B[27m\u001B[39m\u001B[22m\u001B[1m' + + '\u001B[38;2;144;10;178mthere!\u001B[39m\u001B[22m'); t.is(instance`{bold.bgRgb(144,10,178).inverse Hello, {~inverse there!}}`, - '\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, ' + - '\u001B[27m\u001B[49m\u001B[22m\u001B[1m' + - '\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m'); + '\u001B[1m\u001B[48;2;144;10;178m\u001B[7mHello, ' + + '\u001B[27m\u001B[49m\u001B[22m\u001B[1m' + + '\u001B[48;2;144;10;178mthere!\u001B[49m\u001B[22m'); }); test('properly handle escapes', t => { @@ -103,13 +103,13 @@ test('properly style multiline color blocks', t => { } {underline I hope you enjoy }`, - '\u001B[1m\u001B[22m\n' + - '\u001B[1m\t\t\tHello! This is a\u001B[22m\n' + - '\u001B[1m\t\t\tmultiline block!\u001B[22m\n' + - '\u001B[1m\t\t\t:)\u001B[22m\n' + - '\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n' + - '\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n' + - '\u001B[4m\t\t\u001B[24m' + '\u001B[1m\u001B[22m\n' + + '\u001B[1m\t\t\tHello! This is a\u001B[22m\n' + + '\u001B[1m\t\t\tmultiline block!\u001B[22m\n' + + '\u001B[1m\t\t\t:)\u001B[22m\n' + + '\u001B[1m\t\t\u001B[22m \u001B[4m\u001B[24m\n' + + '\u001B[4m\t\t\tI hope you enjoy\u001B[24m\n' + + '\u001B[4m\t\t\u001B[24m', ); });