Desired outcome
--no-color actually strips colour, and rendering a report does not mutate the process environment.
Why it matters
src/reporters/terminal.ts:
const useColor = options.color ?? true;
if (!useColor) {
// picocolors respects NO_COLOR, but honor an explicit override too.
process.env.NO_COLOR = "1";
}
Two problems.
-
It probably does not work. picocolors decides whether colour is supported once, when the module is first imported, and exposes the result as isColorSupported. By the time renderTerminal runs, pc.red and friends are already bound to either the colouring or the pass-through implementations. Setting process.env.NO_COLOR after import does not retroactively change that, so mcp-audit --no-color (src/cli.ts line 189, documented at line 65) can still emit ANSI escapes into a redirected file or a CI log.
-
It is a global side effect from a pure-looking render function. renderTerminal is exported from the package (src/index.ts), so a library consumer who renders one report with color: false has NO_COLOR=1 set for the rest of their process, silently changing the behaviour of every other library they use. It is never restored.
Steps
- Use picocolors' explicit constructor instead of the environment:
import { createColors } from "picocolors" and build a colour object with createColors(useColor), then use that instead of the default pc import inside renderTerminal and renderSummary.
- Delete the
process.env.NO_COLOR assignment.
renderSummary is exported separately and also uses the module-level pc, so it needs the colour object passed in or a parameter of its own.
- Add a test in
test/reporters.test.ts asserting the output of renderTerminal(result, { color: false }) contains no ANSI escape sequences, and that process.env.NO_COLOR is unchanged afterwards.
Claiming this
Comment below to claim it. A reply usually comes within a day.
Desired outcome
--no-coloractually strips colour, and rendering a report does not mutate the process environment.Why it matters
src/reporters/terminal.ts:Two problems.
It probably does not work. picocolors decides whether colour is supported once, when the module is first imported, and exposes the result as
isColorSupported. By the timerenderTerminalruns,pc.redand friends are already bound to either the colouring or the pass-through implementations. Settingprocess.env.NO_COLORafter import does not retroactively change that, somcp-audit --no-color(src/cli.tsline 189, documented at line 65) can still emit ANSI escapes into a redirected file or a CI log.It is a global side effect from a pure-looking render function.
renderTerminalis exported from the package (src/index.ts), so a library consumer who renders one report withcolor: falsehasNO_COLOR=1set for the rest of their process, silently changing the behaviour of every other library they use. It is never restored.Steps
import { createColors } from "picocolors"and build a colour object withcreateColors(useColor), then use that instead of the defaultpcimport insiderenderTerminalandrenderSummary.process.env.NO_COLORassignment.renderSummaryis exported separately and also uses the module-levelpc, so it needs the colour object passed in or a parameter of its own.test/reporters.test.tsasserting the output ofrenderTerminal(result, { color: false })contains no ANSI escape sequences, and thatprocess.env.NO_COLORis unchanged afterwards.Claiming this
Comment below to claim it. A reply usually comes within a day.