From 558d4e74a5382a3f49cc4c6a06a87e0a3de669eb Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Mon, 11 Apr 2022 09:50:24 +0200 Subject: [PATCH] Minor change to improve support for Parcel/SWC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parcel is currently [unable to perform static analysis](https://github.com/parcel-bundler/parcel/issues/7904) on the `in` operator applied to `process.env`, for the purposes of bundling the module. (Parcel is a front-end to SWC, so this most likely affects SWC as well.) Would you mind making this very minor change? It should work exactly the same - `enabled` is `true` by default, so `FORCE_COLOR` only has an effect when set to exactly `0`. It's a bit simpler and avoids mutations, so maybe a bit easier to read anyhow. 🙂 --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 8e26419..71a5570 100644 --- a/index.js +++ b/index.js @@ -8,11 +8,12 @@ const identity = val => val; const ANSI_REGEX = /[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g; const create = () => { - const colors = { enabled: true, visible: true, styles: {}, keys: {} }; - - if ('FORCE_COLOR' in process.env) { - colors.enabled = process.env.FORCE_COLOR !== '0'; - } + const colors = { + enabled: process.env.FORCE_COLOR !== '0', + visible: true, + styles: {}, + keys: {} + }; const ansi = style => { let open = style.open = `\u001b[${style.codes[0]}m`;