From d7000503cf24771801fae003995d2299d8e8cbc1 Mon Sep 17 00:00:00 2001 From: biodiscus Date: Sun, 14 Jul 2024 17:37:53 +0200 Subject: [PATCH] chore: remove DEPRECATED named import syntax, use new syntax since v2 --- CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ README.md | 35 ++++++++++++++--------------------- README.npm.md | 32 +++++++++++++++----------------- package.json | 4 ++-- package.npm.json | 21 +++++---------------- test/package.test.js | 12 ++---------- test/package/cjs/test.cjs | 14 +++----------- test/package/esm/test.mjs | 14 +++----------- 8 files changed, 78 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ad7023..a05ffa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Change log +## 3.3.0 (2024-07-14) + +- feat(BREAKING CHANGE): remove `old` named import DEPRECATED in `v2.0.0` (2023-11-03). + If you update the package from `v1.x` to `v3.3.0` then check your code:\ + ESM + ```diff + - import { red } from 'ansis/colors'; + + import { red } from 'ansis'; + ``` + CJS + ```diff + - const { red } = require('ansis/colors'); + + const { red } = require('ansis'); + ``` +- chore: cleanup/optimize `package.json` for npm package + ## 3.2.1 (2024-07-12) - chore: reduce unpacked size by ~ 1 KB @@ -38,6 +54,8 @@ - test: add more tests - docs: improve readme + + ## 3.0.0 (2024-03-29) - feat: add detection of color spaces support: TrueColor, 256 colors, 16 colors, no color @@ -61,6 +79,22 @@ In the new major version `3.x` are removed unused styles and methods. Drop supports for Node <= `14`. Minimal supported version is `15.0.0` (Released 2020-10-20). In the theory the `v3` can works with Node`12`, but we can't test it. +### Deleted DEPRECATED named import syntax (since `v3.3.0`) + +ESM + +```diff +- import { red } from 'ansis/colors'; ++ import { red } from 'ansis'; +``` + +CJS + +```diff +- const { red } = require('ansis/colors'); ++ const { red } = require('ansis'); +``` + ### Deleted styles The `not widely supported` styles are deleted: diff --git a/README.md b/README.md index 0696194..b83676a 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,15 @@ hex('#E0115F').bold.underline('TrueColor!') - Quick response to issues. - Long term support. -## πŸ† Compare & Benchmark +## βš–οΈ Similar packages -See the [features comparison](#compare) and [benchmarks](#benchmark) of most popular terminal colors libraries:\ -[ansis][ansis], [chalk][chalk], [kleur][kleur], [kolorist][kolorist], [colors.js][colors.js], [colorette][colorette], [picocolors][picocolors], [ansi-colors][ansi-colors], [cli-color][cli-color], [colors-cli][colors-cli]. +Most popular ANSI libraries for Node.js: + +[chalk][chalk], [kleur][kleur], [kolorist][kolorist], [colors.js][colors.js], [colorette][colorette], [picocolors][picocolors], [ansi-colors][ansi-colors], [cli-color][cli-color], [colors-cli][colors-cli] + +- βœ… [Compare features](#compare) + +- πŸ“Š [Benchmarks](#benchmark) @@ -97,8 +102,8 @@ See the [features comparison](#compare) and [benchmarks](#benchmark) of most pop > #### ⚠️ Warning > -> The `v3` has the **BREAKING CHANGES** (removed not widely supported styles and deprecated methods).\ -> For details see the [changelog](https://github.com/webdiscus/ansis/blob/master/CHANGELOG.md). +> The `v3` has the **BREAKING CHANGES** (removed not widely supported styles and DEPRECATIONS).\ +> For details see the [changelog](https://github.com/webdiscus/ansis/blob/master/CHANGELOG.md#v3-0-0). ## ❓Question / Feature Request / Bug @@ -696,8 +701,9 @@ npm run compare > The size of distributed code that will be loaded via `require` or `import` into your app. It's not a package size. > > **Named import**\ +> ESM\ > `import { red, green, blue } from 'lib';`\ -> or\ +> CJS\ > `const { red, green, blue } = require('lib');` > > **Naming colors** @@ -744,7 +750,7 @@ npm run demo -## Benchmark +## Benchmarks To measure performance is used [benchmark.js](https://github.com/bestiejs/benchmark.js). @@ -761,7 +767,7 @@ To measure performance is used [benchmark.js](https://github.com/bestiejs/benchm > > The real performance results of `chalk` and `ansis` in this test are very close. -### Run benchmark +### Run benchmarks ```bash git clone https://github.com/webdiscus/ansis.git @@ -945,19 +951,6 @@ c.hex('#FBA')('foo'); `npm run test` will run the unit and integration tests.\ `npm run test:coverage` will run the tests with coverage. -## Also See - -Most popular ANSI libraries for `Node.js`: - -- [colors.js][colors.js] -- [colorette][colorette] -- [picocolors][picocolors] -- [cli-color][cli-color] -- [colors-cli][colors-cli] -- [ansi-colors][ansi-colors] -- [kleur][kleur] -- [chalk][chalk] - ## License [ISC](https://github.com/webdiscus/ansis/blob/master/LICENSE) diff --git a/README.npm.md b/README.npm.md index 6194957..f4b318e 100644 --- a/README.npm.md +++ b/README.npm.md @@ -1,6 +1,6 @@

- ansis
+
ANSI Styling

@@ -14,6 +14,10 @@ Colorize terminal with ANSI colors & styles, smaller and faster alternative to C πŸš€ [Install and Quick Start](https://github.com/webdiscus/ansis#install) +βœ… [Compare features](https://github.com/webdiscus/ansis#compare) with similar packages + +πŸ“Š [Benchmarks](https://github.com/webdiscus/ansis#benchmark) + πŸ“– [Read full docs on GitHub](https://github.com/webdiscus/ansis) ## Usage @@ -21,26 +25,20 @@ Colorize terminal with ANSI colors & styles, smaller and faster alternative to C ```js import ansis, { red, green, black, ansi256, hex } from 'ansis'; -ansis.cyan('path/to/file') -green('Succeful!') -red`Error!` -black.bgYellow`Warning!` +ansis.cyan('file') +green('Ok') +red`Error` +black.bgYellow`Warning` ansi256(214)`Orange` -hex('#E0115F').bold.underline('TrueColor') +hex('#E0115F').bold('TrueColor') ``` -## πŸ† Compare & Benchmark - -See the [features comparison](https://github.com/webdiscus/ansis#compare) and [benchmarks](https://github.com/webdiscus/ansis#benchmark) of most popular terminal colors libraries:\ -`ansis` `chalk` `kleur` `kolorist` `colors.js` `colorette` `picocolors` `ansi-colors` `cli-color` `colors-cli`. - -## πŸ’‘ Highlights +## Highlights ![ANSI demo](https://github.com/webdiscus/ansis/raw/master/docs/img/ansis-demo.png) -- Supports ESM, CommonJS, TypeScript, Bun, Deno, Next.JS -- [Standard API](https://github.com/webdiscus/ansis#base-colors), drop-in replacement for Chalk -- Default and named import: `import ansis, { red, bold, hex } from 'ansis'` +- Supports ESM, CJS, TypeScript, Bun, Deno, Next.JS +- Named import: `import ansis, { red, bold, hex } from 'ansis'` - Chained syntax: `red.bold.underline('text')` - Nested template strings: ``` red`RED ${green`GREEN`} RED` ``` - ANSI styles: `dim` **`bold`** _`italic`_ `underline` `strikethrough` @@ -48,10 +46,10 @@ See the [features comparison](https://github.com/webdiscus/ansis#compare) and [b - ANSI 256 colors: ``` fg(56)`violet` ``` ``` bg(208)`orange` ``` - TrueColor: ``` rgb(224, 17, 95)`Ruby` ``` ``` hex('#96C')`Amethyst` ``` - Color fallback: TrueColor β†’ 256 colors β†’ 16 colors β†’ no colors -- Raw ANSI codes: ``` `foo ${red.open}red{red.close} bar` ``` +- Raw ANSI codes: ``` `foo ${red.open}bar{red.close} foo` ``` - Strip ANSI codes: `ansis.strip()` - Detect color support: `ansis.isSupported()` - Supports CLI: `NO_COLOR` `FORCE_COLOR` `--no-color` `--color` - Correct style break at the `end of line` when used `\n` - Doesn't extend `String.prototype` -- Zero dependencies +- No dependencies diff --git a/package.json b/package.json index 28c1f8a..5bbe62f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ansis", - "version": "3.2.1", - "description": "Colorize terminal with ANSI colors & styles", + "version": "3.3.0", + "description": "Colorize terminal output with ANSI colors & styles", "keywords": [ "ansi", "colour", diff --git a/package.npm.json b/package.npm.json index a1ddeb2..f64ddb6 100644 --- a/package.npm.json +++ b/package.npm.json @@ -1,21 +1,19 @@ { "name": "ansis", - "version": "3.2.1", - "description": "Colorize terminal with ANSI colors & styles", + "version": "3.3.0", + "description": "Colorize terminal output with ANSI colors & styles", "keywords": [ "ansi", "color", "truecolor", - "ansi256", + "console", "terminal", "cli", "chalk" ], "license": "ISC", "author": "webdiscus", - "homepage": "https://github.com/webdiscus/ansis", "repository": "webdiscus/ansis", - "sideEffects": false, "main": "./index.js", "types": "./index.d.ts", "exports": { @@ -23,22 +21,13 @@ "types": "./index.d.ts", "require": "./index.js", "import": "./index.mjs" - }, - "./colors": { - "types": "./index.d.ts", - "require": "./index.js", - "import": "./index.mjs" } }, + "sideEffects": false, "engines": { "node": ">=15" }, "files": [ - "index.d.ts", - "index.js", - "index.mjs", - "package.json", - "LICENSE", - "README.md" + "index.*" ] } diff --git a/test/package.test.js b/test/package.test.js index 29b2220..c1f92db 100644 --- a/test/package.test.js +++ b/test/package.test.js @@ -21,11 +21,7 @@ describe('Usage `ansis` npm package', () => { '\x1b[38;2;255;117;209mextend: ansis2.pink\x1b[39m\n' + '\x1b[3m\x1b[38;2;255;171;64mextend: ansis2.italic.orange\x1b[39m\x1b[23m\n' + 'colored: \x1b[32mgreen text\x1b[39m\n' + - 'striped: green text\n' + - '--- OLD named import: \x1b[33mconst { magenta, cyan, blue } = require(\'ansis/colors\');\x1b[39m\n' + - '\x1b[35mmagenta\x1b[39m\n' + - '\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' + - '\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m'; + 'striped: green text'; expect(esc(received)).toEqual(esc(expected)); }); @@ -45,11 +41,7 @@ describe('Usage `ansis` npm package', () => { '\x1b[38;2;255;117;209mextend: ansis2.pink\x1b[39m\n' + '\x1b[3m\x1b[38;2;255;171;64mextend: ansis2.italic.orange\x1b[39m\x1b[23m\n' + 'colored: \x1b[32mgreen text\x1b[39m\n' + - 'striped: green text\n' + - '--- OLD named import: \x1b[33mimport { magenta, cyan, blue } from \'ansis/colors\';\x1b[39m\n' + - '\x1b[35mmagenta\x1b[39m\n' + - '\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' + - '\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m'; + 'striped: green text'; expect(esc(received)).toEqual(esc(expected)); }); }); \ No newline at end of file diff --git a/test/package/cjs/test.cjs b/test/package/cjs/test.cjs index 049071e..e2b4690 100644 --- a/test/package/cjs/test.cjs +++ b/test/package/cjs/test.cjs @@ -1,10 +1,7 @@ const ansis = require('ansis'); -// test new named import -const { Ansis, red, green, yellow, hex } = require('ansis'); - -// test old named import -const { magenta, cyan, blue } = require('ansis/colors'); +// test named import +const { Ansis, red, green, hex } = require('ansis'); const log = console.log; @@ -41,9 +38,4 @@ log(ansis2.italic.orange('extend: ansis2.italic.orange')); // strip const greenText = green`green text`; log('colored: ', greenText); -log('striped: ', ansis.strip(greenText)); - -log(`--- OLD named import: ${yellow`const { magenta, cyan, blue } = require('ansis/colors');`}`); -log(magenta`magenta`); -log(cyan.bold`cyan bold`); -log(blue.italic`blue italic`); \ No newline at end of file +log('striped: ', ansis.strip(greenText)); \ No newline at end of file diff --git a/test/package/esm/test.mjs b/test/package/esm/test.mjs index a90618c..a3c1a51 100644 --- a/test/package/esm/test.mjs +++ b/test/package/esm/test.mjs @@ -1,8 +1,5 @@ -// test new named import -import ansis, { Ansis, red, green, yellow, hex } from 'ansis'; - -// test old named import -import { magenta, cyan, blue } from 'ansis/colors'; +// test named import +import ansis, { Ansis, red, green, hex } from 'ansis'; const log = console.log; @@ -39,9 +36,4 @@ log(ansis2.italic.orange('extend: ansis2.italic.orange')); // strip const greenText = green`green text`; log('colored: ', greenText); -log('striped: ', ansis.strip(greenText)); - -log(`--- OLD named import: ${yellow`import { magenta, cyan, blue } from 'ansis/colors';`}`); -log(magenta`magenta`); -log(cyan.bold`cyan bold`); -log(blue.italic`blue italic`); \ No newline at end of file +log('striped: ', ansis.strip(greenText)); \ No newline at end of file