From aa9898e47ce20d925072ccc93986b28c0593e625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20J=C3=A4ppinen?= Date: Tue, 28 Jul 2020 19:38:27 +0300 Subject: [PATCH] fix: ensure supportsColor.level exists before stringifying it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- bin/lint-staged.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/lint-staged.js b/bin/lint-staged.js index 8df264b67..a48c14291 100755 --- a/bin/lint-staged.js +++ b/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() }