@@ -299,6 +299,7 @@ namespace ts.tscWatch {
299
299
}
300
300
export interface TscWatchCheckOptions {
301
301
baselineSourceMap ?: boolean ;
302
+ baselineDependencies ?: boolean ;
302
303
}
303
304
export interface TscWatchCompileBase extends TscWatchCheckOptions {
304
305
scenario : string ;
@@ -323,7 +324,7 @@ namespace ts.tscWatch {
323
324
const {
324
325
scenario, subScenario,
325
326
commandLineArgs, changes,
326
- baselineSourceMap
327
+ baselineSourceMap, baselineDependencies
327
328
} = input ;
328
329
329
330
if ( ! isWatch ( commandLineArgs ) ) sys . exit = exitCode => sys . exitCode = exitCode ;
@@ -342,6 +343,7 @@ namespace ts.tscWatch {
342
343
oldSnap,
343
344
getPrograms,
344
345
baselineSourceMap,
346
+ baselineDependencies,
345
347
changes,
346
348
watchOrSolution
347
349
} ) ;
@@ -381,7 +383,7 @@ namespace ts.tscWatch {
381
383
export function runWatchBaseline ( {
382
384
scenario, subScenario, commandLineArgs,
383
385
getPrograms, sys, baseline, oldSnap,
384
- baselineSourceMap,
386
+ baselineSourceMap, baselineDependencies ,
385
387
changes, watchOrSolution
386
388
} : RunWatchBaseline ) {
387
389
baseline . push ( `${ sys . getExecutingFilePath ( ) } ${ commandLineArgs . join ( " " ) } ` ) ;
@@ -390,7 +392,8 @@ namespace ts.tscWatch {
390
392
getPrograms,
391
393
sys,
392
394
oldSnap,
393
- baselineSourceMap
395
+ baselineSourceMap,
396
+ baselineDependencies,
394
397
} ) ;
395
398
396
399
for ( const { caption, change, timeouts } of changes ) {
@@ -401,7 +404,8 @@ namespace ts.tscWatch {
401
404
getPrograms,
402
405
sys,
403
406
oldSnap,
404
- baselineSourceMap
407
+ baselineSourceMap,
408
+ baselineDependencies,
405
409
} ) ;
406
410
}
407
411
Harness . Baseline . runBaseline ( `${ isBuild ( commandLineArgs ) ?
@@ -420,10 +424,10 @@ namespace ts.tscWatch {
420
424
export interface WatchBaseline extends Baseline , TscWatchCheckOptions {
421
425
getPrograms : ( ) => readonly CommandLineProgram [ ] ;
422
426
}
423
- export function watchBaseline ( { baseline, getPrograms, sys, oldSnap, baselineSourceMap } : WatchBaseline ) {
427
+ export function watchBaseline ( { baseline, getPrograms, sys, oldSnap, baselineSourceMap, baselineDependencies } : WatchBaseline ) {
424
428
if ( baselineSourceMap ) generateSourceMapBaselineFiles ( sys ) ;
425
429
sys . serializeOutput ( baseline ) ;
426
- const programs = baselinePrograms ( baseline , getPrograms ) ;
430
+ const programs = baselinePrograms ( baseline , getPrograms , baselineDependencies ) ;
427
431
sys . serializeWatches ( baseline ) ;
428
432
baseline . push ( `exitCode:: ExitStatus.${ ExitStatus [ sys . exitCode as ExitStatus ] } ` , "" ) ;
429
433
sys . diff ( baseline , oldSnap ) ;
@@ -434,15 +438,15 @@ namespace ts.tscWatch {
434
438
return programs ;
435
439
}
436
440
437
- export function baselinePrograms ( baseline : string [ ] , getPrograms : ( ) => readonly CommandLineProgram [ ] ) {
441
+ export function baselinePrograms ( baseline : string [ ] , getPrograms : ( ) => readonly CommandLineProgram [ ] , baselineDependencies : boolean | undefined ) {
438
442
const programs = getPrograms ( ) ;
439
443
for ( const program of programs ) {
440
- baselineProgram ( baseline , program ) ;
444
+ baselineProgram ( baseline , program , baselineDependencies ) ;
441
445
}
442
446
return programs ;
443
447
}
444
448
445
- function baselineProgram ( baseline : string [ ] , [ program , builderProgram ] : CommandLineProgram ) {
449
+ function baselineProgram ( baseline : string [ ] , [ program , builderProgram ] : CommandLineProgram , baselineDependencies : boolean | undefined ) {
446
450
const options = program . getCompilerOptions ( ) ;
447
451
baseline . push ( `Program root files: ${ JSON . stringify ( program . getRootFileNames ( ) ) } ` ) ;
448
452
baseline . push ( `Program options: ${ JSON . stringify ( options ) } ` ) ;
@@ -466,6 +470,15 @@ namespace ts.tscWatch {
466
470
baseline . push ( "No cached semantic diagnostics in the builder::" ) ;
467
471
}
468
472
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 ( "" ) ;
469
482
}
470
483
471
484
export interface VerifyTscWatch extends TscWatchCompile {
@@ -492,4 +505,31 @@ namespace ts.tscWatch {
492
505
const content = Debug . checkDefined ( sys . readFile ( file ) ) ;
493
506
sys . writeFile ( file , content . replace ( searchValue , replaceValue ) ) ;
494
507
}
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
+ }
495
535
}
0 commit comments