From b15d6a48cb3d07b82e4c079cc27c85ad76abc497 Mon Sep 17 00:00:00 2001 From: Valera Rozuvan Date: Tue, 2 Oct 2018 19:09:51 +0300 Subject: [PATCH] Fix GH#18217 issue for FileLog. (#27430) * Fix GH#18217 issue for FileLog. * Refactor FileLog class to not use isEnabled property. --- src/typingsInstaller/nodeTypingsInstaller.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index 00ee8b4fa19..62bdcfce260 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -1,5 +1,3 @@ -// tslint:disable no-unnecessary-type-assertion (TODO: tslint can't find node types) - namespace ts.server.typingsInstaller { const fs: { appendFileSync(file: string, content: string): void @@ -12,19 +10,20 @@ namespace ts.server.typingsInstaller { } = require("path"); class FileLog implements Log { - private logEnabled = true; - constructor(private readonly logFile?: string) { + constructor(private logFile: string | undefined) { } isEnabled = () => { - return this.logEnabled && this.logFile !== undefined; + return typeof this.logFile === "string"; } writeLine = (text: string) => { + if (typeof this.logFile !== "string") return; + try { - fs.appendFileSync(this.logFile!, `[${nowString()}] ${text}${sys.newLine}`); // TODO: GH#18217 + fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`); } catch (e) { - this.logEnabled = false; + this.logFile = undefined; } } }