@@ -299,6 +299,7 @@ namespace ts.tscWatch {
299299 }
300300 export interface TscWatchCheckOptions {
301301 baselineSourceMap ?: boolean ;
302+ baselineDependencies ?: boolean ;
302303 }
303304 export interface TscWatchCompileBase extends TscWatchCheckOptions {
304305 scenario : string ;
@@ -323,7 +324,7 @@ namespace ts.tscWatch {
323324 const {
324325 scenario, subScenario,
325326 commandLineArgs, changes,
326- baselineSourceMap
327+ baselineSourceMap, baselineDependencies
327328 } = input ;
328329
329330 if ( ! isWatch ( commandLineArgs ) ) sys . exit = exitCode => sys . exitCode = exitCode ;
@@ -342,6 +343,7 @@ namespace ts.tscWatch {
342343 oldSnap,
343344 getPrograms,
344345 baselineSourceMap,
346+ baselineDependencies,
345347 changes,
346348 watchOrSolution
347349 } ) ;
@@ -381,7 +383,7 @@ namespace ts.tscWatch {
381383 export function runWatchBaseline ( {
382384 scenario, subScenario, commandLineArgs,
383385 getPrograms, sys, baseline, oldSnap,
384- baselineSourceMap,
386+ baselineSourceMap, baselineDependencies ,
385387 changes, watchOrSolution
386388 } : RunWatchBaseline ) {
387389 baseline . push ( `${ sys . getExecutingFilePath ( ) } ${ commandLineArgs . join ( " " ) } ` ) ;
@@ -390,7 +392,8 @@ namespace ts.tscWatch {
390392 getPrograms,
391393 sys,
392394 oldSnap,
393- baselineSourceMap
395+ baselineSourceMap,
396+ baselineDependencies,
394397 } ) ;
395398
396399 for ( const { caption, change, timeouts } of changes ) {
@@ -401,7 +404,8 @@ namespace ts.tscWatch {
401404 getPrograms,
402405 sys,
403406 oldSnap,
404- baselineSourceMap
407+ baselineSourceMap,
408+ baselineDependencies,
405409 } ) ;
406410 }
407411 Harness . Baseline . runBaseline ( `${ isBuild ( commandLineArgs ) ?
@@ -420,10 +424,10 @@ namespace ts.tscWatch {
420424 export interface WatchBaseline extends Baseline , TscWatchCheckOptions {
421425 getPrograms : ( ) => readonly CommandLineProgram [ ] ;
422426 }
423- export function watchBaseline ( { baseline, getPrograms, sys, oldSnap, baselineSourceMap } : WatchBaseline ) {
427+ export function watchBaseline ( { baseline, getPrograms, sys, oldSnap, baselineSourceMap, baselineDependencies } : WatchBaseline ) {
424428 if ( baselineSourceMap ) generateSourceMapBaselineFiles ( sys ) ;
425429 sys . serializeOutput ( baseline ) ;
426- const programs = baselinePrograms ( baseline , getPrograms ) ;
430+ const programs = baselinePrograms ( baseline , getPrograms , baselineDependencies ) ;
427431 sys . serializeWatches ( baseline ) ;
428432 baseline . push ( `exitCode:: ExitStatus.${ ExitStatus [ sys . exitCode as ExitStatus ] } ` , "" ) ;
429433 sys . diff ( baseline , oldSnap ) ;
@@ -434,15 +438,15 @@ namespace ts.tscWatch {
434438 return programs ;
435439 }
436440
437- export function baselinePrograms ( baseline : string [ ] , getPrograms : ( ) => readonly CommandLineProgram [ ] ) {
441+ export function baselinePrograms ( baseline : string [ ] , getPrograms : ( ) => readonly CommandLineProgram [ ] , baselineDependencies : boolean | undefined ) {
438442 const programs = getPrograms ( ) ;
439443 for ( const program of programs ) {
440- baselineProgram ( baseline , program ) ;
444+ baselineProgram ( baseline , program , baselineDependencies ) ;
441445 }
442446 return programs ;
443447 }
444448
445- function baselineProgram ( baseline : string [ ] , [ program , builderProgram ] : CommandLineProgram ) {
449+ function baselineProgram ( baseline : string [ ] , [ program , builderProgram ] : CommandLineProgram , baselineDependencies : boolean | undefined ) {
446450 const options = program . getCompilerOptions ( ) ;
447451 baseline . push ( `Program root files: ${ JSON . stringify ( program . getRootFileNames ( ) ) } ` ) ;
448452 baseline . push ( `Program options: ${ JSON . stringify ( options ) } ` ) ;
@@ -466,6 +470,15 @@ namespace ts.tscWatch {
466470 baseline . push ( "No cached semantic diagnostics in the builder::" ) ;
467471 }
468472 baseline . push ( "" ) ;
473+ if ( ! baselineDependencies ) return ;
474+ baseline . push ( "Dependencies for::" ) ;
475+ for ( const file of builderProgram . getSourceFiles ( ) ) {
476+ baseline . push ( `${ file . fileName } :` ) ;
477+ for ( const depenedency of builderProgram . getAllDependencies ( file ) ) {
478+ baseline . push ( ` ${ depenedency } ` ) ;
479+ }
480+ }
481+ baseline . push ( "" ) ;
469482 }
470483
471484 export interface VerifyTscWatch extends TscWatchCompile {
@@ -492,4 +505,31 @@ namespace ts.tscWatch {
492505 const content = Debug . checkDefined ( sys . readFile ( file ) ) ;
493506 sys . writeFile ( file , content . replace ( searchValue , replaceValue ) ) ;
494507 }
508+
509+ export function createSolutionBuilder ( system : WatchedSystem , rootNames : readonly string [ ] , defaultOptions ?: BuildOptions ) {
510+ const host = createSolutionBuilderHost ( system ) ;
511+ return ts . createSolutionBuilder ( host , rootNames , defaultOptions || { } ) ;
512+ }
513+
514+ export function ensureErrorFreeBuild ( host : WatchedSystem , rootNames : readonly string [ ] ) {
515+ // ts build should succeed
516+ const solutionBuilder = createSolutionBuilder ( host , rootNames , { } ) ;
517+ solutionBuilder . build ( ) ;
518+ assert . equal ( host . getOutput ( ) . length , 0 , JSON . stringify ( host . getOutput ( ) , /*replacer*/ undefined , " " ) ) ;
519+ }
520+
521+ export function createSystemWithSolutionBuild ( solutionRoots : readonly string [ ] , files : readonly TestFSWithWatch . FileOrFolderOrSymLink [ ] , params ?: TestFSWithWatch . TestServerHostCreationParameters ) {
522+ const sys = createWatchedSystem ( files , params ) ;
523+ const originalReadFile = sys . readFile ;
524+ const originalWrite = sys . write ;
525+ const originalWriteFile = sys . writeFile ;
526+ const solutionBuilder = createSolutionBuilder ( TestFSWithWatch . changeToHostTrackingWrittenFiles (
527+ fakes . patchHostForBuildInfoReadWrite ( sys )
528+ ) , solutionRoots , { } ) ;
529+ solutionBuilder . build ( ) ;
530+ sys . readFile = originalReadFile ;
531+ sys . write = originalWrite ;
532+ sys . writeFile = originalWriteFile ;
533+ return sys ;
534+ }
495535}
0 commit comments