From 3598b906e344b5a2971a65cedb99536df3847292 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Aug 2015 11:40:21 -0700 Subject: [PATCH 1/3] Add optional argument to readConfigFile Which allows the caller to specify the `System` used to read the file. --- src/compiler/commandLineParser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1f57c142113..ece6471ee2f 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -374,10 +374,10 @@ namespace ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { + export function readConfigFile(fileName: string, system: System = sys): { config?: any; error?: Diagnostic } { let text = ""; try { - text = sys.readFile(fileName); + text = system.readFile(fileName); } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; From e4af02bb8b27b409a8e600454967b335cbada459 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Aug 2015 16:35:02 -0700 Subject: [PATCH 2/3] Toss the option out the window --- src/compiler/commandLineParser.ts | 2 +- src/compiler/tsc.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index ece6471ee2f..6696045be94 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -374,7 +374,7 @@ namespace ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string, system: System = sys): { config?: any; error?: Diagnostic } { + export function readConfigFile(fileName: string, system: System): { config?: any; error?: Diagnostic } { let text = ""; try { text = system.readFile(fileName); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 8c0a6d4e8c4..1c883eb37dd 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -216,7 +216,7 @@ namespace ts { if (!cachedProgram) { if (configFileName) { - let result = readConfigFile(configFileName); + let result = readConfigFile(configFileName, sys); if (result.error) { reportDiagnostic(result.error); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); From f1dbf904a773f7133a7db3a1d13d4a940d033b8e Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 27 Aug 2015 16:52:49 -0700 Subject: [PATCH 3/3] Toss the System out --- src/compiler/commandLineParser.ts | 4 ++-- src/compiler/tsc.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 6696045be94..938777b42d2 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -374,10 +374,10 @@ namespace ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string, system: System): { config?: any; error?: Diagnostic } { + export function readConfigFile(fileName: string, readFile: (path: string) => string): { config?: any; error?: Diagnostic } { let text = ""; try { - text = system.readFile(fileName); + text = readFile(fileName); } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 1c883eb37dd..96759b68250 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -216,7 +216,7 @@ namespace ts { if (!cachedProgram) { if (configFileName) { - let result = readConfigFile(configFileName, sys); + let result = readConfigFile(configFileName, sys.readFile); if (result.error) { reportDiagnostic(result.error); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);