|
1 | 1 | import path from 'node:path' |
| 2 | +import process from 'node:process' |
2 | 3 | import { createDebug } from 'obug' |
3 | 4 | import { RE_DTS, RE_NODE_MODULES } from '../filename.ts' |
4 | 5 | import { |
@@ -113,9 +114,7 @@ export class TsgoGenerator implements Generator { |
113 | 114 | .flat() |
114 | 115 | .filter(isMapperDiagnostic) |
115 | 116 | if (diagnostics.length) { |
116 | | - throw new Error( |
117 | | - this.apiModule.formatDiagnostics(diagnostics, this.api), |
118 | | - ) |
| 117 | + throw new Error(this.formatDiagnostics(diagnostics)) |
119 | 118 | } |
120 | 119 | } |
121 | 120 | } |
@@ -154,6 +153,13 @@ export class TsgoGenerator implements Generator { |
154 | 153 | return this.options.compiler === 'tsrs' ? 'tsrs' : 'TypeScript Go' |
155 | 154 | } |
156 | 155 |
|
| 156 | + private formatDiagnostics(diagnostics: readonly Diagnostic[]): string { |
| 157 | + const format = process.stderr.hasColors?.() |
| 158 | + ? this.apiModule!.formatDiagnosticsWithColorAndContext |
| 159 | + : this.apiModule!.formatDiagnostics |
| 160 | + return format(diagnostics, this.api!) |
| 161 | + } |
| 162 | + |
157 | 163 | private toTsFilename(fileName: string): string { |
158 | 164 | return path.resolve(this.options.languageContext.toTsFilename(fileName)) |
159 | 165 | } |
@@ -311,7 +317,7 @@ export class TsgoGenerator implements Generator { |
311 | 317 | if (output.emitSkipped && output.diagnostics.length) { |
312 | 318 | return { |
313 | 319 | error: mapError( |
314 | | - this.apiModule.formatDiagnostics(output.diagnostics, this.api), |
| 320 | + this.formatDiagnostics(output.diagnostics), |
315 | 321 | tsFileName, |
316 | 322 | fileName, |
317 | 323 | ), |
|
0 commit comments