Skip to content

Commit

Permalink
Persist resolutions in services
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Mar 30, 2021
1 parent d0947f2 commit fb609c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
15 changes: 10 additions & 5 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ namespace ts {
getCurrentDirectory(): string;
readFile(fileName: string): string | undefined;
}
export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost) {
if (outFileWithoutPersistResolutions(compilerOptions)) return undefined;
/*@internal*/
export function readBuildInfoForProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost) {
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(compilerOptions);
if (!buildInfoPath) return undefined;
const content = host.readFile(buildInfoPath);
const content = host.readFile?.(buildInfoPath);
if (!content) return undefined;
const buildInfo = getBuildInfo(content);
if (buildInfo.version !== version) return undefined;
if (!buildInfo.program) return undefined;
return createBuildProgramUsingProgramBuildInfo(buildInfo.program, buildInfoPath, host);
return { buildInfo, buildInfoPath };
}
export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost) {
if (outFileWithoutPersistResolutions(compilerOptions)) return undefined;
const result = readBuildInfoForProgram(compilerOptions, host);
if (!result?.buildInfo.program) return undefined;
return createBuildProgramUsingProgramBuildInfo(result.buildInfo.program, result.buildInfoPath, host);
}

export interface CleanPersistedProgramOfTsBuildInfoHost {
Expand Down
11 changes: 10 additions & 1 deletion src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,15 @@ namespace ts {
return sourceFile;
}

function getOldProgram(options: CompilerOptions, compilerHost: CompilerHost): Program | ProgramFromBuildInfo | undefined {
if (program) return program;
if (!options.persistResolutions) return undefined;
const buildInfoResult = readBuildInfoForProgram(options, compilerHost);
if (!buildInfoResult?.buildInfo.program?.peristedProgram) return undefined;
const result = createProgramFromBuildInfo(buildInfoResult.buildInfo.program, buildInfoResult.buildInfoPath, compilerHost);
return result?.program;
}

function synchronizeHostData(): void {
Debug.assert(languageServiceMode !== LanguageServiceMode.Syntactic);
// perform fast check if host supports it
Expand Down Expand Up @@ -1361,7 +1370,7 @@ namespace ts {
rootNames: rootFileNames,
options: newSettings,
host: compilerHost,
oldProgram: program,
oldProgram: getOldProgram(newSettings, compilerHost),
projectReferences
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,11 @@ FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/globalFil
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/globalMain.ts 500 undefined WatchType: Closed Script info
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/types.ts 500 undefined WatchType: Closed Script info
Starting updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json
======== Resolving module './filePresent' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts'. ========
Module resolution kind is not specified, using 'Classic'.
File '/user/username/projects/myproject/src/filePresent.ts' exist - use it as a name resolution result.
======== Module name './filePresent' was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'. ========
======== Resolving module './fileNotFound' from '/user/username/projects/myproject/src/anotherFileReusingResolution.ts'. ========
Module resolution kind is not specified, using 'Classic'.
File '/user/username/projects/myproject/src/fileNotFound.ts' does not exist.
File '/user/username/projects/myproject/src/fileNotFound.tsx' does not exist.
File '/user/username/projects/myproject/src/fileNotFound.d.ts' does not exist.
File '/user/username/projects/myproject/src/fileNotFound.js' does not exist.
File '/user/username/projects/myproject/src/fileNotFound.jsx' does not exist.
======== Module name './fileNotFound' was not resolved. ========
======== Resolving module './filePresent' from '/user/username/projects/myproject/src/main.ts'. ========
Resolution for module './filePresent' was found in cache from location '/user/username/projects/myproject/src'.
======== Module name './filePresent' was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'. ========
======== Resolving module './filePresent' from '/user/username/projects/myproject/src/main.ts'. ========
Resolution for module './filePresent' was found in cache from location '/user/username/projects/myproject/src'.
======== Module name './filePresent' was successfully resolved to '/user/username/projects/myproject/src/filePresent.ts'. ========
======== Resolving module './fileNotFound' from '/user/username/projects/myproject/src/main.ts'. ========
Resolution for module './fileNotFound' was found in cache from location '/user/username/projects/myproject/src'.
======== Module name './fileNotFound' was not resolved. ========
FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/src/globalFileNotFound.ts 500 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Missing file
DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Type roots
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject/node_modules/@types 1 undefined Project: /user/username/projects/myproject/tsconfig.json WatchType: Type roots
Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
Finishing updateGraphWorker: Project: /user/username/projects/myproject/tsconfig.json Version: 1 structureChanged: true structureIsReused:: Completely Elapsed:: *ms
Project '/user/username/projects/myproject/tsconfig.json' (Configured)
Files (9)
/a/lib/lib.d.ts
Expand Down

0 comments on commit fb609c0

Please sign in to comment.