Skip to content

Commit 0173a3f

Browse files
authored
return empty file watcher in case if target directory does not exist (#12091)
* return empty file watcher in case if target directory does not exist * linter
1 parent 4ffdea8 commit 0173a3f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/compiler/sys.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ namespace ts {
439439
return filter<string>(_fs.readdirSync(path), dir => fileSystemEntryExists(combinePaths(path, dir), FileSystemEntryKind.Directory));
440440
}
441441

442+
const noOpFileWatcher: FileWatcher = { close: noop };
442443
const nodeSystem: System = {
443444
args: process.argv.slice(2),
444445
newLine: _os.EOL,
@@ -475,7 +476,7 @@ namespace ts {
475476
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
476477
let options: any;
477478
if (!directoryExists(directoryName)) {
478-
return;
479+
return noOpFileWatcher;
479480
}
480481

481482
if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) {

src/harness/unittests/tsserverProjectSystem.ts

+27
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,33 @@ namespace ts.projectSystem {
19641964
projectService.checkNumberOfProjects({ configuredProjects: 1 });
19651965
checkProjectActualFiles(projectService.configuredProjects[0], [libES5.path, libES2015Promise.path, app.path]);
19661966
});
1967+
1968+
it("should handle non-existing directories in config file", () => {
1969+
const f = {
1970+
path: "/a/src/app.ts",
1971+
content: "let x = 1;"
1972+
};
1973+
const config = {
1974+
path: "/a/tsconfig.json",
1975+
content: JSON.stringify({
1976+
compilerOptions: {},
1977+
include: [
1978+
"src/**/*",
1979+
"notexistingfolder/*"
1980+
]
1981+
})
1982+
};
1983+
const host = createServerHost([f, config]);
1984+
const projectService = createProjectService(host);
1985+
projectService.openClientFile(f.path);
1986+
projectService.checkNumberOfProjects({ configuredProjects: 1 });
1987+
1988+
projectService.closeClientFile(f.path);
1989+
projectService.checkNumberOfProjects({ configuredProjects: 0 });
1990+
1991+
projectService.openClientFile(f.path);
1992+
projectService.checkNumberOfProjects({ configuredProjects: 1 });
1993+
});
19671994
});
19681995

19691996
describe("prefer typings to js", () => {

0 commit comments

Comments
 (0)