@@ -247,6 +247,23 @@ namespace ts.projectSystem {
247
247
checkFileNames(`${server.ProjectKind[project.projectKind]} project, rootFileNames`, project.getRootFiles(), expectedFiles);
248
248
}
249
249
250
+ function getNodeModuleDirectories(dir: string) {
251
+ const result: string[] = [];
252
+ while (true) {
253
+ result.push(combinePaths(dir, "node_modules"));
254
+ const parentDir = getDirectoryPath(dir);
255
+ if (parentDir === dir) {
256
+ break;
257
+ }
258
+ dir = parentDir;
259
+ }
260
+ return result;
261
+ }
262
+
263
+ function getNumberOfWatchesInvokedForRecursiveWatches(recursiveWatchedDirs: string[], file: string) {
264
+ return countWhere(recursiveWatchedDirs, dir => file.length > dir.length && startsWith(file, dir) && file[dir.length] === directorySeparator);
265
+ }
266
+
250
267
/**
251
268
* Test server cancellation token used to mock host token cancellation requests.
252
269
* The cancelAfterRequest constructor param specifies how many isCancellationRequested() calls
@@ -375,7 +392,7 @@ namespace ts.projectSystem {
375
392
const configFiles = flatMap(configFileLocations, location => [location + "tsconfig.json", location + "jsconfig.json"]);
376
393
checkWatchedFiles(host, configFiles.concat(libFile.path, moduleFile.path));
377
394
checkWatchedDirectories(host, [], /*recursive*/ false);
378
- checkWatchedDirectories(host, ["/", typeRootFromTsserverLocation], /*recursive*/ true);
395
+ checkWatchedDirectories(host, ["/a/b/c ", typeRootFromTsserverLocation], /*recursive*/ true);
379
396
});
380
397
381
398
it("can handle tsconfig file name with difference casing", () => {
@@ -4243,7 +4260,7 @@ namespace ts.projectSystem {
4243
4260
const { configFileName } = projectService.openClientFile(file1.path);
4244
4261
assert.equal(configFileName, tsconfigFile.path, `should find config`);
4245
4262
checkNumberOfConfiguredProjects(projectService, 1);
4246
- const watchingRecursiveDirectories = [`${canonicalFrontendDir}/src`, canonicalFrontendDir, "/"] ;
4263
+ const watchingRecursiveDirectories = [`${canonicalFrontendDir}/src`, canonicalFrontendDir].concat(getNodeModuleDirectories(getDirectoryPath(canonicalFrontendDir))) ;
4247
4264
4248
4265
const project = projectService.configuredProjects.get(canonicalConfigPath);
4249
4266
verifyProjectAndWatchedDirectories();
@@ -4256,7 +4273,8 @@ namespace ts.projectSystem {
4256
4273
host.runQueuedTimeoutCallbacks();
4257
4274
4258
4275
const canonicalFile3Path = useCaseSensitiveFileNames ? file3.path : file3.path.toLocaleLowerCase();
4259
- callsTrackingHost.verifyCalledOnEachEntryNTimes("fileExists", [canonicalFile3Path], watchingRecursiveDirectories.length);
4276
+ const numberOfTimesWatchInvoked = getNumberOfWatchesInvokedForRecursiveWatches(watchingRecursiveDirectories, canonicalFile3Path);
4277
+ callsTrackingHost.verifyCalledOnEachEntryNTimes("fileExists", [canonicalFile3Path], numberOfTimesWatchInvoked);
4260
4278
4261
4279
// Called for type root resolution
4262
4280
const directoryExistsCalled = createMap<number>();
@@ -4266,7 +4284,7 @@ namespace ts.projectSystem {
4266
4284
directoryExistsCalled.set(`/node_modules`, 2);
4267
4285
directoryExistsCalled.set(`${frontendDir}/types`, 2);
4268
4286
directoryExistsCalled.set(`${frontendDir}/node_modules/@types`, 2);
4269
- directoryExistsCalled.set(canonicalFile3Path, watchingRecursiveDirectories.length );
4287
+ directoryExistsCalled.set(canonicalFile3Path, numberOfTimesWatchInvoked );
4270
4288
callsTrackingHost.verifyCalledOnEachEntry("directoryExists", directoryExistsCalled);
4271
4289
4272
4290
callsTrackingHost.verifyNoCall("getDirectories");
@@ -4353,7 +4371,7 @@ namespace ts.projectSystem {
4353
4371
const projectService = createProjectService(host);
4354
4372
const { configFileName } = projectService.openClientFile(app.path);
4355
4373
assert.equal(configFileName, tsconfigJson.path, `should find config`);
4356
- const recursiveWatchedDirectories: string[] = [appFolder, "/"] ;
4374
+ const recursiveWatchedDirectories: string[] = [appFolder].concat(getNodeModuleDirectories(getDirectoryPath(appFolder))) ;
4357
4375
verifyProject();
4358
4376
4359
4377
let timeoutAfterReloadFs = timeoutDuringPartialInstallation;
0 commit comments