feat: NO_COLOR env var removes color in dev format - #377
Conversation
|
I went way down a rabbit hole on this one tbh. The original PR was mergeable, but still I didnt like the read of process.env on every log, it almost triples the perf cost (we're talking like ~200 nanoseconds to ~600 nanoseconds on an already only for dev format, so not really relevant, but still, and the cost was worse for users w/ it unset bc thats how process.env reads work). And the fact that the PR would fail tests for anyone who presumably uses NO_COLOR themeslves just seemed a little tragic. We got like 10 autoamted PRs for this one issue or something, and I dont know that any even addressed these small issues, but I feel good about the time spent and taking this one over. |
There was a problem hiding this comment.
If we're going to check NO_COLOR on module import, maybe we could just "overwrite" the dev format instead of adding a condition that is executed every time (something that I suggested in #303 (comment)).
|
That's a good approach @krzysdz, I got too distracted by meeting what was already in there, ill push up a change |
|
If morgan didn't have to support old Node.js versions we could use some functions from
|
|
weirdly the ecosystem is not even very consistent w/ NO_COLORS, Node's builtins dont implement the If we land it like this, compliant with the text, then we're actually noncompliant with node's built in tools. Im down to merge this and not think about it again though. |

My approach to solve #302
Taking a dep on the env for the behavior of dev format is the whole feature, which required a little hardening of the test setup to ensure that people for whom this feature is intended, users of
NO_COLORcan still run the normal test suite locally without it failing due toNO_COLORfailing the main suite's dev tests.Because mocha doesnt support env or process isolation well (a second file in the same mocha invocation shares
process.envacross all files) and my approach favored checking NO_COLOR once at module require, I added a second mocha invocation to the maintestnpm script.This shouldnt affect nyc coverage, it should still merge it all
¯\_(ツ)_/¯