Skip to content

In tsc--watch, fix the leaking watch when old source file is not part of program any more #22090

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 2 commits into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,9 @@ namespace ts {
(missingFilePathsRequestedForRelease || (missingFilePathsRequestedForRelease = [])).push(oldSourceFile.path);
}
else if ((hostSourceFileInfo as FilePresentOnHost).sourceFile === oldSourceFile) {
if ((hostSourceFileInfo as FilePresentOnHost).fileWatcher) {
(hostSourceFileInfo as FilePresentOnHost).fileWatcher.close();
}
sourceFilesCache.delete(oldSourceFile.path);
resolutionCache.removeResolutionsOfFile(oldSourceFile.path);
}
Expand Down
28 changes: 28 additions & 0 deletions src/harness/unittests/tscWatchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,34 @@ namespace ts.tscWatch {
checkProgramActualFiles(watch(), files.map(file => file.path));
checkOutputErrors(host, [], ExpectedOutputErrorsPosition.AfterFileChangeDetected);
});

it("watched files when file is deleted and new file is added as part of change", () => {
const projectLocation = "/home/username/project";
const file: FileOrFolder = {
path: `${projectLocation}/src/file1.ts`,
content: "var a = 10;"
};
const configFile: FileOrFolder = {
path: `${projectLocation}/tsconfig.json`,
content: "{}"
};
const files = [file, libFile, configFile];
const host = createWatchedSystem(files);
const watch = createWatchOfConfigFile(configFile.path, host);
verifyProgram();

file.path = file.path.replace("file1", "file2");
host.reloadFS(files);
host.runQueuedTimeoutCallbacks();
verifyProgram();

function verifyProgram() {
checkProgramActualFiles(watch(), mapDefined(files, f => f === configFile ? undefined : f.path));
checkWatchedDirectories(host, [], /*recursive*/ false);
checkWatchedDirectories(host, [projectLocation, `${projectLocation}/node_modules/@types`], /*recursive*/ true);
checkWatchedFiles(host, files.map(f => f.path));
}
});
});

describe("tsc-watch emit with outFile or out setting", () => {
Expand Down