Skip to content

Commit aa9898e

Browse files
committedJul 28, 2020
fix: ensure supportsColor.level exists before stringifying it
When supports-color detects a level of 0, it will not return an object containing the key `level`, but instead only `false`. This commit makes sure `supportsColor.level` exists before calling `supportsColor.level.toString()`. The TypeScript definitions of `chalk` seem wrong in this regard, since they imply that if `supportsColor` is truthy, it is an object and always contains the `level` key of type `0 | 1 | 2 | 3`.
1 parent 86c9ed2 commit aa9898e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎bin/lint-staged.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
66
const { supportsColor } = require('chalk')
7-
if (supportsColor) {
7+
if (supportsColor && supportsColor.level) {
88
process.env.FORCE_COLOR = supportsColor.level.toString()
99
}
1010

0 commit comments

Comments
 (0)
Please sign in to comment.