Skip to content

Commit b15d6a4

Browse files
valera-rozuvanAndy
authored and
Andy
committed
Fix GH#18217 issue for FileLog. (#27430)
* Fix GH#18217 issue for FileLog. * Refactor FileLog class to not use isEnabled property.
1 parent 1237df7 commit b15d6a4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/typingsInstaller/nodeTypingsInstaller.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// tslint:disable no-unnecessary-type-assertion (TODO: tslint can't find node types)
2-
31
namespace ts.server.typingsInstaller {
42
const fs: {
53
appendFileSync(file: string, content: string): void
@@ -12,19 +10,20 @@ namespace ts.server.typingsInstaller {
1210
} = require("path");
1311

1412
class FileLog implements Log {
15-
private logEnabled = true;
16-
constructor(private readonly logFile?: string) {
13+
constructor(private logFile: string | undefined) {
1714
}
1815

1916
isEnabled = () => {
20-
return this.logEnabled && this.logFile !== undefined;
17+
return typeof this.logFile === "string";
2118
}
2219
writeLine = (text: string) => {
20+
if (typeof this.logFile !== "string") return;
21+
2322
try {
24-
fs.appendFileSync(this.logFile!, `[${nowString()}] ${text}${sys.newLine}`); // TODO: GH#18217
23+
fs.appendFileSync(this.logFile, `[${nowString()}] ${text}${sys.newLine}`);
2524
}
2625
catch (e) {
27-
this.logEnabled = false;
26+
this.logFile = undefined;
2827
}
2928
}
3029
}

0 commit comments

Comments
 (0)