npm@6.2.0 audit always prints ANSI escape codes, even when output is not a TTY

cli
priority:low
triaged

(Misty De Méo) #1

What I Wanted to Do

I attempted to pipe the output of npm audit into the clipboard / a file via running npm audit | pbcopy. I expected the output to be without ANSI escape formatting.

What Happened Instead

The output contained ANSI escape formatting, so it’s unreadable in a text editor.

Reproduction Steps

Using npm@6.2.0, run npm audit | pbcopy or npm audit > file.txt.

Details

Using git bisect, I’ve narrowed this into having been introduced in https://github.com/npm/cli/commit/0483f5c5deaf18c968a128657923103e49f4e67a. Unfortunately, since that’s a megacommit that touched many (all?) of npm’s dependencies, it’s not clear to me what precisely caused this. This bug isn’t present in npm@6.1.0.

I attempted to include sample attachments, but the forum won’t let me because this is a new account. Here’s a short clip from each.

6.1.0:

=== npm audit security report ===                        
                                                                                
# Run  npm install npm-audit-report@1.3.1  to resolve 1 vulnerability

6.2.0:

e[90m                                                                                e[39m
e[90m e[39m                      === npm audit security report ===                       e[90m e[39m
e[90m                                                                                e[39m
# Run  npm install npm-audit-report@1.3.1  to resolve 1 vulnerability

Platform Info

$ npm --versions
{ npm: '6.2.0',
  ares: '1.14.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.32.0',
  node: '10.7.0',
  openssl: '1.1.0h',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.22.0',
  v8: '6.7.288.49-node.15',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

(Misty De Méo) #3

Just tested, and this also occurs in the just-released 6.3.0.


(Rebecca Turner) #4

I can reproduce this.

It’s worth noting that it does disable color when writing to a non-tty, but still outputs some other ANSI codes that aren’t displayed. This is caused by a bug in the colors module used by cli-table2 and cli-table3 that got updated when we were flattening. For the time being I’ll pin us back.


(system) #5

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.