angular-cli: Flag to disable build/serve colors for text viewers that don't support them
Bug Report or Feature Request (mark with an x
)
- [ ] bug report -> please search issues before submitting
- [x] feature request
Versions.
@angular/cli: 1.0.0
Repro steps.
ng build >> log.txt
The log given by the failure.
chunk {[1m[33m4[39m[22m} [1m[32minline.bundle.js, inline.bundle.js.map[39m[22m (inline) 0 bytes[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
Desired functionality.
There’s no way to disable colors in output. Leading to lines and lines of:
chunk {[1m[33m4[39m[22m} [1m[32minline.bundle.js, inline.bundle.js.map[39m[22m (inline) 0 bytes[1m[33m [entry][39m[22m[1m[32m [rendered][39m[22m
in log files. This makes log lines absurdly long and generally reader unfriendly. Plus, the color option being only available for testing makes it even more confusing, as one would expect such an option to be global.
Mention any other details that might be useful.
This is an issue with any non-console or otherwise color unsupporting viewer. For both builds and live reload, in high reliance systems it doesn’t seem viable to constantly designate a terminal window for the output of one component of the product, since 95+% of the time you won’t need it.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 56
- Comments: 16 (1 by maintainers)
@sumitarora consider changing the label to
type: bug
as per previous comment, and also maybe change the priority 🙏This should be a bare basic option for Angular cli, as it is intended to be used within a CI, and it might not have color support out of the box (With Jenkins + Blue Ocean for instance, it cannot be achieved. And the logs are just crazy and hard to look at)
I think it should be a high priority, as the main reason for a CLI is to be a interface from the User to the Code, and we cannot understand the interface if information is not clear.
Funny thing, it looks like the following line in angular-cli sources is responsible for colorizing the
ng build
output:https://github.com/angular/angular-cli/blob/b6b8acc1bf9928fc8016d77980dc61e9d978876b/packages/%40angular/cli/models/webpack-configs/utils.ts#L8
It’s compiled into
utils.js
version upon install, and if you replacecolors
property value withfalse
there - the color is gone everywhere in angular-cli output. So, despite dependency onsupports-color
, it just isn’t invoked byng build ...
.Actually I’d consider it a bug rather than a feature request - other angular-cli commands seem to use
supports-color
correctly - e.g.,ng help | less
doesn’t show color codes. I suppose it’s because thewebpack
options override becomes global somehow.UPDATE:
I have played with the issue a bit, looks like the only thing colorized forcibly is webpack output. So, a quick and dirty way to make
ng build
recognize the terminal and apply colors aschalk
does is as follows:Please use the environment variable NO_COLOR to align with the NO_COLOR-project: http://no-color.org/
For me, using a solarized theme in my terminal, the output is particularly unreadable.
@ivanseidel There are some things that help improve it, like, --no-progess (or similar). But I know your feeling, it’s a shock, especially before there was an issue, and it felt like no one else had ever launched it on jenkins or redirected stdout to file and seen the horror.
Note: currently this can be removed like this on UNIX:
ng build | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" > log.txt
According to: https://stackoverflow.com/a/18000433 It works for me, however, I cannot guarantee it’s consistency, so exercise caution when piping your logs.Edit: using this for ng serve causes a segfault for me. I suppose it still can help when retrieving the files.
Just an update for everyone interested (as I’ve spend some time investigating this issue myself today): This will be fixed in
@angular-devkit/build-angular
v0.7.0 as they removedchalk
and are using their ownterminal
capabilities from@angular-devkit/core
. Haven’t seen this mentioned anywhere though.You can use an environment variable like
CI=1
, to disable color output if you’re doing something custom, but it seems it’s already preconfigured, for the most common solutions.See here how it’s determined if to use colors or not: https://github.com/angular/angular-cli/blob/44086c60ff1d6c26d30850bef125120f6c498ac1/packages/angular_devkit/core/src/terminal/caps.ts#L79-L144
Based on @rsxdalv comment above, when running
ng build
in MS-Studio’s Package Manager Console, the escape sequences can be removed using