@@ -235,6 +235,13 @@ namespace ts {
235
235
category : Diagnostics . Basic_Options ,
236
236
description : Diagnostics . Specify_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir ,
237
237
} ,
238
+ {
239
+ name : "composite" ,
240
+ type : "boolean" ,
241
+ isTSConfigOnly : true ,
242
+ category : Diagnostics . Basic_Options ,
243
+ description : Diagnostics . Enable_project_compilation ,
244
+ } ,
238
245
{
239
246
name : "removeComments" ,
240
247
type : "boolean" ,
@@ -814,12 +821,14 @@ namespace ts {
814
821
export function parseCommandLine ( commandLine : ReadonlyArray < string > , readFile ?: ( path : string ) => string | undefined ) : ParsedCommandLine {
815
822
const options : CompilerOptions = { } ;
816
823
const fileNames : string [ ] = [ ] ;
824
+ const projectReferences : ProjectReference [ ] | undefined = undefined ;
817
825
const errors : Diagnostic [ ] = [ ] ;
818
826
819
827
parseStrings ( commandLine ) ;
820
828
return {
821
829
options,
822
830
fileNames,
831
+ projectReferences,
823
832
errors
824
833
} ;
825
834
@@ -933,6 +942,49 @@ namespace ts {
933
942
return optionNameMap . get ( optionName ) ;
934
943
}
935
944
945
+
946
+ export type DiagnosticReporter = ( diagnostic : Diagnostic ) => void ;
947
+ /**
948
+ * Reports config file diagnostics
949
+ */
950
+ export interface ConfigFileDiagnosticsReporter {
951
+ /**
952
+ * Reports unrecoverable error when parsing config file
953
+ */
954
+ onUnRecoverableConfigFileDiagnostic : DiagnosticReporter ;
955
+ }
956
+
957
+ /**
958
+ * Interface extending ParseConfigHost to support ParseConfigFile that reads config file and reports errors
959
+ */
960
+ export interface ParseConfigFileHost extends ParseConfigHost , ConfigFileDiagnosticsReporter {
961
+ getCurrentDirectory ( ) : string ;
962
+ }
963
+
964
+ /**
965
+ * Reads the config file, reports errors if any and exits if the config file cannot be found
966
+ */
967
+ export function getParsedCommandLineOfConfigFile ( configFileName : string , optionsToExtend : CompilerOptions , host : ParseConfigFileHost ) : ParsedCommandLine | undefined {
968
+ let configFileText : string ;
969
+ try {
970
+ configFileText = host . readFile ( configFileName ) ;
971
+ }
972
+ catch ( e ) {
973
+ const error = createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , configFileName , e . message ) ;
974
+ host . onUnRecoverableConfigFileDiagnostic ( error ) ;
975
+ return undefined ;
976
+ }
977
+ if ( ! configFileText ) {
978
+ const error = createCompilerDiagnostic ( Diagnostics . File_0_not_found , configFileName ) ;
979
+ host . onUnRecoverableConfigFileDiagnostic ( error ) ;
980
+ return undefined ;
981
+ }
982
+
983
+ const result = parseJsonText ( configFileName , configFileText ) ;
984
+ const cwd = host . getCurrentDirectory ( ) ;
985
+ return parseJsonSourceFileConfigFileContent ( result , host , getNormalizedAbsolutePath ( getDirectoryPath ( configFileName ) , cwd ) , optionsToExtend , getNormalizedAbsolutePath ( configFileName , cwd ) ) ;
986
+ }
987
+
936
988
/**
937
989
* Read tsconfig.json file
938
990
* @param fileName The path to the config file
@@ -1008,6 +1060,14 @@ namespace ts {
1008
1060
name : "extends" ,
1009
1061
type : "string"
1010
1062
} ,
1063
+ {
1064
+ name : "references" ,
1065
+ type : "list" ,
1066
+ element : {
1067
+ name : "references" ,
1068
+ type : "object"
1069
+ }
1070
+ } ,
1011
1071
{
1012
1072
name : "files" ,
1013
1073
type : "list" ,
@@ -1415,7 +1475,7 @@ namespace ts {
1415
1475
for ( let i = 0 ; i < nameColumn . length ; i ++ ) {
1416
1476
const optionName = nameColumn [ i ] ;
1417
1477
const description = descriptionColumn [ i ] ;
1418
- result . push ( optionName && `${ tab } ${ tab } ${ optionName } ${ description && ( makePadding ( marginLength - optionName . length + 2 ) + description ) } ` ) ;
1478
+ result . push ( optionName && `${ tab } ${ tab } ${ optionName } ${ description && ( makePadding ( marginLength - optionName . length + 2 ) + description ) } ` ) ;
1419
1479
}
1420
1480
if ( fileNames . length ) {
1421
1481
result . push ( `${ tab } },` ) ;
@@ -1499,12 +1559,13 @@ namespace ts {
1499
1559
const parsedConfig = parseConfig ( json , sourceFile , host , basePath , configFileName , resolutionStack , errors ) ;
1500
1560
const { raw } = parsedConfig ;
1501
1561
const options = extend ( existingOptions , parsedConfig . options || { } ) ;
1502
- options . configFilePath = configFileName ;
1562
+ options . configFilePath = configFileName && normalizeSlashes ( configFileName ) ;
1503
1563
setConfigFileInOptions ( options , sourceFile ) ;
1504
- const { fileNames, wildcardDirectories, spec } = getFileNames ( ) ;
1564
+ const { fileNames, wildcardDirectories, spec, projectReferences } = getFileNames ( ) ;
1505
1565
return {
1506
1566
options,
1507
1567
fileNames,
1568
+ projectReferences,
1508
1569
typeAcquisition : parsedConfig . typeAcquisition || getDefaultTypeAcquisition ( ) ,
1509
1570
raw,
1510
1571
errors,
@@ -1558,10 +1619,33 @@ namespace ts {
1558
1619
}
1559
1620
1560
1621
const result = matchFileNames ( filesSpecs , includeSpecs , excludeSpecs , configFileName ? directoryOfCombinedPath ( configFileName , basePath ) : basePath , options , host , errors , extraFileExtensions , sourceFile ) ;
1561
- if ( result . fileNames . length === 0 && ! hasProperty ( raw , "files" ) && resolutionStack . length === 0 ) {
1622
+ if ( result . fileNames . length === 0 && ! hasProperty ( raw , "files" ) && resolutionStack . length === 0 && ! hasProperty ( raw , "references" ) ) {
1562
1623
errors . push ( getErrorForNoInputFiles ( result . spec , configFileName ) ) ;
1563
1624
}
1564
1625
1626
+ if ( hasProperty ( raw , "references" ) && ! isNullOrUndefined ( raw . references ) ) {
1627
+ if ( isArray ( raw . references ) ) {
1628
+ const references : ProjectReference [ ] = [ ] ;
1629
+ for ( const ref of raw . references ) {
1630
+ if ( typeof ref . path !== "string" ) {
1631
+ createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "reference.path" , "string" ) ;
1632
+ }
1633
+ else {
1634
+ references . push ( {
1635
+ path : getNormalizedAbsolutePath ( ref . path , basePath ) ,
1636
+ originalPath : ref . path ,
1637
+ prepend : ref . prepend ,
1638
+ circular : ref . circular
1639
+ } ) ;
1640
+ }
1641
+ }
1642
+ result . projectReferences = references ;
1643
+ }
1644
+ else {
1645
+ createCompilerDiagnosticOnlyIfJson ( Diagnostics . Compiler_option_0_requires_a_value_of_type_1 , "references" , "Array" ) ;
1646
+ }
1647
+ }
1648
+
1565
1649
return result ;
1566
1650
}
1567
1651
@@ -1850,6 +1934,9 @@ namespace ts {
1850
1934
1851
1935
const options = getDefaultCompilerOptions ( configFileName ) ;
1852
1936
convertOptionsFromJson ( optionDeclarations , jsonOptions , basePath , options , Diagnostics . Unknown_compiler_option_0 , errors ) ;
1937
+ if ( configFileName ) {
1938
+ options . configFilePath = normalizeSlashes ( configFileName ) ;
1939
+ }
1853
1940
return options ;
1854
1941
}
1855
1942
@@ -2048,7 +2135,7 @@ namespace ts {
2048
2135
// new entries in these paths.
2049
2136
const wildcardDirectories = getWildcardDirectories ( validatedIncludeSpecs , validatedExcludeSpecs , basePath , host . useCaseSensitiveFileNames ) ;
2050
2137
2051
- const spec : ConfigFileSpecs = { filesSpecs, includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories } ;
2138
+ const spec : ConfigFileSpecs = { filesSpecs, referencesSpecs : undefined , includeSpecs, excludeSpecs, validatedIncludeSpecs, validatedExcludeSpecs, wildcardDirectories } ;
2052
2139
return getFileNamesFromConfigSpecs ( spec , basePath , options , host , extraFileExtensions ) ;
2053
2140
}
2054
2141
@@ -2119,8 +2206,16 @@ namespace ts {
2119
2206
2120
2207
const literalFiles = arrayFrom ( literalFileMap . values ( ) ) ;
2121
2208
const wildcardFiles = arrayFrom ( wildcardFileMap . values ( ) ) ;
2209
+ const projectReferences = spec . referencesSpecs && spec . referencesSpecs . map ( ( r ) : ProjectReference => {
2210
+ return {
2211
+ ...r ,
2212
+ path : getNormalizedAbsolutePath ( r . path , basePath )
2213
+ } ;
2214
+ } ) ;
2215
+
2122
2216
return {
2123
2217
fileNames : literalFiles . concat ( wildcardFiles ) ,
2218
+ projectReferences,
2124
2219
wildcardDirectories,
2125
2220
spec
2126
2221
} ;
0 commit comments