1
+ import * as fakes from "../../_namespaces/fakes" ;
2
+ import * as ts from "../../_namespaces/ts" ;
3
+ import { commandLineCallbacks } from "./baseline" ;
4
+ import {
5
+ makeSystemReadyForBaseline ,
6
+ TscCompileSystem ,
7
+ } from "./tsc" ;
8
+ import {
9
+ changeToHostTrackingWrittenFiles ,
10
+ createWatchedSystem ,
11
+ FileOrFolderOrSymLink ,
12
+ FileOrFolderOrSymLinkMap ,
13
+ TestServerHost ,
14
+ TestServerHostCreationParameters ,
15
+ } from "./virtualFileSystemWithWatch" ;
16
+
17
+ export function createSolutionBuilderHostForBaseline (
18
+ sys : TscCompileSystem | TestServerHost ,
19
+ versionToWrite ?: string ,
20
+ originalRead ?: ( TscCompileSystem | TestServerHost ) [ "readFile" ]
21
+ ) {
22
+ if ( sys instanceof fakes . System ) makeSystemReadyForBaseline ( sys , versionToWrite ) ;
23
+ const { cb } = commandLineCallbacks ( sys , originalRead ) ;
24
+ const host = ts . createSolutionBuilderHost ( sys ,
25
+ /*createProgram*/ undefined ,
26
+ ts . createDiagnosticReporter ( sys , /*pretty*/ true ) ,
27
+ ts . createBuilderStatusReporter ( sys , /*pretty*/ true )
28
+ ) ;
29
+ host . afterProgramEmitAndDiagnostics = cb ;
30
+ host . afterEmitBundle = cb ;
31
+ return host ;
32
+ }
33
+
34
+ export function createSolutionBuilder ( system : TestServerHost , rootNames : readonly string [ ] , originalRead ?: TestServerHost [ "readFile" ] ) {
35
+ const host = createSolutionBuilderHostForBaseline ( system , /*versionToWrite*/ undefined , originalRead ) ;
36
+ return ts . createSolutionBuilder ( host , rootNames , { } ) ;
37
+ }
38
+
39
+ export function ensureErrorFreeBuild ( host : TestServerHost , rootNames : readonly string [ ] ) {
40
+ // ts build should succeed
41
+ solutionBuildWithBaseline ( host , rootNames ) ;
42
+ assert . equal ( host . getOutput ( ) . length , 0 , JSON . stringify ( host . getOutput ( ) , /*replacer*/ undefined , " " ) ) ;
43
+ }
44
+
45
+ export function solutionBuildWithBaseline ( sys : TestServerHost , solutionRoots : readonly string [ ] , originalRead ?: TestServerHost [ "readFile" ] ) {
46
+ const originalReadFile = sys . readFile ;
47
+ const originalWrite = sys . write ;
48
+ const originalWriteFile = sys . writeFile ;
49
+ ts . Debug . assert ( sys . writtenFiles === undefined ) ;
50
+ const solutionBuilder = createSolutionBuilder ( changeToHostTrackingWrittenFiles (
51
+ fakes . patchHostForBuildInfoReadWrite ( sys )
52
+ ) , solutionRoots , originalRead ) ;
53
+ solutionBuilder . build ( ) ;
54
+ sys . readFile = originalReadFile ;
55
+ sys . write = originalWrite ;
56
+ sys . writeFile = originalWriteFile ;
57
+ sys . writtenFiles = undefined ;
58
+ return sys ;
59
+ }
60
+
61
+ export function createSystemWithSolutionBuild ( solutionRoots : readonly string [ ] , files : FileOrFolderOrSymLinkMap | readonly FileOrFolderOrSymLink [ ] , params ?: TestServerHostCreationParameters ) {
62
+ return solutionBuildWithBaseline ( createWatchedSystem ( files , params ) , solutionRoots ) ;
63
+ }
0 commit comments