Skip to content

Commit a6443e3

Browse files
authored
Avoid watching non-existing directories and fix null-exception (#11601)
* Avoid watching non-existing directories and fix null-exception * Add test * Move the fix to sys to cover tsc -w also
1 parent 17c2ab2 commit a6443e3

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/compiler/sys.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,10 @@ namespace ts {
476476
// Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
477477
// (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
478478
let options: any;
479+
if (!directoryExists(directoryName)) {
480+
return;
481+
}
482+
479483
if (isNode4OrLater() && (process.platform === "win32" || process.platform === "darwin")) {
480484
options = { persistent: true, recursive: !!recursive };
481485
}

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,4 +2387,33 @@ namespace ts.projectSystem {
23872387
assert.isTrue(errorResult.length === 0);
23882388
});
23892389
});
2390+
2391+
describe("non-existing directories listed in config file input array", () => {
2392+
it("should be tolerated without crashing the server", () => {
2393+
const configFile = {
2394+
path: "/a/b/tsconfig.json",
2395+
content: `{
2396+
"compilerOptions": {},
2397+
"include": ["app/*", "test/**/*", "something"]
2398+
}`
2399+
};
2400+
const file1 = {
2401+
path: "/a/b/file1.ts",
2402+
content: "let t = 10;"
2403+
};
2404+
2405+
const host = createServerHost([file1, configFile]);
2406+
const projectService = createProjectService(host);
2407+
projectService.openClientFile(file1.path);
2408+
host.runQueuedTimeoutCallbacks();
2409+
checkNumberOfConfiguredProjects(projectService, 1);
2410+
checkNumberOfInferredProjects(projectService, 1);
2411+
2412+
const configuredProject = projectService.configuredProjects[0];
2413+
assert.isTrue(configuredProject.getFileNames().length == 0);
2414+
2415+
const inferredProject = projectService.inferredProjects[0];
2416+
assert.isTrue(inferredProject.containsFile(<server.NormalizedPath>file1.path));
2417+
});
2418+
});
23902419
}

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ namespace ts.server {
710710
Debug.assert(!!parsedCommandLine.fileNames);
711711

712712
if (parsedCommandLine.fileNames.length === 0) {
713-
errors.push(createCompilerDiagnostic(Diagnostics.The_config_file_0_found_doesn_t_contain_any_source_files, configFilename));
713+
(errors || (errors = [])).push(createCompilerDiagnostic(Diagnostics.The_config_file_0_found_doesn_t_contain_any_source_files, configFilename));
714714
return { success: false, configFileErrors: errors };
715715
}
716716

0 commit comments

Comments
 (0)