@@ -7,7 +7,7 @@ namespace ts {
77 * The primary thing we track here is which files were written to,
88 * but unchanged, because this enables fast downstream updates
99 */
10- interface BuildContext {
10+ export interface BuildContext {
1111 options : BuildOptions ;
1212 /**
1313 * Map from output file name to its pre-build timestamp
@@ -299,6 +299,9 @@ namespace ts {
299299
300300 function parseConfigFile ( configFilePath : string ) {
301301 const sourceFile = host . getSourceFile ( configFilePath , ScriptTarget . JSON ) as JsonSourceFile ;
302+ if ( sourceFile === undefined ) {
303+ return undefined ;
304+ }
302305 const parsed = parseJsonSourceFileConfigFileContent ( sourceFile , configParseHost , getDirectoryPath ( configFilePath ) ) ;
303306 parsed . options . configFilePath = configFilePath ;
304307 cache . setValue ( configFilePath , parsed ) ;
@@ -322,7 +325,7 @@ namespace ts {
322325 return fileExtensionIs ( fileName , ".d.ts" ) ;
323326 }
324327
325- function createBuildContext ( options : BuildOptions ) : BuildContext {
328+ export function createBuildContext ( options : BuildOptions ) : BuildContext {
326329 const verboseDiag = options . verbose && createDiagnosticReporter ( sys , /*pretty*/ false ) ;
327330 return {
328331 options,
@@ -334,18 +337,15 @@ namespace ts {
334337 } ;
335338 }
336339
337- export function performBuild ( args : string [ ] ) {
338- const diagReporter = createDiagnosticReporter ( sys , /*pretty*/ true ) ;
339- const host = createCompilerHost ( { } ) ;
340-
340+ export function performBuild ( host : CompilerHost , reportDiagnostic : DiagnosticReporter , args : string [ ] ) {
341341 let verbose = false ;
342342 let dry = false ;
343343 let force = false ;
344344 let clean = false ;
345345
346346 const projects : string [ ] = [ ] ;
347- for ( let i = 0 ; i < args . length ; i ++ ) {
348- switch ( args [ i ] . toLowerCase ( ) ) {
347+ for ( const arg of args ) {
348+ switch ( arg . toLowerCase ( ) ) {
349349 case "-v" :
350350 case "--verbose" :
351351 verbose = true ;
@@ -363,7 +363,7 @@ namespace ts {
363363 continue ;
364364 }
365365 // Not a flag, parse as filename
366- addProject ( args [ i ] ) ;
366+ addProject ( arg ) ;
367367 }
368368
369369 if ( projects . length === 0 ) {
@@ -372,7 +372,7 @@ namespace ts {
372372 }
373373
374374 const context = createBuildContext ( { verbose, dry, force } ) ;
375- const builder = createSolutionBuilder ( host , context ) ;
375+ const builder = createSolutionBuilder ( host , reportDiagnostic , context ) ;
376376 if ( clean ) {
377377 builder . cleanProjects ( projects ) ;
378378 }
@@ -384,15 +384,14 @@ namespace ts {
384384 const fileName = resolvePath ( host . getCurrentDirectory ( ) , projectSpecification ) ;
385385 const refPath = resolveProjectReferencePath ( host , { path : fileName } ) ;
386386 if ( ! host . fileExists ( refPath ) ) {
387- diagReporter ( createCompilerDiagnostic ( Diagnostics . File_0_does_not_exist , fileName ) ) ;
387+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . File_0_does_not_exist , fileName ) ) ;
388388 }
389389 projects . push ( refPath ) ;
390390
391391 }
392392 }
393393
394- export function createSolutionBuilder ( host : CompilerHost , context : BuildContext ) {
395- const diagReporter = createDiagnosticReporter ( sys , /*pretty*/ true ) ;
394+ export function createSolutionBuilder ( host : CompilerHost , reportDiagnostic : DiagnosticReporter , context : BuildContext ) {
396395 const configFileCache = createConfigFileCache ( host ) ;
397396
398397 return {
@@ -418,7 +417,7 @@ namespace ts {
418417 else {
419418 const outputs : string [ ] = [ ] ;
420419 for ( const inputFile of project . fileNames ) {
421- ( outputs as string [ ] ) . push ( ...getOutputFileNames ( inputFile , project ) ) ;
420+ outputs . push ( ...getOutputFileNames ( inputFile , project ) ) ;
422421 }
423422 return outputs ;
424423 }
@@ -553,7 +552,8 @@ namespace ts {
553552 for ( const root of roots ) {
554553 const config = configFileCache . parseConfigFile ( root ) ;
555554 if ( config === undefined ) {
556- throw new Error ( `Could not parse ${ root } ` ) ;
555+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . File_0_does_not_exist , root ) ) ;
556+ continue ;
557557 }
558558 enumerateReferences ( normalizePath ( root ) , config ) ;
559559 }
@@ -564,7 +564,7 @@ namespace ts {
564564 dependencyMap
565565 } ;
566566
567- function enumerateReferences ( fileName : string , root : ts . ParsedCommandLine ) : void {
567+ function enumerateReferences ( fileName : string , root : ParsedCommandLine ) : void {
568568 const myBuildLevel = buildQueue [ buildQueuePosition ] = buildQueue [ buildQueuePosition ] || [ ] ;
569569 if ( myBuildLevel . indexOf ( fileName ) < 0 ) {
570570 myBuildLevel . push ( fileName ) ;
@@ -605,7 +605,7 @@ namespace ts {
605605 // TODO Accept parsedCommandLine
606606 function buildSingleProject ( proj : string ) {
607607 if ( context . options . dry ) {
608- diagReporter ( createCompilerDiagnostic ( Diagnostics . Would_build_project_0 , proj ) ) ;
608+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Would_build_project_0 , proj ) ) ;
609609 }
610610
611611 context . verbose ( Diagnostics . Building_project_0 , proj ) ;
@@ -627,18 +627,18 @@ namespace ts {
627627
628628 const programOptions : CreateProgramOptions = {
629629 projectReferences : configFile . projectReferences ,
630- host : host ,
630+ host,
631631 rootNames : configFile . fileNames ,
632632 options : configFile . options
633633 } ;
634- const program = ts . createProgram ( programOptions ) ;
634+ const program = createProgram ( programOptions ) ;
635635
636636 // Don't emit anything in the presence of syntactic errors or options diagnostics
637637 const syntaxDiagnostics = [ ...program . getOptionsDiagnostics ( ) , ...program . getSyntacticDiagnostics ( ) ] ;
638638 if ( syntaxDiagnostics . length ) {
639639 resultFlags |= BuildResultFlags . SyntaxErrors ;
640640 for ( const diag of syntaxDiagnostics ) {
641- diagReporter ( diag ) ;
641+ reportDiagnostic ( diag ) ;
642642 }
643643 return resultFlags ;
644644 }
@@ -649,7 +649,7 @@ namespace ts {
649649 if ( declDiagnostics . length ) {
650650 resultFlags |= BuildResultFlags . DeclarationEmitErrors ;
651651 for ( const diag of declDiagnostics ) {
652- diagReporter ( diag ) ;
652+ reportDiagnostic ( diag ) ;
653653 }
654654 return resultFlags ;
655655 }
@@ -659,13 +659,13 @@ namespace ts {
659659 if ( semanticDiagnostics . length ) {
660660 resultFlags |= BuildResultFlags . TypeErrors ;
661661 for ( const diag of semanticDiagnostics ) {
662- diagReporter ( diag ) ;
662+ reportDiagnostic ( diag ) ;
663663 }
664664 return resultFlags ;
665665 }
666666
667667 let newestDeclarationFileContentChangedTime = minimumDate ;
668- program . emit ( undefined , ( fileName , content , writeBom , onError ) => {
668+ program . emit ( /*targetSourceFile*/ undefined , ( fileName , content , writeBom , onError ) => {
669669 let priorChangeTime : Date | undefined ;
670670
671671 if ( isDeclarationFile ( fileName ) && host . fileExists ( fileName ) ) {
@@ -690,7 +690,7 @@ namespace ts {
690690
691691 function updateOutputTimestamps ( proj : ParsedCommandLine ) {
692692 if ( context . options . dry ) {
693- diagReporter ( createCompilerDiagnostic ( Diagnostics . Would_build_project_0 , proj . options . configFilePath ) ) ;
693+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Would_build_project_0 , proj . options . configFilePath ) ) ;
694694 return ;
695695 }
696696
@@ -731,13 +731,29 @@ namespace ts {
731731 }
732732
733733 if ( context . options . dry ) {
734- diagReporter ( createCompilerDiagnostic ( Diagnostics . Would_delete_the_following_files_Colon_0 , fileReport . map ( f => `\r\n * ${ f } ` ) . join ( "" ) ) ) ;
734+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . Would_delete_the_following_files_Colon_0 , fileReport . map ( f => `\r\n * ${ f } ` ) . join ( "" ) ) ) ;
735735 }
736736 }
737737
738738 function buildProjects ( configFileNames : string [ ] ) {
739+ const resolvedNames : string [ ] = [ ] ;
740+ for ( const name of configFileNames ) {
741+ let fullPath = resolvePath ( host . getCurrentDirectory ( ) , name ) ;
742+ if ( host . fileExists ( fullPath ) ) {
743+ resolvedNames . push ( fullPath ) ;
744+ continue ;
745+ }
746+ fullPath = combinePaths ( fullPath , "tsconfig.json" ) ;
747+ if ( host . fileExists ( fullPath ) ) {
748+ resolvedNames . push ( fullPath ) ;
749+ continue ;
750+ }
751+ reportDiagnostic ( createCompilerDiagnostic ( Diagnostics . File_0_not_found , fullPath ) ) ;
752+ return ;
753+ }
754+
739755 // Establish what needs to be built
740- const graph = createDependencyGraph ( configFileNames ) ;
756+ const graph = createDependencyGraph ( resolvedNames ) ;
741757
742758 const queue = graph . buildQueue ;
743759 reportBuildQueue ( graph ) ;
0 commit comments