Skip to content

Commit

Permalink
Do not create program multiple times when there are no changes in fil…
Browse files Browse the repository at this point in the history
…es (#747)

TypeScript cant tell if there is invalidation because of custom module resolution, that means it needs to create new program whenver asked for
Fixes #746
  • Loading branch information
sheetalkamat authored and johnnyreilly committed Mar 17, 2018
1 parent 0936566 commit caec556
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -255,6 +255,7 @@ function updateFileInCache(
}

if (instance.watchHost && fileWatcherEventKind !== undefined) {
instance.hasUnaccountedModifiedFiles = true;
instance.watchHost.invokeFileWatcher(filePath, fileWatcherEventKind);
instance.watchHost.invokeDirectoryWatcher(path.dirname(filePath), filePath);
}
Expand Down
17 changes: 10 additions & 7 deletions src/instances.ts
Expand Up @@ -25,13 +25,16 @@ const instances = <TSInstances>{};

function ensureProgram(instance: TSInstance) {
if (instance && instance.watchHost) {
if (instance.changedFilesList) {
instance.watchHost.updateRootFileNames();
}
if (instance.watchOfFilesAndCompilerOptions) {
instance.program = instance.watchOfFilesAndCompilerOptions
.getProgram()
.getProgram();
if (instance.hasUnaccountedModifiedFiles) {
if (instance.changedFilesList) {
instance.watchHost.updateRootFileNames();
}
if (instance.watchOfFilesAndCompilerOptions) {
instance.program = instance.watchOfFilesAndCompilerOptions
.getProgram()
.getProgram();
}
instance.hasUnaccountedModifiedFiles = false;
}
return instance.program;
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Expand Up @@ -256,6 +256,7 @@ export interface TSInstance {
typescript.BuilderProgram
>;
program?: typescript.Program;
hasUnaccountedModifiedFiles?: boolean;
changedFilesList?: boolean;
}

Expand Down

0 comments on commit caec556

Please sign in to comment.