Skip to content

Commit 924c68c

Browse files
authored
use cache for program creation on watch mode. (microsoft#49958)
1 parent 90cfbae commit 924c68c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/compiler/watchPublic.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,11 @@ namespace ts {
445445

446446
// All resolutions are invalid if user provided resolutions
447447
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(userProvidedResolution);
448-
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
448+
const {
449+
originalReadFile, originalFileExists, originalDirectoryExists,
450+
originalCreateDirectory, originalWriteFile,
451+
} = changeCompilerHostLikeToUseCache(compilerHost, toPath);
452+
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileName => compilerHost.fileExists(fileName), hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
449453
if (hasChangedConfigFileParsingErrors) {
450454
if (reportFileChangeDetectedOnCreateProgram) {
451455
reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
@@ -462,11 +466,16 @@ namespace ts {
462466
}
463467

464468
reportFileChangeDetectedOnCreateProgram = false;
465-
466469
if (host.afterProgramCreate && program !== builderProgram) {
467470
host.afterProgramCreate(builderProgram);
468471
}
469472

473+
compilerHost.readFile = originalReadFile;
474+
compilerHost.fileExists = originalFileExists;
475+
compilerHost.directoryExists = originalDirectoryExists;
476+
compilerHost.createDirectory = originalCreateDirectory;
477+
compilerHost.writeFile = originalWriteFile!;
478+
470479
return builderProgram;
471480
}
472481

0 commit comments

Comments
 (0)