From 2ac40969f746e7c54df164e3721a33e4353d63d3 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Wed, 22 Sep 2021 17:08:23 +0200 Subject: [PATCH] perf: replace chalk with nanocolors (2x faster) --- package-lock.json | 33 +++++++++++++++++++++++++++++---- package.json | 2 +- scripts/release.js | 10 +++------- src/errors.ts | 2 +- src/index.ts | 2 +- src/log.ts | 7 ++++--- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec3e1f2..8f5e2da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,8 @@ "license": "MIT", "dependencies": { "cac": "^6.7.3", - "chalk": "^4.1.2", "chokidar": "^3.5.2", + "nanocolors": "^0.1.6", "sass": "^1.42.1", "vite": "^2.5.10", "vite-plugin-vue2": "^1.8.2", @@ -1534,6 +1534,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -2462,6 +2463,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -2545,6 +2547,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -2555,7 +2558,8 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "node_modules/colorette": { "version": "1.4.0", @@ -3692,6 +3696,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, "engines": { "node": ">=8" } @@ -5380,6 +5385,14 @@ "thenify-all": "^1.0.0" } }, + "node_modules/nanocolors": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/nanocolors/-/nanocolors-0.1.6.tgz", + "integrity": "sha512-2pvTw6vYRaBLGir2xR7MxaJtyWkrn+C53EpW8yPotG+pdAwBvt0Xwk4VJ6VHLY0aLthVZPvDfm9TdZvrvAm5UQ==", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/nanoid": { "version": "3.1.25", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz", @@ -6571,6 +6584,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -8508,6 +8522,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "requires": { "color-convert": "^2.0.1" } @@ -9334,6 +9349,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "requires": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -9399,6 +9415,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "requires": { "color-name": "~1.1.4" } @@ -9406,7 +9423,8 @@ "color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "colorette": { "version": "1.4.0", @@ -10269,7 +10287,8 @@ "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true }, "hash-sum": { "version": "2.0.0", @@ -11577,6 +11596,11 @@ "thenify-all": "^1.0.0" } }, + "nanocolors": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/nanocolors/-/nanocolors-0.1.6.tgz", + "integrity": "sha512-2pvTw6vYRaBLGir2xR7MxaJtyWkrn+C53EpW8yPotG+pdAwBvt0Xwk4VJ6VHLY0aLthVZPvDfm9TdZvrvAm5UQ==" + }, "nanoid": { "version": "3.1.25", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz", @@ -12450,6 +12474,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "requires": { "has-flag": "^4.0.0" } diff --git a/package.json b/package.json index 607bfde..a351260 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ }, "dependencies": { "cac": "^6.7.3", - "chalk": "^4.1.2", "chokidar": "^3.5.2", + "nanocolors": "^0.1.6", "sass": "^1.42.1", "vite": "^2.5.10", "vite-plugin-vue2": "^1.8.2", diff --git a/scripts/release.js b/scripts/release.js index 7cbbdde..9beea1c 100644 --- a/scripts/release.js +++ b/scripts/release.js @@ -1,6 +1,6 @@ const fs = require('fs') const path = require('path') -const chalk = require('chalk') +const colors = require('nanocolors') const semver = require('semver') const { prompt } = require('enquirer') const execa = require('execa') @@ -12,7 +12,7 @@ const versionIncrements = ['patch', 'minor', 'major'] const inc = (i) => semver.inc(currentVersion, i) const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts }) -const step = (msg) => console.log(chalk.cyan(msg)) +const step = (msg) => console.log(colors.cyan(msg)) async function main() { let targetVersion @@ -83,11 +83,7 @@ async function main() { // Publish the package. step('\nPublishing the package...') - await run('npm', [ - 'publish', - '--no-commit-hooks', - '--no-git-tag-version' - ]) + await run('npm', ['publish', '--no-commit-hooks', '--no-git-tag-version']) // Push to GitHub. step('\nPushing to GitHub...') diff --git a/src/errors.ts b/src/errors.ts index de8e0ec..89943af 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -1,4 +1,4 @@ -import colors from 'chalk' +import colors from 'nanocolors' export class PrettyError extends Error { constructor(message: string) { diff --git a/src/index.ts b/src/index.ts index 73d8d37..07a5eae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,12 @@ import { resolve, dirname } from 'path' import { existsSync } from 'fs' +import colors from 'nanocolors' import { build as viteBuild } from 'vite' import { createVuePlugin } from 'vite-plugin-vue2' import { handleError, PrettyError } from './errors' import { debouncePromise } from './utils' import { log } from './log' import { name, version } from '../package.json' -import colors from 'chalk' import type { Awaited } from 'ts-essentials' import type { Options, NormalizedOptions } from './types' diff --git a/src/log.ts b/src/log.ts index 048cca2..f97c5af 100644 --- a/src/log.ts +++ b/src/log.ts @@ -1,10 +1,11 @@ -import colors from 'chalk' +import colors from 'nanocolors' import { name } from '../package.json' -import type { Color } from 'chalk' +import type { Colors as NanoColors } from 'nanocolors' type LogLevel = 'info' | 'success' | 'error' +type Colors = Exclude -const colorMap = new Map([ +const colorMap = new Map([ ['info', 'yellow'], ['success', 'green'], ['error', 'red']