Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚦 Replacing chalk with picocolors #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 35 additions & 35 deletions package-lock.json

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

18 changes: 15 additions & 3 deletions packages/koa-signal/package-lock.json

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

4 changes: 2 additions & 2 deletions packages/koa-signal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
}
},
"dependencies": {
"chalk": "^2.4.1",
"json-stringify-safe": "^5.0.1"
"json-stringify-safe": "^5.0.1",
"picocolors": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/koa-signal/src/components/error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk'
import pc from 'picocolors'

/* Config and then passed Koa ctx & msg */
export default (config = {}) => (ctx, error = {}) => {
Expand All @@ -18,6 +18,6 @@ export default (config = {}) => (ctx, error = {}) => {
: tail

return displayStackTrace
? [ head, ...stack.map(it => chalk[color](it)).map(i => i.replace(/^/, '\n')) ]
? [ head, ...stack.map(it => pc[color](it)).map(i => i.replace(/^/, '\n')) ]
: head
}
2 changes: 1 addition & 1 deletion packages/koa-signal/src/components/message.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold } from 'chalk'
import { bold } from 'picocolors'
import format from '../helper/format'

const isObject = obj => obj === Object(obj)
Expand Down
2 changes: 1 addition & 1 deletion packages/koa-signal/src/components/summary.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bold, red } from 'chalk'
import { bold, red } from 'picocolors'

import format from '../helper/format'
import flatten from '../helper/flatten'
Expand Down
10 changes: 5 additions & 5 deletions packages/koa-signal/src/helper/format.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk'
import pc from 'picocolors'

export default (config, text) => {
if (!text) return
Expand All @@ -13,9 +13,9 @@ export default (config, text) => {
const padF = alignment === 'left' ? 'padEnd' : 'padStart'
const displayText = minimumWidth ? text[padF](minimumWidth) : text

const chalkF = Array.isArray(color)
? color.reduce((acc, it) => acc[it], chalk)
: chalk[color] || (i => i)
const colorF = Array.isArray(color)
? color.reduce((acc, it) => (msg) => acc(pc[it](msg)), pc.reset)
: pc[color] || (i => i)

return chalkF(displayFormat.replace('%s', displayText))
return colorF(displayFormat.replace('%s', displayText))
}
6 changes: 3 additions & 3 deletions packages/koa-signal/src/helper/text-modifier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk'
import pc from 'picocolors'

export default (config = {}, text) => [
config.uppercase && ((s = '') => s.toUpperCase()),
config.underline && ((s = '') => chalk.underline(s)),
config.italic && ((s = '') => chalk.italic(s))
config.underline && ((s = '') => pc.underline(s)),
config.italic && ((s = '') => pc.italic(s))
].reduce((acc, it) => it ? it(acc) : acc, text)
4 changes: 2 additions & 2 deletions packages/koa-signal/src/koa-signal.defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

"trace": {
"badge": "⚡️",
"labelColor": ["blueBright"],
"labelColor": ["blue"],
"format": ["level", "id", "fileName", "timeDiffInit", "timeDiffScope", "just:-", "scope", "message"]
},

Expand Down Expand Up @@ -134,7 +134,7 @@
},

"timeDiffScope": {
"color": [ "blueBright" ],
"color": [ "blue" ],
"defaultReturn": "0ms",
"minimumWidth": 8,
"alignment": "right"
Expand Down
2 changes: 1 addition & 1 deletion packages/koa-signal/src/koa-signal.print-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { dim } from 'chalk'
import { dim } from 'picocolors'
import Signal from './koa-signal.js'
const signal = new Signal({ levels: {json: { format: [ 'json' ] }, rawJson: { format: ['raw-json']}}})

Expand Down