Skip to content

Commit

Permalink
fix: ensure supportsColor.level exists before stringifying it
Browse files Browse the repository at this point in the history
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 aa9898e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion bin/lint-staged.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down

0 comments on commit aa9898e

Please sign in to comment.