Update another writeFile call-site

This commit is contained in:
Andrew Casey 2019-10-17 11:36:45 -07:00
parent b6659e5d6e
commit f39b49d756
3 changed files with 15 additions and 4 deletions

View file

@ -124,7 +124,7 @@ namespace ts {
try {
writeFileWorker(fileName, data, writeByteOrderMark);
}
catch (_) {
catch {
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
writeFileWorker(fileName, data, writeByteOrderMark);
}

View file

@ -547,7 +547,7 @@ namespace ts {
try {
originalWriteFile.call(sys, path, data, writeBom);
}
catch (_) {
catch {
const directoryPath = getDirectoryPath(normalizeSlashes(path));
if (directoryPath && !sys.directoryExists(directoryPath)) {
recursiveCreateDirectory(directoryPath, sys);

View file

@ -307,9 +307,20 @@ namespace ts {
function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) {
try {
performance.mark("beforeIOWrite");
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
host.writeFile!(fileName, text, writeByteOrderMark);
// PERF: Checking for directory existence is expensive.
// Instead, assume the directory exists and fall back
// to creating it if the file write fails.
// NOTE: If patchWriteFileEnsuringDirectory has been called,
// the file write will do its own directory creation and
// the ensureDirectoriesExist call will always be redundant.
try {
host.writeFile!(fileName, text, writeByteOrderMark);
}
catch {
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
host.writeFile!(fileName, text, writeByteOrderMark);
}
performance.mark("afterIOWrite");
performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");