@@ -67,19 +67,24 @@ namespace ts {
6767 }
6868
6969 export function createCompilerHost ( options : CompilerOptions , setParentNodes ?: boolean ) : CompilerHost {
70+ return createCompilerHostWorker ( options , setParentNodes ) ;
71+ }
72+ /*@internal */
73+ // TODO(shkamat): update this after reworking ts build API
74+ export function createCompilerHostWorker ( options : CompilerOptions , setParentNodes ?: boolean , system = sys ) : CompilerHost {
7075 const existingDirectories = createMap < boolean > ( ) ;
7176
7277 function getCanonicalFileName ( fileName : string ) : string {
7378 // if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
7479 // otherwise use toLowerCase as a canonical form.
75- return sys . useCaseSensitiveFileNames ? fileName : fileName . toLowerCase ( ) ;
80+ return system . useCaseSensitiveFileNames ? fileName : fileName . toLowerCase ( ) ;
7681 }
7782
7883 function getSourceFile ( fileName : string , languageVersion : ScriptTarget , onError ?: ( message : string ) => void ) : SourceFile | undefined {
7984 let text : string | undefined ;
8085 try {
8186 performance . mark ( "beforeIORead" ) ;
82- text = sys . readFile ( fileName , options . charset ) ;
87+ text = system . readFile ( fileName , options . charset ) ;
8388 performance . mark ( "afterIORead" ) ;
8489 performance . measure ( "I/O Read" , "beforeIORead" , "afterIORead" ) ;
8590 }
@@ -97,7 +102,7 @@ namespace ts {
97102 if ( existingDirectories . has ( directoryPath ) ) {
98103 return true ;
99104 }
100- if ( sys . directoryExists ( directoryPath ) ) {
105+ if ( system . directoryExists ( directoryPath ) ) {
101106 existingDirectories . set ( directoryPath , true ) ;
102107 return true ;
103108 }
@@ -108,7 +113,7 @@ namespace ts {
108113 if ( directoryPath . length > getRootLength ( directoryPath ) && ! directoryExists ( directoryPath ) ) {
109114 const parentDirectory = getDirectoryPath ( directoryPath ) ;
110115 ensureDirectoriesExist ( parentDirectory ) ;
111- sys . createDirectory ( directoryPath ) ;
116+ system . createDirectory ( directoryPath ) ;
112117 }
113118 }
114119
@@ -119,8 +124,8 @@ namespace ts {
119124 outputFingerprints = createMap < OutputFingerprint > ( ) ;
120125 }
121126
122- const hash = sys . createHash ! ( data ) ; // TODO: GH#18217
123- const mtimeBefore = sys . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
127+ const hash = system . createHash ! ( data ) ; // TODO: GH#18217
128+ const mtimeBefore = system . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
124129
125130 if ( mtimeBefore ) {
126131 const fingerprint = outputFingerprints . get ( fileName ) ;
@@ -133,9 +138,9 @@ namespace ts {
133138 }
134139 }
135140
136- sys . writeFile ( fileName , data , writeByteOrderMark ) ;
141+ system . writeFile ( fileName , data , writeByteOrderMark ) ;
137142
138- const mtimeAfter = sys . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
143+ const mtimeAfter = system . getModifiedTime ! ( fileName ) || missingFileModifiedTime ; // TODO: GH#18217
139144
140145 outputFingerprints . set ( fileName , {
141146 hash,
@@ -149,11 +154,11 @@ namespace ts {
149154 performance . mark ( "beforeIOWrite" ) ;
150155 ensureDirectoriesExist ( getDirectoryPath ( normalizePath ( fileName ) ) ) ;
151156
152- if ( isWatchSet ( options ) && sys . createHash && sys . getModifiedTime ) {
157+ if ( isWatchSet ( options ) && system . createHash && system . getModifiedTime ) {
153158 writeFileIfUpdated ( fileName , data , writeByteOrderMark ) ;
154159 }
155160 else {
156- sys . writeFile ( fileName , data , writeByteOrderMark ) ;
161+ system . writeFile ( fileName , data , writeByteOrderMark ) ;
157162 }
158163
159164 performance . mark ( "afterIOWrite" ) ;
@@ -167,32 +172,29 @@ namespace ts {
167172 }
168173
169174 function getDefaultLibLocation ( ) : string {
170- return getDirectoryPath ( normalizePath ( sys . getExecutingFilePath ( ) ) ) ;
175+ return getDirectoryPath ( normalizePath ( system . getExecutingFilePath ( ) ) ) ;
171176 }
172177
173- const newLine = getNewLineCharacter ( options ) ;
174- const realpath = sys . realpath && ( ( path : string ) => sys . realpath ! ( path ) ) ;
178+ const newLine = getNewLineCharacter ( options , ( ) => system . newLine ) ;
179+ const realpath = system . realpath && ( ( path : string ) => system . realpath ! ( path ) ) ;
175180
176181 return {
177182 getSourceFile,
178183 getDefaultLibLocation,
179184 getDefaultLibFileName : options => combinePaths ( getDefaultLibLocation ( ) , getDefaultLibFileName ( options ) ) ,
180185 writeFile,
181- getCurrentDirectory : memoize ( ( ) => sys . getCurrentDirectory ( ) ) ,
182- useCaseSensitiveFileNames : ( ) => sys . useCaseSensitiveFileNames ,
186+ getCurrentDirectory : memoize ( ( ) => system . getCurrentDirectory ( ) ) ,
187+ useCaseSensitiveFileNames : ( ) => system . useCaseSensitiveFileNames ,
183188 getCanonicalFileName,
184189 getNewLine : ( ) => newLine ,
185- fileExists : fileName => sys . fileExists ( fileName ) ,
186- readFile : fileName => sys . readFile ( fileName ) ,
187- trace : ( s : string ) => sys . write ( s + newLine ) ,
188- directoryExists : directoryName => sys . directoryExists ( directoryName ) ,
189- getEnvironmentVariable : name => sys . getEnvironmentVariable ? sys . getEnvironmentVariable ( name ) : "" ,
190- getDirectories : ( path : string ) => sys . getDirectories ( path ) ,
190+ fileExists : fileName => system . fileExists ( fileName ) ,
191+ readFile : fileName => system . readFile ( fileName ) ,
192+ trace : ( s : string ) => system . write ( s + newLine ) ,
193+ directoryExists : directoryName => system . directoryExists ( directoryName ) ,
194+ getEnvironmentVariable : name => system . getEnvironmentVariable ? system . getEnvironmentVariable ( name ) : "" ,
195+ getDirectories : ( path : string ) => system . getDirectories ( path ) ,
191196 realpath,
192- readDirectory : ( path , extensions , include , exclude , depth ) => sys . readDirectory ( path , extensions , include , exclude , depth ) ,
193- getModifiedTime : sys . getModifiedTime && ( path => sys . getModifiedTime ! ( path ) ) ,
194- setModifiedTime : sys . setModifiedTime && ( ( path , date ) => sys . setModifiedTime ! ( path , date ) ) ,
195- deleteFile : sys . deleteFile && ( path => sys . deleteFile ! ( path ) )
197+ readDirectory : ( path , extensions , include , exclude , depth ) => system . readDirectory ( path , extensions , include , exclude , depth )
196198 } ;
197199 }
198200
0 commit comments