Skip to content

Commit

Permalink
Minor change to improve support for Parcel/SWC
Browse files Browse the repository at this point in the history
Parcel is currently [unable to perform static analysis](parcel-bundler/parcel#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. 🙂
  • Loading branch information
mindplay-dk committed Apr 11, 2022
1 parent a479436 commit 558d4e7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down

0 comments on commit 558d4e7

Please sign in to comment.