Skip to content

Commit f39b49d

Browse files
committed
Update another writeFile call-site
1 parent b6659e5 commit f39b49d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace ts {
124124
try {
125125
writeFileWorker(fileName, data, writeByteOrderMark);
126126
}
127-
catch (_) {
127+
catch {
128128
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
129129
writeFileWorker(fileName, data, writeByteOrderMark);
130130
}

src/compiler/sys.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ namespace ts {
547547
try {
548548
originalWriteFile.call(sys, path, data, writeBom);
549549
}
550-
catch (_) {
550+
catch {
551551
const directoryPath = getDirectoryPath(normalizeSlashes(path));
552552
if (directoryPath && !sys.directoryExists(directoryPath)) {
553553
recursiveCreateDirectory(directoryPath, sys);

src/compiler/watch.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,20 @@ namespace ts {
307307
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) {
308308
try {
309309
performance.mark("beforeIOWrite");
310-
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
311310

312-
host.writeFile!(fileName, text, writeByteOrderMark);
311+
// PERF: Checking for directory existence is expensive.
312+
// Instead, assume the directory exists and fall back
313+
// to creating it if the file write fails.
314+
// NOTE: If patchWriteFileEnsuringDirectory has been called,
315+
// the file write will do its own directory creation and
316+
// the ensureDirectoriesExist call will always be redundant.
317+
try {
318+
host.writeFile!(fileName, text, writeByteOrderMark);
319+
}
320+
catch {
321+
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
322+
host.writeFile!(fileName, text, writeByteOrderMark);
323+
}
313324

314325
performance.mark("afterIOWrite");
315326
performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");

0 commit comments

Comments
 (0)