microsoft / microsoft/TypeScript

Add support for FORCE_COLOR environment variable to tsc

Open
#44,233 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Suggestion

🔍 Search Terms

FORCE_COLOR

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

https://github.com/chalk/supports-color/blob/main/index.js

Among the npm/js ecosystem it is common to support overriding color output through an environment variable named FORCE_COLOR. The most commonly used implementation being the 'supports-color' library maintained by the 'chalk' team, linked above. The basic behavior is...

If FORCE_COLOR is "0" or "false" then force plain, uncolored output
If FORCE_COLOR is "1" or "true" then force 16 color ANSI output
If FORCE_COLOR is "2" then force 256 color ANSI output
If FORCE_COLOR is "3" then force full 24-bit RGB output

This ends up being particularly useful for writing tools that act as wrappers around tsc, which might spawn a tsc process and then display its output.

I think the tsc only ever uses 16 color output, which would simplify implementation a little bit.

📃 Motivating Example

The ability to run tsc in a task harness, while still getting colored output, without needing to do any weird argument/configuration injecting.

💻 Use Cases

The particular use case that I'm working on is a CLI tool that can invoke other CLI tools in parallel, such as ESLint, TSC, Prettier, Jest, TypeDoc, etc. The output of each process is piped into a set of buffers until the process exits, and then the buffer is piped out to stdout/stderr as appropriate. You get the speed benefits of running all the tooling in parallel, without needing to have 5+ terminals open to run them all manually, and without the output of each tool getting mixed with the output of others and becoming mangled and hard to read.

[jest]
--- Full color, continuous Jest output ---
[tsc]
--- Full color, continuous tsc output ---

etc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named in the issue. Start by locating tsc's color-output handling, then compare the requested FORCE_COLOR values with the linked supports-color behavior; done means tsc honors the documented overrides while preserving normal output behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.