@@ -248,6 +248,13 @@ namespace ts {
248
248
category : Diagnostics . Basic_Options ,
249
249
description : Diagnostics . Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir ,
250
250
} ,
251
+ {
252
+ name : "composite" ,
253
+ type : "boolean" ,
254
+ isTSConfigOnly : true ,
255
+ category : Diagnostics . Basic_Options ,
256
+ description : Diagnostics . Enable_project_compilation ,
257
+ } ,
251
258
{
252
259
name : "removeComments" ,
253
260
type : "boolean" ,
@@ -827,12 +834,14 @@ namespace ts {
827
834
export function parseCommandLine ( commandLine : ReadonlyArray < string > , readFile ?: ( path : string ) => string | undefined ) : ParsedCommandLine {
828
835
const options : CompilerOptions = { } ;
829
836
const fileNames : string [ ] = [ ] ;
837
+ const projectReferences : ProjectReference [ ] | undefined = undefined ;
830
838
const errors : Diagnostic [ ] = [ ] ;
831
839
832
840
parseStrings ( commandLine ) ;
833
841
return {
834
842
options,
835
843
fileNames,
844
+ projectReferences,
836
845
errors
837
846
} ;
838
847
@@ -946,6 +955,49 @@ namespace ts {
946
955
return optionNameMap . get ( optionName ) ;
947
956
}
948
957
958
+
959
+ export type DiagnosticReporter = ( diagnostic : Diagnostic ) => void ;
960
+ /**
961
+ * Reports config file diagnostics
962
+ */
963
+ export interface ConfigFileDiagnosticsReporter {
964
+ /**
965
+ * Reports unrecoverable error when parsing config file
966
+ */
967
+ onUnRecoverableConfigFileDiagnostic : DiagnosticReporter ;
968
+ }
969
+
970
+ /**
971
+ * Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors
972
+ */
973
+ export interface ParseConfigFileHost extends ParseConfigHost , ConfigFileDiagnosticsReporter {
974
+ getCurrentDirectory ( ) : string ;
975
+ }
976
+
977
+ /**
978
+ * Reads the config file, reports errors if any and exits if the config file cannot be found
979
+ */
980
+ export function getParsedCommandLineOfConfigFile ( configFileName : string , optionsToExtend : CompilerOptions , host : ParseConfigFileHost ) : ParsedCommandLine | undefined {
981
+ let configFileText : string ;
982
+ try {
983
+ configFileText = host . readFile ( configFileName ) ;
984
+ }
985
+ catch ( e ) {
986
+ const error = createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , configFileName , e . message ) ;
987
+ host . onUnRecoverableConfigFileDiagnostic ( error ) ;
988
+ return undefined ;
989
+ }
990
+ if ( ! configFileText ) {
991
+ const error = createCompilerDiagnostic ( Diagnostics . File_0_not_found , configFileName ) ;
992
+ host . onUnRecoverableConfigFileDiagnostic ( error ) ;
993
+ return undefined ;
994
+ }
995
+
996
+ const result = parseJsonText ( configFileName , configFileText ) ;
997
+ const cwd = host . getCurrentDirectory ( ) ;
998
+ return parseJsonSourceFileConfigFileContent ( result , host , getNormalizedAbsolutePath ( getDirectoryPath ( configFileName ) , cwd ) , optionsToExtend , getNormalizedAbsolutePath ( configFileName , cwd ) ) ;
999
+ }
1000
+
949
1001
/**
950
1002
* Read tsconfig.json file
951
1003
* @param fileName The path to the config file
@@ -1021,6 +1073,14 @@ namespace ts {
1021
1073
name : "extends" ,
1022
1074
type : "string"
1023
1075
} ,
1076
+ {
1077
+ name : "references" ,
1078
+ type : "list" ,
1079
+ element : {
1080
+ name : "references" ,
1081
+ type : "object"
1082
+ }
1083
+ } ,
1024
1084
{
1025
1085
name : "files" ,
1026
1086
type : "list" ,
@@ -1428,7 +1488,7 @@ namespace ts {
1428
1488
for ( let i = 0 ; i < nameColumn . length ; i ++ ) {
1429
1489
const optionName = nameColumn [ i ] ;
1430
1490
const description = descriptionColumn [ i ] ;
1431
- result . push ( optionName && `${ tab } ${ tab } ${ optionName } ${ description && ( makePadding ( marginLength - optionName . length + 2 ) + description ) } ` ) ;
1491
+ result . push ( optionName && `${ tab } ${ tab } ${ optionName } ${ description && ( makePadding ( marginLength - optionName . length + 2 ) + description ) } ` ) ;
1432
1492
}
1433
1493
if ( fileNames . length ) {
1434
1494
result . push ( `${ tab } },` ) ;
@@ -1512,12 +1572,13 @@ namespace ts {
1512
1572
const parsedConfig = parseConfig ( json , sourceFile , host , basePath , configFileName , resolutionStack , errors ) ;
1513
1573
const { raw } = parsedConfig ;
1514
1574
const options = extend ( existingOptions , parsedConfig . options || { } ) ;
1515
- options . configFilePath = configFileName ;
1575
+ options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
1516
1576
setConfigFileInOptions ( options , sourceFile ) ;
1517
- const { fileNames, wildcardDirectories, spec } = getFileNames ( ) ;
1577
+ const { fileNames, wildcardDirectories, spec, projectReferences } = getFileNames ( ) ;
1518
1578
return {
1519
1579
options,
1520
1580
fileNames,
1581
+ projectReferences,
1521
1582
typeAcquisition : parsedConfig . typeAcquisition || getDefaultTypeAcquisition ( ) ,
1522
1583
raw,
1523
1584
errors,
@@ -1571,10 +1632,33 @@ namespace ts {
1571
1632
}
1572
1633
1573
1634
const result = matchFileNames ( filesSpecs , includeSpecs , excludeSpecs , configFileName ? directoryOfCombinedPath ( configFileName , basePath ) : basePath , options , host , errors , extraFileExtensions , sourceFile ) ;
1574
- if ( result . fileNames . length === 0 && ! hasProperty ( raw , "files" ) && resolutionStack . length === 0 ) {
1635
+ if ( result . fileNames . length === 0 && ! hasProperty ( raw , "files" ) && resolutionStack . length === 0 && ! hasProperty ( raw , "references" ) ) {
1575
1636
errors . push ( getErrorForNoInputFiles ( result . spec , configFileName ) ) ;
1576
1637
}
1577
1638
1639
+ if ( hasProperty ( raw , "references" ) && ! isNullOrUndefined ( raw . references ) ) {
1640
+ if ( isArray ( raw . references ) ) {
1641
+ const references : ProjectReference [ ] = [ ] ;
1642
+ for ( const ref of raw . references ) {
1643
+ if ( typeof ref . path !== "string" ) {
1644
+ createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "reference.path" , "string" ) ;
1645
+ }
1646
+ else {
1647
+ references . push ( {
1648
+ path : getNormalizedAbsolutePath ( ref . path , basePath ) ,
1649
+ originalPath : ref . path ,
1650
+ prepend : ref . prepend ,
1651
+ circular : ref . circular
1652
+ } ) ;
1653
+ }
1654
+ }
1655
+ result . projectReferences = references ;
1656
+ }
1657
+ else {
1658
+ createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "references" , "Array" ) ;
1659
+ }
1660
+ }
1661
+
1578
1662
return result ;
1579
1663
}
1580
1664
@@ -1863,6 +1947,9 @@ namespace ts {
1863
1947
1864
1948
const options = getDefaultCompilerOptions ( configFileName ) ;
1865
1949
convertOptionsFromJson ( optionDeclarations , jsonOptions , basePath , options , Diagnostics . Unknown_compiler_option_0 , errors ) ;
1950
+ if ( configFileName ) {
1951
+ options . configFilePath = normalizeSlashes ( configFileName ) ;
1952
+ }
1866
1953
return options ;
1867
1954
}
1868
1955
@@ -2061,7 +2148,7 @@ namespace ts {
2061
2148
// new entries in these paths.
2062
2149
const wildcardDirectories = getWildcardDirectories ( validatedIncludeSpecs , validatedExcludeSpecs , basePath , host . useCaseSensitiveFileNames ) ;
2063
2150
2064
- const spec : ConfigFileSpecs = { filesSpecs, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories } ;
2151
+ const spec : ConfigFileSpecs = { filesSpecs, referencesSpecs : undefined , includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories } ;
2065
2152
return getFileNamesFromConfigSpecs ( spec , basePath , options , host , extraFileExtensions ) ;
2066
2153
}
2067
2154
@@ -2132,8 +2219,16 @@ namespace ts {
2132
2219
2133
2220
const literalFiles = arrayFrom ( literalFileMap . values ( ) ) ;
2134
2221
const wildcardFiles = arrayFrom ( wildcardFileMap . values ( ) ) ;
2222
+ const projectReferences = spec . referencesSpecs && spec . referencesSpecs . map ( ( r ) : ProjectReference => {
2223
+ return {
2224
+ ...r ,
2225
+ path : getNormalizedAbsolutePath ( r . path , basePath )
2226
+ } ;
2227
+ } ) ;
2228
+
2135
2229
return {
2136
2230
fileNames : literalFiles . concat ( wildcardFiles ) ,
2231
+ projectReferences,
2137
2232
wildcardDirectories,
2138
2233
spec
2139
2234
} ;
0 commit comments