Skip to content

Commit 46ec6af

Browse files
authored
Support FORCE_COLOR (#63055)
1 parent 66edca1 commit 46ec6af

4 files changed

Lines changed: 361 additions & 1 deletion

File tree

src/compiler/executeCommandLine.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,13 @@ function updateReportDiagnostic(
157157
}
158158

159159
function defaultIsPretty(sys: System) {
160-
return !!sys.writeOutputIsTTY && sys.writeOutputIsTTY() && !sys.getEnvironmentVariable("NO_COLOR");
160+
if (sys.getEnvironmentVariable("NO_COLOR")) {
161+
return false;
162+
}
163+
if (sys.getEnvironmentVariable("FORCE_COLOR")) {
164+
return true;
165+
}
166+
return !!sys.writeOutputIsTTY && sys.writeOutputIsTTY();
161167
}
162168

163169
function shouldBePretty(sys: System, options: CompilerOptions | BuildOptions) {

src/testRunner/unittests/tsc/commandLine.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ describe("unittests:: tsc:: commandLine::", () => {
3030
commandLineArgs: emptyArray,
3131
});
3232

33+
verifyTsc({
34+
scenario: "commandLine",
35+
subScenario: "adds color when FORCE_COLOR is set",
36+
sys: () =>
37+
TestServerHost.createWatchedSystem(emptyArray, {
38+
environmentVariables: new Map([["FORCE_COLOR", "true"]]),
39+
}),
40+
commandLineArgs: emptyArray,
41+
});
42+
43+
verifyTsc({
44+
scenario: "commandLine",
45+
subScenario: "does not add color when NO_COLOR is set even if FORCE_COLOR is set",
46+
sys: () =>
47+
TestServerHost.createWatchedSystem(emptyArray, {
48+
environmentVariables: new Map([["NO_COLOR", "true"], ["FORCE_COLOR", "true"]]),
49+
}),
50+
commandLineArgs: emptyArray,
51+
});
52+
3353
verifyTsc({
3454
scenario: "commandLine",
3555
subScenario: "when build not first argument",
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
2+
Input::
3+
//// [/home/src/tslibs/TS/Lib/lib.d.ts]
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
18+
/home/src/tslibs/TS/Lib/tsc.js
19+
Output::
20+
Version FakeTSVersion
21+
tsc: The TypeScript Compiler - Version FakeTSVersion
22+
23+
COMMON COMMANDS
24+
25+
tsc
26+
Compiles the current project (tsconfig.json in the working directory.)
27+
28+
tsc app.ts util.ts
29+
Ignoring tsconfig.json, compiles the specified files with default compiler options.
30+
31+
tsc -b
32+
Build a composite project in the working directory.
33+
34+
tsc --init
35+
Creates a tsconfig.json with the recommended settings in the working directory.
36+
37+
tsc -p ./path/to/tsconfig.json
38+
Compiles the TypeScript project located at the specified path.
39+
40+
tsc --help --all
41+
An expanded version of this information, showing all possible compiler options
42+
43+
tsc --noEmit
44+
tsc --target esnext
45+
Compiles the current project, with additional settings.
46+
47+
COMMAND LINE FLAGS
48+
49+
--help, -h
50+
Print this message.
51+
52+
--watch, -w
53+
Watch input files.
54+
55+
--all
56+
Show all compiler options.
57+
58+
--version, -v
59+
Print the compiler's version.
60+
61+
--init
62+
Initializes a TypeScript project and creates a tsconfig.json file.
63+
64+
--project, -p
65+
Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
66+
67+
--showConfig
68+
Print the final configuration instead of building.
69+
70+
--ignoreConfig
71+
Ignore the tsconfig found and build with commandline options and files.
72+
73+
--build, -b
74+
Build one or more projects and their dependencies, if out of date
75+
76+
COMMON COMPILER OPTIONS
77+
78+
--pretty
79+
Enable color and formatting in TypeScript's output to make compiler errors easier to read.
80+
type: boolean
81+
default: true
82+
83+
--declaration, -d
84+
Generate .d.ts files from TypeScript and JavaScript files in your project.
85+
type: boolean
86+
default: `false`, unless `composite` is set
87+
88+
--declarationMap
89+
Create sourcemaps for d.ts files.
90+
type: boolean
91+
default: false
92+
93+
--emitDeclarationOnly
94+
Only output d.ts files and not JavaScript files.
95+
type: boolean
96+
default: false
97+
98+
--sourceMap
99+
Create source map files for emitted JavaScript files.
100+
type: boolean
101+
default: false
102+
103+
--noEmit
104+
Disable emitting files from a compilation.
105+
type: boolean
106+
default: false
107+
108+
--target, -t
109+
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
110+
one of: es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext
111+
default: es5
112+
113+
--module, -m
114+
Specify what module code is generated.
115+
one of: commonjs, es6/es2015, es2020, es2022, esnext, node16, node18, node20, nodenext, preserve
116+
default: undefined
117+
118+
--lib
119+
Specify a set of bundled library declaration files that describe the target runtime environment.
120+
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.iterable, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es2023.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, esnext.typedarrays, esnext.error, esnext.sharedmemory, decorators, decorators.legacy
121+
default: undefined
122+
123+
--allowJs
124+
Allow JavaScript files to be a part of your program. Use the 'checkJs' option to get errors from these files.
125+
type: boolean
126+
default: `false`, unless `checkJs` is set
127+
128+
--checkJs
129+
Enable error reporting in type-checked JavaScript files.
130+
type: boolean
131+
default: false
132+
133+
--jsx
134+
Specify what JSX code is generated.
135+
one of: preserve, react, react-native, react-jsx, react-jsxdev
136+
default: undefined
137+
138+
--outFile
139+
Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output.
140+
141+
--outDir
142+
Specify an output folder for all emitted files.
143+
144+
--removeComments
145+
Disable emitting comments.
146+
type: boolean
147+
default: false
148+
149+
--strict
150+
Enable all strict type-checking options.
151+
type: boolean
152+
default: false
153+
154+
--types
155+
Specify type package names to be included without being referenced in a source file.
156+
157+
--esModuleInterop
158+
Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility.
159+
type: boolean
160+
default: true
161+
162+
You can learn about all of the compiler options at https://aka.ms/tsc
163+
164+
165+
166+
167+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
currentDirectory:: /home/src/workspaces/project useCaseSensitiveFileNames:: false
2+
Input::
3+
//// [/home/src/tslibs/TS/Lib/lib.d.ts]
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
18+
/home/src/tslibs/TS/Lib/tsc.js
19+
Output::
20+
Version FakeTSVersion
21+
tsc: The TypeScript Compiler - Version FakeTSVersion
22+
23+
COMMON COMMANDS
24+
25+
tsc
26+
Compiles the current project (tsconfig.json in the working directory.)
27+
28+
tsc app.ts util.ts
29+
Ignoring tsconfig.json, compiles the specified files with default compiler options.
30+
31+
tsc -b
32+
Build a composite project in the working directory.
33+
34+
tsc --init
35+
Creates a tsconfig.json with the recommended settings in the working directory.
36+
37+
tsc -p ./path/to/tsconfig.json
38+
Compiles the TypeScript project located at the specified path.
39+
40+
tsc --help --all
41+
An expanded version of this information, showing all possible compiler options
42+
43+
tsc --noEmit
44+
tsc --target esnext
45+
Compiles the current project, with additional settings.
46+
47+
COMMAND LINE FLAGS
48+
49+
--help, -h
50+
Print this message.
51+
52+
--watch, -w
53+
Watch input files.
54+
55+
--all
56+
Show all compiler options.
57+
58+
--version, -v
59+
Print the compiler's version.
60+
61+
--init
62+
Initializes a TypeScript project and creates a tsconfig.json file.
63+
64+
--project, -p
65+
Compile the project given the path to its configuration file, or to a folder with a 'tsconfig.json'.
66+
67+
--showConfig
68+
Print the final configuration instead of building.
69+
70+
--ignoreConfig
71+
Ignore the tsconfig found and build with commandline options and files.
72+
73+
--build, -b
74+
Build one or more projects and their dependencies, if out of date
75+
76+
COMMON COMPILER OPTIONS
77+
78+
--pretty
79+
Enable color and formatting in TypeScript's output to make compiler errors easier to read.
80+
type: boolean
81+
default: true
82+
83+
--declaration, -d
84+
Generate .d.ts files from TypeScript and JavaScript files in your project.
85+
type: boolean
86+
default: `false`, unless `composite` is set
87+
88+
--declarationMap
89+
Create sourcemaps for d.ts files.
90+
type: boolean
91+
default: false
92+
93+
--emitDeclarationOnly
94+
Only output d.ts files and not JavaScript files.
95+
type: boolean
96+
default: false
97+
98+
--sourceMap
99+
Create source map files for emitted JavaScript files.
100+
type: boolean
101+
default: false
102+
103+
--noEmit
104+
Disable emitting files from a compilation.
105+
type: boolean
106+
default: false
107+
108+
--target, -t
109+
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
110+
one of: es5, es6/es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext
111+
default: es5
112+
113+
--module, -m
114+
Specify what module code is generated.
115+
one of: commonjs, es6/es2015, es2020, es2022, esnext, node16, node18, node20, nodenext, preserve
116+
default: undefined
117+
118+
--lib
119+
Specify a set of bundled library declaration files that describe the target runtime environment.
120+
one or more: es5, es6/es2015, es7/es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, es2024, esnext, dom, dom.iterable, dom.asynciterable, webworker, webworker.importscripts, webworker.iterable, webworker.asynciterable, scripthost, es2015.core, es2015.collection, es2015.generator, es2015.iterable, es2015.promise, es2015.proxy, es2015.reflect, es2015.symbol, es2015.symbol.wellknown, es2016.array.include, es2016.intl, es2017.arraybuffer, es2017.date, es2017.object, es2017.sharedmemory, es2017.string, es2017.intl, es2017.typedarrays, es2018.asyncgenerator, es2018.asynciterable/esnext.asynciterable, es2018.intl, es2018.promise, es2018.regexp, es2019.array, es2019.object, es2019.string, es2019.symbol/esnext.symbol, es2019.intl, es2020.bigint/esnext.bigint, es2020.date, es2020.promise, es2020.sharedmemory, es2020.string, es2020.symbol.wellknown, es2020.intl, es2020.number, es2021.promise, es2021.string, es2021.weakref/esnext.weakref, es2021.intl, es2022.array, es2022.error, es2022.intl, es2022.object, es2022.string, es2022.regexp, es2023.array, es2023.collection, es2023.intl, es2024.arraybuffer, es2024.collection, es2024.object/esnext.object, es2024.promise, es2024.regexp/esnext.regexp, es2024.sharedmemory, es2024.string/esnext.string, esnext.array, esnext.collection, esnext.intl, esnext.disposable, esnext.promise, esnext.decorators, esnext.iterator, esnext.float16, esnext.typedarrays, esnext.error, esnext.sharedmemory, decorators, decorators.legacy
121+
default: undefined
122+
123+
--allowJs
124+
Allow JavaScript files to be a part of your program. Use the 'checkJs' option to get errors from these files.
125+
type: boolean
126+
default: `false`, unless `checkJs` is set
127+
128+
--checkJs
129+
Enable error reporting in type-checked JavaScript files.
130+
type: boolean
131+
default: false
132+
133+
--jsx
134+
Specify what JSX code is generated.
135+
one of: preserve, react, react-native, react-jsx, react-jsxdev
136+
default: undefined
137+
138+
--outFile
139+
Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output.
140+
141+
--outDir
142+
Specify an output folder for all emitted files.
143+
144+
--removeComments
145+
Disable emitting comments.
146+
type: boolean
147+
default: false
148+
149+
--strict
150+
Enable all strict type-checking options.
151+
type: boolean
152+
default: false
153+
154+
--types
155+
Specify type package names to be included without being referenced in a source file.
156+
157+
--esModuleInterop
158+
Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility.
159+
type: boolean
160+
default: true
161+
162+
You can learn about all of the compiler options at https://aka.ms/tsc
163+
164+
165+
166+
167+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped

0 commit comments

Comments
 (0)