Skip to content

Commit 9aea256

Browse files
committed
Memoize chalk creation
1 parent baf47e8 commit 9aea256

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/colors.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict'
22

3-
const chalk = require('chalk')
3+
const Chalk = require('chalk')
4+
const moize = require('moize').default
45

6+
// Can disable colors with `opts.colors`.
7+
// chalk will automatically disable colors if output does not support it.
58
const getChalk = function(enabled) {
6-
// Can disable colors with `opts.colors`.
7-
// chalk will automatically disable colors if output does not support it.
8-
return new chalk.constructor({ enabled })
9+
const chalk = new Chalk.constructor({ enabled })
10+
return { chalk }
911
}
1012

13+
const mGetChalk = moize(getChalk)
14+
1115
module.exports = {
12-
getChalk,
16+
getChalk: mGetChalk,
1317
}

src/prettify.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ const { getChalk } = require('./colors')
77
const prettify = function({ message, name, level, opts: { colors } }) {
88
const [explanation, firstLine, ...lines] = message.split('\n')
99

10-
// Can disable colors with `opts.colors`.
11-
// chalk will automatically disable colors if output does not support it.
12-
const chalk = getChalk(colors)
13-
const { bold, dim, inverse, italic } = chalk
10+
const {
11+
chalk,
12+
chalk: { bold, dim, inverse, italic },
13+
} = getChalk(colors)
1414

1515
// Add color, sign and `event.name` to first message line, and concatenate
1616
// `firstLine`

0 commit comments

Comments
 (0)