@@ -96,7 +96,7 @@ namespace ts {
96
96
if ( existingDirectories . has ( directoryPath ) ) {
97
97
return true ;
98
98
}
99
- if ( system . directoryExists ( directoryPath ) ) {
99
+ if ( ( compilerHost . directoryExists || system . directoryExists ) ( directoryPath ) ) {
100
100
existingDirectories . set ( directoryPath , true ) ;
101
101
return true ;
102
102
}
@@ -107,45 +107,8 @@ namespace ts {
107
107
if ( directoryPath . length > getRootLength ( directoryPath ) && ! directoryExists ( directoryPath ) ) {
108
108
const parentDirectory = getDirectoryPath ( directoryPath ) ;
109
109
ensureDirectoriesExist ( parentDirectory ) ;
110
- if ( compilerHost . createDirectory ) {
111
- compilerHost . createDirectory ( directoryPath ) ;
112
- }
113
- else {
114
- system . createDirectory ( directoryPath ) ;
115
- }
116
- }
117
- }
118
-
119
- let outputFingerprints : Map < OutputFingerprint > ;
120
-
121
- function writeFileIfUpdated ( fileName : string , data : string , writeByteOrderMark : boolean ) : void {
122
- if ( ! outputFingerprints ) {
123
- outputFingerprints = createMap < OutputFingerprint > ( ) ;
124
- }
125
-
126
- const hash = system . createHash ! ( data ) ; // TODO: GH#18217
127
- const mtimeBefore = system . getModifiedTime ! ( fileName ) ; // TODO: GH#18217
128
-
129
- if ( mtimeBefore ) {
130
- const fingerprint = outputFingerprints . get ( fileName ) ;
131
- // If output has not been changed, and the file has no external modification
132
- if ( fingerprint &&
133
- fingerprint . byteOrderMark === writeByteOrderMark &&
134
- fingerprint . hash === hash &&
135
- fingerprint . mtime . getTime ( ) === mtimeBefore . getTime ( ) ) {
136
- return ;
137
- }
110
+ ( compilerHost . createDirectory || system . createDirectory ) ( directoryPath ) ;
138
111
}
139
-
140
- system . writeFile ( fileName , data , writeByteOrderMark ) ;
141
-
142
- const mtimeAfter = system . getModifiedTime ! ( fileName ) || missingFileModifiedTime ; // TODO: GH#18217
143
-
144
- outputFingerprints . set ( fileName , {
145
- hash,
146
- byteOrderMark : writeByteOrderMark ,
147
- mtime : mtimeAfter
148
- } ) ;
149
112
}
150
113
151
114
function writeFile ( fileName : string , data : string , writeByteOrderMark : boolean , onError ?: ( message : string ) => void ) {
@@ -155,6 +118,9 @@ namespace ts {
155
118
// PERF: Checking for directory existence is expensive.
156
119
// Instead, assume the directory exists and fall back
157
120
// to creating it if the file write fails.
121
+ // NOTE: If patchWriteFileEnsuringDirectory has been called,
122
+ // the file write will do its own directory creation and
123
+ // the ensureDirectoriesExist call will always be redundant.
158
124
try {
159
125
writeFileWorker ( fileName , data , writeByteOrderMark ) ;
160
126
}
@@ -173,13 +139,40 @@ namespace ts {
173
139
}
174
140
}
175
141
142
+ let outputFingerprints : Map < OutputFingerprint > ;
176
143
function writeFileWorker ( fileName : string , data : string , writeByteOrderMark : boolean ) {
177
- if ( isWatchSet ( options ) && system . createHash && system . getModifiedTime ) {
178
- writeFileIfUpdated ( fileName , data , writeByteOrderMark ) ;
179
- }
180
- else {
144
+ if ( ! isWatchSet ( options ) || ! system . createHash || ! system . getModifiedTime ) {
181
145
system . writeFile ( fileName , data , writeByteOrderMark ) ;
146
+ return ;
147
+ }
148
+
149
+ if ( ! outputFingerprints ) {
150
+ outputFingerprints = createMap < OutputFingerprint > ( ) ;
151
+ }
152
+
153
+ const hash = system . createHash ( data ) ;
154
+ const mtimeBefore = system . getModifiedTime ( fileName ) ;
155
+
156
+ if ( mtimeBefore ) {
157
+ const fingerprint = outputFingerprints . get ( fileName ) ;
158
+ // If output has not been changed, and the file has no external modification
159
+ if ( fingerprint &&
160
+ fingerprint . byteOrderMark === writeByteOrderMark &&
161
+ fingerprint . hash === hash &&
162
+ fingerprint . mtime . getTime ( ) === mtimeBefore . getTime ( ) ) {
163
+ return ;
164
+ }
182
165
}
166
+
167
+ system . writeFile ( fileName , data , writeByteOrderMark ) ;
168
+
169
+ const mtimeAfter = system . getModifiedTime ( fileName ) || missingFileModifiedTime ;
170
+
171
+ outputFingerprints . set ( fileName , {
172
+ hash,
173
+ byteOrderMark : writeByteOrderMark ,
174
+ mtime : mtimeAfter
175
+ } ) ;
183
176
}
184
177
185
178
function getDefaultLibLocation ( ) : string {
0 commit comments