Skip to content

Commit 8527be9

Browse files
committed
Read program from buildInfo
1 parent ec47859 commit 8527be9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/compiler/watch.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ namespace ts {
646646
((typeDirectiveNames, containingFile, redirectedReference) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference));
647647
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
648648

649+
readBuilderProgram();
649650
synchronizeProgram();
650651

651652
// Update the wild card directory watch
@@ -655,18 +656,30 @@ namespace ts {
655656
{ getCurrentProgram: getCurrentBuilderProgram, getProgram: synchronizeProgram } :
656657
{ getCurrentProgram: getCurrentBuilderProgram, getProgram: synchronizeProgram, updateRootFileNames };
657658

659+
function readBuilderProgram() {
660+
if (compilerOptions.out || compilerOptions.outFile) return;
661+
if (!isIncrementalCompilation(compilerOptions)) return;
662+
const buildInfoPath = getOutputPathForBuildInfo(compilerOptions);
663+
if (!buildInfoPath) return;
664+
const content = directoryStructureHost.readFile(buildInfoPath);
665+
if (!content) return;
666+
const buildInfo = JSON.parse(content) as BuildInfo;
667+
if (!buildInfo.program) return;
668+
builderProgram = createBuildProgramUsingProgramBuildInfo(buildInfo.program) as any as T;
669+
}
670+
658671
function getCurrentBuilderProgram() {
659672
return builderProgram;
660673
}
661674

662675
function getCurrentProgram() {
663-
return builderProgram && builderProgram.getProgram();
676+
return builderProgram && builderProgram.getProgramOrUndefined();
664677
}
665678

666679
function synchronizeProgram() {
667680
writeLog(`Synchronizing program`);
668681

669-
const program = getCurrentProgram();
682+
const program = getCurrentBuilderProgram();
670683
if (hasChangedCompilerOptions) {
671684
newLine = updateNewLine();
672685
if (program && changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)) {
@@ -683,7 +696,7 @@ namespace ts {
683696
}
684697
}
685698
else {
686-
createNewProgram(program, hasInvalidatedResolution);
699+
createNewProgram(hasInvalidatedResolution);
687700
}
688701

689702
if (host.afterProgramCreate) {
@@ -693,13 +706,13 @@ namespace ts {
693706
return builderProgram;
694707
}
695708

696-
function createNewProgram(program: Program, hasInvalidatedResolution: HasInvalidatedResolution) {
709+
function createNewProgram(hasInvalidatedResolution: HasInvalidatedResolution) {
697710
// Compile the program
698711
writeLog("CreatingProgramWith::");
699712
writeLog(` roots: ${JSON.stringify(rootFileNames)}`);
700713
writeLog(` options: ${JSON.stringify(compilerOptions)}`);
701714

702-
const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !program;
715+
const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !getCurrentProgram();
703716
hasChangedCompilerOptions = false;
704717
hasChangedConfigFileParsingErrors = false;
705718
resolutionCache.startCachingPerDirectoryResolution();

0 commit comments

Comments
 (0)