Skip to content

webpack output is no longer colored in git bash #11833

Closed
@bedag-moo

Description

@bedag-moo

Bug Report or Feature Request

- [x] bug report

Command (mark with an x)

- [x] serve

Versions

$ node --version
v8.11.3

$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.1.2
Node: 8.11.3
OS: win32 x64
Angular: 6.1.1
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.7.2
@angular-devkit/build-angular     0.7.2
@angular-devkit/build-optimizer   0.7.2
@angular-devkit/build-webpack     0.7.2
@angular-devkit/core              0.7.2
@angular-devkit/schematics        0.7.2
@angular/cli                      6.1.2
@ngtools/webpack                  6.1.2
@schematics/angular               0.7.2
@schematics/update                0.7.2
rxjs                              6.2.2
typescript                        2.7.2
webpack                           4.9.2

$ git --version
git version 2.14.2.windows.2

I use the mingw terminal.

Repro steps

Run ng serve

Expected: webpack output uses colors as in @angular/[email protected]
Actual: webpack output does not use color

Mention any other details that might be useful

The color detection logic in

function _getColorLevel(stream: Socket): number {
if (stream && !stream.isTTY) {
return 0;
}
if (_platform.startsWith('win32')) {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
// libuv that enables 256 color output on Windows. Anything earlier and it
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
// release that supports 256 colors.
const osRelease = _os.release().split('.');
if (Number(_versions.node.split('.')[0]) >= 8
&& Number(osRelease[0]) >= 10
&& Number(osRelease[2]) >= 10586) {
return 2;
}
return 1;
}
if ('CI' in _env) {
if (ciVars.some(sign => sign in _env) || _env.CI_NAME === 'codeship') {
return 1;
}
return 0;
}
if ('TEAMCITY_VERSION' in _env) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(_env.TEAMCITY_VERSION) ? 1 : 0;
}
if ('TERM_PROGRAM' in _env) {
const version = parseInt((_env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
switch (_env.TERM_PROGRAM) {
case 'iTerm.app':
return version >= 3 ? 3 : 2;
case 'Hyper':
return 3;
case 'Apple_Terminal':
return 2;
// No default
}
}
if (/-256(color)?$/i.test(_env.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(_env.TERM)) {
return 1;
}
if ('COLORTERM' in _env) {
return 1;
}
if (_env.TERM === 'dumb') {
return 0;
}
return 0;
}

does not recognize the terminal as color capable, because the following if matches:

  if (stream && !stream.isTTY) {
    return 0;
  }

(stream is a Socket, no clue why)

However, git-bash does set a couple environment variables that may be helpful in detecting it, including:

MSYSTEM: 'MINGW64',
TERM: 'xterm',

I'll submit a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions