@@ -1242,10 +1242,9 @@ namespace ts {
1242
1242
}
1243
1243
1244
1244
function parseResponseFile ( fileName : string ) {
1245
- const text = readFile ? readFile ( fileName ) : sys . readFile ( fileName ) ;
1246
-
1247
- if ( ! text ) {
1248
- errors . push ( createCompilerDiagnostic ( Diagnostics . File_0_not_found , fileName ) ) ;
1245
+ const text = tryReadFile ( fileName , readFile || ( fileName => sys . readFile ( fileName ) ) ) ;
1246
+ if ( ! isString ( text ) ) {
1247
+ errors . push ( text ) ;
1249
1248
return ;
1250
1249
}
1251
1250
@@ -1466,18 +1465,9 @@ namespace ts {
1466
1465
extendedConfigCache ?: Map < ExtendedConfigCacheEntry > ,
1467
1466
watchOptionsToExtend ?: WatchOptions
1468
1467
) : ParsedCommandLine | undefined {
1469
- let configFileText : string | undefined ;
1470
- try {
1471
- configFileText = host . readFile ( configFileName ) ;
1472
- }
1473
- catch ( e ) {
1474
- const error = createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , configFileName , e . message ) ;
1475
- host . onUnRecoverableConfigFileDiagnostic ( error ) ;
1476
- return undefined ;
1477
- }
1478
- if ( ! configFileText ) {
1479
- const error = createCompilerDiagnostic ( Diagnostics . File_0_not_found , configFileName ) ;
1480
- host . onUnRecoverableConfigFileDiagnostic ( error ) ;
1468
+ const configFileText = tryReadFile ( configFileName , fileName => host . readFile ( fileName ) ) ;
1469
+ if ( ! isString ( configFileText ) ) {
1470
+ host . onUnRecoverableConfigFileDiagnostic ( configFileText ) ;
1481
1471
return undefined ;
1482
1472
}
1483
1473
@@ -1530,15 +1520,16 @@ namespace ts {
1530
1520
return isString ( textOrDiagnostic ) ? parseJsonText ( fileName , textOrDiagnostic ) : < TsConfigSourceFile > { parseDiagnostics : [ textOrDiagnostic ] } ;
1531
1521
}
1532
1522
1533
- function tryReadFile ( fileName : string , readFile : ( path : string ) => string | undefined ) : string | Diagnostic {
1523
+ /*@internal */
1524
+ export function tryReadFile ( fileName : string , readFile : ( path : string ) => string | undefined ) : string | Diagnostic {
1534
1525
let text : string | undefined ;
1535
1526
try {
1536
1527
text = readFile ( fileName ) ;
1537
1528
}
1538
1529
catch ( e ) {
1539
1530
return createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , e . message ) ;
1540
1531
}
1541
- return text === undefined ? createCompilerDiagnostic ( Diagnostics . The_specified_path_does_not_exist_Colon_0 , fileName ) : text ;
1532
+ return text === undefined ? createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0 , fileName ) : text ;
1542
1533
}
1543
1534
1544
1535
function commandLineOptionsToMap ( options : readonly CommandLineOption [ ] ) {
0 commit comments