Skip to content

Commit

Permalink
perf: replace chalk with nanocolors (2x faster)
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Sep 22, 2021
1 parent 21ea22c commit 2ac4096
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
33 changes: 29 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 3 additions & 7 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -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...')
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import colors from 'chalk'
import colors from 'nanocolors'

export class PrettyError extends Error {
constructor(message: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
7 changes: 4 additions & 3 deletions src/log.ts
Original file line number Diff line number Diff line change
@@ -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<keyof NanoColors, 'isColorSupported'>

const colorMap = new Map<LogLevel, typeof Color>([
const colorMap = new Map<LogLevel, Colors>([
['info', 'yellow'],
['success', 'green'],
['error', 'red']
Expand Down

0 comments on commit 2ac4096

Please sign in to comment.