From 1e837f3281413c7a9a3a27bb37b6829e3d2a85fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 11 Feb 2019 00:19:31 +0100 Subject: [PATCH] Respect NO_COLOR in TypeScript output (#1736) --- js/compiler.ts | 9 +++++---- js/compiler_test.ts | 3 +++ rollup.config.js | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/js/compiler.ts b/js/compiler.ts index 904e38eba6..85d8085200 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -68,6 +68,7 @@ interface Ts { createLanguageService: typeof ts.createLanguageService; /* tslint:disable-next-line:max-line-length */ formatDiagnosticsWithColorAndContext: typeof ts.formatDiagnosticsWithColorAndContext; + formatDiagnostics: typeof ts.formatDiagnostics; } /** A simple object structure for caching resolved modules and their contents. @@ -344,10 +345,10 @@ class Compiler implements ts.LanguageServiceHost, ts.FormatDiagnosticsHost { ...service.getSemanticDiagnostics(fileName) ]; if (diagnostics.length > 0) { - const errMsg = this._ts.formatDiagnosticsWithColorAndContext( - diagnostics, - this - ); + const errMsg = os.noColor + ? this._ts.formatDiagnostics(diagnostics, this) + : this._ts.formatDiagnosticsWithColorAndContext(diagnostics, this); + console.log(errMsg); // All TypeScript errors are terminal for deno this._os.exit(1); diff --git a/js/compiler_test.ts b/js/compiler_test.ts index 771fbcc6b6..57da29ea0c 100644 --- a/js/compiler_test.ts +++ b/js/compiler_test.ts @@ -308,6 +308,9 @@ const tsMock = { createLanguageService() { return {} as any; }, + formatDiagnostics(diagnostics: ReadonlyArray, _host: any): string { + return JSON.stringify(diagnostics.map(({ messageText }) => messageText)); + }, formatDiagnosticsWithColorAndContext( diagnostics: ReadonlyArray, _host: any diff --git a/rollup.config.js b/rollup.config.js index cd5e8394ab..30d03bd776 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -264,6 +264,7 @@ export default function makeConfig(commandOptions) { // bundle [typescriptPath]: [ "createLanguageService", + "formatDiagnostics", "formatDiagnosticsWithColorAndContext", "ModuleKind", "ScriptKind",