Skip to content
Permalink
Browse files

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`.
  • Loading branch information
iiroj committed Jul 28, 2020
1 parent 86c9ed2 commit aa9898e47ce20d925072ccc93986b28c0593e625
Showing with 1 addition and 1 deletion.
  1. +1 −1 bin/lint-staged.js
@@ -4,7 +4,7 @@

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

0 comments on commit aa9898e

Please sign in to comment.
You can’t perform that action at this time.