@@ -66,20 +66,20 @@ namespace ts {
66
66
mtime : Date ;
67
67
}
68
68
69
- export function createCompilerHost ( options : CompilerOptions , setParentNodes ?: boolean ) : CompilerHost {
69
+ export function createCompilerHost ( options : CompilerOptions , setParentNodes ?: boolean , system = sys ) : CompilerHost {
70
70
const existingDirectories = createMap < boolean > ( ) ;
71
71
72
72
function getCanonicalFileName ( fileName : string ) : string {
73
73
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
74
74
// otherwise use toLowerCase as a canonical form.
75
- return sys . useCaseSensitiveFileNames ? fileName : fileName . toLowerCase ( ) ;
75
+ return system . useCaseSensitiveFileNames ? fileName : fileName . toLowerCase ( ) ;
76
76
}
77
77
78
78
function getSourceFile ( fileName : string , languageVersion : ScriptTarget , onError ?: ( message : string ) => void ) : SourceFile | undefined {
79
79
let text : string | undefined ;
80
80
try {
81
81
performance . mark ( "beforeIORead" ) ;
82
- text = sys . readFile ( fileName , options . charset ) ;
82
+ text = system . readFile ( fileName , options . charset ) ;
83
83
performance . mark ( "afterIORead" ) ;
84
84
performance . measure ( "I/O Read" , "beforeIORead" , "afterIORead" ) ;
85
85
}
@@ -97,7 +97,7 @@ namespace ts {
97
97
if ( existingDirectories . has ( directoryPath ) ) {
98
98
return true ;
99
99
}
100
- if ( sys . directoryExists ( directoryPath ) ) {
100
+ if ( system . directoryExists ( directoryPath ) ) {
101
101
existingDirectories . set ( directoryPath , true ) ;
102
102
return true ;
103
103
}
@@ -108,7 +108,7 @@ namespace ts {
108
108
if ( directoryPath . length > getRootLength ( directoryPath ) && ! directoryExists ( directoryPath ) ) {
109
109
const parentDirectory = getDirectoryPath ( directoryPath ) ;
110
110
ensureDirectoriesExist ( parentDirectory ) ;
111
- sys . createDirectory ( directoryPath ) ;
111
+ system . createDirectory ( directoryPath ) ;
112
112
}
113
113
}
114
114
@@ -119,8 +119,8 @@ namespace ts {
119
119
outputFingerprints = createMap < OutputFingerprint > ( ) ;
120
120
}
121
121
122
- const hash = sys . createHash ! ( data ) ; // TODO: GH#18217
123
- const mtimeBefore = sys . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
122
+ const hash = system . createHash ! ( data ) ; // TODO: GH#18217
123
+ const mtimeBefore = system . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
124
124
125
125
if ( mtimeBefore ) {
126
126
const fingerprint = outputFingerprints . get ( fileName ) ;
@@ -133,9 +133,9 @@ namespace ts {
133
133
}
134
134
}
135
135
136
- sys . writeFile ( fileName , data , writeByteOrderMark ) ;
136
+ system . writeFile ( fileName , data , writeByteOrderMark ) ;
137
137
138
- const mtimeAfter = sys . getModifiedTime ! ( fileName ) || missingFileModifiedTime ; // TODO: GH#18217
138
+ const mtimeAfter = system . getModifiedTime ! ( fileName ) || missingFileModifiedTime ; // TODO: GH#18217
139
139
140
140
outputFingerprints . set ( fileName , {
141
141
hash,
@@ -149,11 +149,11 @@ namespace ts {
149
149
performance . mark ( "beforeIOWrite" ) ;
150
150
ensureDirectoriesExist ( getDirectoryPath ( normalizePath ( fileName ) ) ) ;
151
151
152
- if ( isWatchSet ( options ) && sys . createHash && sys . getModifiedTime ) {
152
+ if ( isWatchSet ( options ) && system . createHash && system . getModifiedTime ) {
153
153
writeFileIfUpdated ( fileName , data , writeByteOrderMark ) ;
154
154
}
155
155
else {
156
- sys . writeFile ( fileName , data , writeByteOrderMark ) ;
156
+ system . writeFile ( fileName , data , writeByteOrderMark ) ;
157
157
}
158
158
159
159
performance . mark ( "afterIOWrite" ) ;
@@ -167,32 +167,32 @@ namespace ts {
167
167
}
168
168
169
169
function getDefaultLibLocation ( ) : string {
170
- return getDirectoryPath ( normalizePath ( sys . getExecutingFilePath ( ) ) ) ;
170
+ return getDirectoryPath ( normalizePath ( system . getExecutingFilePath ( ) ) ) ;
171
171
}
172
172
173
173
const newLine = getNewLineCharacter ( options ) ;
174
- const realpath = sys . realpath && ( ( path : string ) => sys . realpath ! ( path ) ) ;
174
+ const realpath = system . realpath && ( ( path : string ) => system . realpath ! ( path ) ) ;
175
175
176
176
return {
177
177
getSourceFile,
178
178
getDefaultLibLocation,
179
179
getDefaultLibFileName : options => combinePaths ( getDefaultLibLocation ( ) , getDefaultLibFileName ( options ) ) ,
180
180
writeFile,
181
- getCurrentDirectory : memoize ( ( ) => sys . getCurrentDirectory ( ) ) ,
182
- useCaseSensitiveFileNames : ( ) => sys . useCaseSensitiveFileNames ,
181
+ getCurrentDirectory : memoize ( ( ) => system . getCurrentDirectory ( ) ) ,
182
+ useCaseSensitiveFileNames : ( ) => system . useCaseSensitiveFileNames ,
183
183
getCanonicalFileName,
184
184
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 ) ,
185
+ fileExists : fileName => system . fileExists ( fileName ) ,
186
+ readFile : fileName => system . readFile ( fileName ) ,
187
+ trace : ( s : string ) => system . write ( s + newLine ) ,
188
+ directoryExists : directoryName => system . directoryExists ( directoryName ) ,
189
+ getEnvironmentVariable : name => system . getEnvironmentVariable ? system . getEnvironmentVariable ( name ) : "" ,
190
+ getDirectories : ( path : string ) => system . getDirectories ( path ) ,
191
191
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 ) )
192
+ readDirectory : ( path , extensions , include , exclude , depth ) => system . readDirectory ( path , extensions , include , exclude , depth ) ,
193
+ getModifiedTime : system . getModifiedTime && ( path => system . getModifiedTime ! ( path ) ) ,
194
+ setModifiedTime : system . setModifiedTime && ( ( path , date ) => system . setModifiedTime ! ( path , date ) ) ,
195
+ deleteFile : system . deleteFile && ( path => system . deleteFile ! ( path ) )
196
196
} ;
197
197
}
198
198
0 commit comments