@@ -120,15 +120,19 @@ func parseArgs() *cliOptions {
120
120
}
121
121
122
122
func main () {
123
+ os .Exit (runMain ())
124
+ }
125
+
126
+ func runMain () int {
123
127
// TypeScript uses ANSI escape sequences which cmd.exe won't parse without enabling virtual terminal processing.
124
128
enableVirtualTerminalProcessing ()
125
129
126
130
if args := os .Args [1 :]; len (args ) > 0 {
127
131
switch args [0 ] {
128
132
case "tsc" :
129
- os . Exit ( int (execute .CommandLine (newSystem (), nil , args [1 :]) ))
133
+ return int (execute .CommandLine (newSystem (), nil , args [1 :]))
130
134
case "lsp" :
131
- os . Exit ( runLSP (args [1 :]) )
135
+ return runLSP (args [1 :])
132
136
}
133
137
}
134
138
opts := parseArgs ()
@@ -143,7 +147,7 @@ func main() {
143
147
currentDirectory , err := os .Getwd ()
144
148
if err != nil {
145
149
fmt .Fprintf (os .Stderr , "Error getting current directory: %v\n " , err )
146
- os . Exit ( 1 )
150
+ return 1
147
151
}
148
152
149
153
fs := bundled .WrapFS (osvfs .FS ())
@@ -154,7 +158,7 @@ func main() {
154
158
configFileName = tspath .CombinePaths (configFileName , "tsconfig.json" )
155
159
if ! fs .FileExists (configFileName ) {
156
160
fmt .Fprintf (os .Stderr , "Error: The file %v does not exist.\n " , configFileName )
157
- os . Exit ( 1 )
161
+ return 1
158
162
}
159
163
}
160
164
@@ -178,25 +182,25 @@ func main() {
178
182
179
183
if compilerOptions .ListFilesOnly .IsTrue () {
180
184
listFiles (program )
181
- os . Exit ( 0 )
185
+ return 0
182
186
}
183
187
184
188
if compilerOptions .ShowConfig .IsTrue () {
185
189
enc := json .NewEncoder (os .Stdout )
186
190
enc .SetIndent ("" , " " )
187
191
if err := enc .Encode (compilerOptions ); err != nil {
188
192
fmt .Fprintf (os .Stderr , "Error encoding JSON: %v\n " , err )
189
- os . Exit ( 1 )
193
+ return 1
190
194
}
191
- os . Exit ( 0 )
195
+ return 0
192
196
}
193
197
194
198
var bindTime , checkTime time.Duration
195
199
196
200
diagnostics := program .GetConfigFileParsingDiagnostics ()
197
201
if len (diagnostics ) != 0 {
198
202
printDiagnostics (diagnostics , host , compilerOptions )
199
- os . Exit ( 1 )
203
+ return 1
200
204
}
201
205
202
206
diagnostics = program .GetSyntacticDiagnostics (nil )
@@ -233,8 +237,12 @@ func main() {
233
237
runtime .GC ()
234
238
runtime .ReadMemStats (& memStats )
235
239
236
- if ! opts .devel .quiet && len (diagnostics ) != 0 {
237
- printDiagnostics (ts .SortAndDeduplicateDiagnostics (diagnostics ), host , compilerOptions )
240
+ exitCode := 0
241
+ if len (diagnostics ) != 0 {
242
+ if ! opts .devel .quiet {
243
+ printDiagnostics (ts .SortAndDeduplicateDiagnostics (diagnostics ), host , compilerOptions )
244
+ }
245
+ exitCode = 1
238
246
}
239
247
240
248
if exts := program .UnsupportedExtensions (); len (exts ) != 0 {
@@ -268,6 +276,8 @@ func main() {
268
276
stats .add ("Total time" , totalTime )
269
277
270
278
stats .print ()
279
+
280
+ return exitCode
271
281
}
272
282
273
283
type tableRow struct {
0 commit comments