Skip to content

Use .tsbuildinfo to build with tsc and tsc --w when not using build mode #30232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 9, 2019
Prev Previous commit
Next Next commit
Read program from buildInfo
  • Loading branch information
sheetalkamat committed Mar 8, 2019
commit 8527be9ea89b4125c9494a8672db505722ff71cc
23 changes: 18 additions & 5 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ namespace ts {
((typeDirectiveNames, containingFile, redirectedReference) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference));
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;

readBuilderProgram();
synchronizeProgram();

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

function readBuilderProgram() {
if (compilerOptions.out || compilerOptions.outFile) return;
if (!isIncrementalCompilation(compilerOptions)) return;
const buildInfoPath = getOutputPathForBuildInfo(compilerOptions);
if (!buildInfoPath) return;
const content = directoryStructureHost.readFile(buildInfoPath);
if (!content) return;
const buildInfo = JSON.parse(content) as BuildInfo;
if (!buildInfo.program) return;
builderProgram = createBuildProgramUsingProgramBuildInfo(buildInfo.program) as any as T;
}

function getCurrentBuilderProgram() {
return builderProgram;
}

function getCurrentProgram() {
return builderProgram && builderProgram.getProgram();
return builderProgram && builderProgram.getProgramOrUndefined();
}

function synchronizeProgram() {
writeLog(`Synchronizing program`);

const program = getCurrentProgram();
const program = getCurrentBuilderProgram();
if (hasChangedCompilerOptions) {
newLine = updateNewLine();
if (program && changesAffectModuleResolution(program.getCompilerOptions(), compilerOptions)) {
Expand All @@ -683,7 +696,7 @@ namespace ts {
}
}
else {
createNewProgram(program, hasInvalidatedResolution);
createNewProgram(hasInvalidatedResolution);
}

if (host.afterProgramCreate) {
Expand All @@ -693,13 +706,13 @@ namespace ts {
return builderProgram;
}

function createNewProgram(program: Program, hasInvalidatedResolution: HasInvalidatedResolution) {
function createNewProgram(hasInvalidatedResolution: HasInvalidatedResolution) {
// Compile the program
writeLog("CreatingProgramWith::");
writeLog(` roots: ${JSON.stringify(rootFileNames)}`);
writeLog(` options: ${JSON.stringify(compilerOptions)}`);

const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !program;
const needsUpdateInTypeRootWatch = hasChangedCompilerOptions || !getCurrentProgram();
hasChangedCompilerOptions = false;
hasChangedConfigFileParsingErrors = false;
resolutionCache.startCachingPerDirectoryResolution();
Expand Down