@@ -321,34 +321,6 @@ namespace ts.projectSystem {
321321 verifyDiagnostics(actual, []);
322322 }
323323
324- function getPathsForTypesOrModules(base: string, rootPaths: string[], typesOrModules: string[], map: Map<true>, rootDir?: string) {
325- while (1) {
326- forEach(rootPaths, r => {
327- const rp = combinePaths(base, r);
328- forEach(typesOrModules, tm => {
329- map.set(tm === "" ? rp : combinePaths(rp, tm), true);
330- });
331- });
332- const parentDir = getDirectoryPath(base);
333- if (base === rootDir || parentDir === base) {
334- break;
335- }
336- base = parentDir;
337- }
338- return map;
339- }
340-
341- function getNodeModulesWatchedDirectories(path: string, modules: string[], map = createMap<true>()) {
342- forEach(modules, module => {
343- getPathsForTypesOrModules(path, ["node_modules"], ["", module, "@types", `@types/${module}`], map);
344- });
345- return map;
346- }
347-
348- function getTypesWatchedDirectories(path: string, typeRoots: string[], types: string[], map = createMap<true>()) {
349- return getPathsForTypesOrModules(path, typeRoots, types.concat(""), map, path);
350- }
351-
352324 describe("tsserverProjectSystem", () => {
353325 const commonFile1: FileOrFolder = {
354326 path: "/a/b/commonFile1.ts",
@@ -386,8 +358,8 @@ namespace ts.projectSystem {
386358 const configFileLocations = ["/a/b/c/", "/a/b/", "/a/", "/"];
387359 const configFiles = flatMap(configFileLocations, location => [location + "tsconfig.json", location + "jsconfig.json"]);
388360 checkWatchedFiles(host, configFiles.concat(libFile.path, moduleFile.path));
389- checkWatchedDirectories(host, ["/a/b/c" ], /*recursive*/ false);
390- checkWatchedDirectories(host, [], /*recursive*/ true);
361+ checkWatchedDirectories(host, [], /*recursive*/ false);
362+ checkWatchedDirectories(host, ["/" ], /*recursive*/ true);
391363 });
392364
393365 it("can handle tsconfig file name with difference casing", () => {
@@ -4040,7 +4012,7 @@ namespace ts.projectSystem {
40404012 const calledMaps = getCallsTrackingMap();
40414013 return {
40424014 verifyNoCall,
4043- verifyCalledOnEachEntryOnce ,
4015+ verifyCalledOnEachEntryNTimes ,
40444016 verifyCalledOnEachEntry,
40454017 verifyNoHostCalls,
40464018 verifyNoHostCallsExceptFileExistsOnce,
@@ -4090,8 +4062,8 @@ namespace ts.projectSystem {
40904062 });
40914063 }
40924064
4093- function verifyCalledOnEachEntryOnce (callback: keyof CalledMaps, expectedKeys: string[]) {
4094- return verifyCalledOnEachEntry(callback, zipToMap(expectedKeys, expectedKeys.map(() => 1 )));
4065+ function verifyCalledOnEachEntryNTimes (callback: keyof CalledMaps, expectedKeys: string[], nTimes: number ) {
4066+ return verifyCalledOnEachEntry(callback, zipToMap(expectedKeys, expectedKeys.map(() => nTimes )));
40954067 }
40964068
40974069 function verifyNoHostCalls() {
@@ -4101,7 +4073,7 @@ namespace ts.projectSystem {
41014073 }
41024074
41034075 function verifyNoHostCallsExceptFileExistsOnce(expectedKeys: string[]) {
4104- verifyCalledOnEachEntryOnce ("fileExists", expectedKeys);
4076+ verifyCalledOnEachEntryNTimes ("fileExists", expectedKeys, 1 );
41054077 verifyNoCall("directoryExists");
41064078 verifyNoCall("getDirectories");
41074079 verifyNoCall("readFile");
@@ -4253,17 +4225,7 @@ namespace ts.projectSystem {
42534225 const { configFileName } = projectService.openClientFile(file1.path);
42544226 assert.equal(configFileName, tsconfigFile.path, `should find config`);
42554227 checkNumberOfConfiguredProjects(projectService, 1);
4256- const watchedModuleDirectories = arrayFrom(
4257- getNodeModulesWatchedDirectories(
4258- canonicalFrontendDir,
4259- types,
4260- getTypesWatchedDirectories(
4261- canonicalFrontendDir,
4262- typeRoots,
4263- types
4264- )
4265- ).keys()
4266- );
4228+ const watchingRecursiveDirectories = [`${canonicalFrontendDir}/src`, canonicalFrontendDir, "/"];
42674229
42684230 const project = projectService.configuredProjects.get(canonicalConfigPath);
42694231 verifyProjectAndWatchedDirectories();
@@ -4276,7 +4238,7 @@ namespace ts.projectSystem {
42764238 host.runQueuedTimeoutCallbacks();
42774239
42784240 const canonicalFile3Path = useCaseSensitiveFileNames ? file3.path : file3.path.toLocaleLowerCase();
4279- callsTrackingHost.verifyCalledOnEachEntryOnce ("fileExists", [canonicalFile3Path]);
4241+ callsTrackingHost.verifyCalledOnEachEntryNTimes ("fileExists", [canonicalFile3Path], watchingRecursiveDirectories.length );
42804242
42814243 // Called for type root resolution
42824244 const directoryExistsCalled = createMap<number>();
@@ -4286,11 +4248,11 @@ namespace ts.projectSystem {
42864248 directoryExistsCalled.set(`/node_modules`, 2);
42874249 directoryExistsCalled.set(`${frontendDir}/types`, 2);
42884250 directoryExistsCalled.set(`${frontendDir}/node_modules/@types`, 2);
4289- directoryExistsCalled.set(canonicalFile3Path, 1 );
4251+ directoryExistsCalled.set(canonicalFile3Path, watchingRecursiveDirectories.length );
42904252 callsTrackingHost.verifyCalledOnEachEntry("directoryExists", directoryExistsCalled);
42914253
42924254 callsTrackingHost.verifyNoCall("getDirectories");
4293- callsTrackingHost.verifyCalledOnEachEntryOnce ("readFile", [file3.path]);
4255+ callsTrackingHost.verifyCalledOnEachEntryNTimes ("readFile", [file3.path], 1 );
42944256 callsTrackingHost.verifyNoCall("readDirectory");
42954257
42964258 checkNumberOfConfiguredProjects(projectService, 1);
@@ -4316,8 +4278,8 @@ namespace ts.projectSystem {
43164278 function verifyProjectAndWatchedDirectories() {
43174279 checkProjectActualFiles(project, map(projectFiles, f => f.path));
43184280 checkWatchedFiles(host, mapDefined(projectFiles, getFilePathIfOpen));
4319- checkWatchedDirectories(host, [`${canonicalFrontendDir}/src`] , /*recursive*/ true);
4320- checkWatchedDirectories(host, watchedModuleDirectories , /*recursive*/ false);
4281+ checkWatchedDirectories(host, watchingRecursiveDirectories , /*recursive*/ true);
4282+ checkWatchedDirectories(host, [] , /*recursive*/ false);
43214283 }
43224284 }
43234285
@@ -4372,7 +4334,7 @@ namespace ts.projectSystem {
43724334 const projectService = createProjectService(host);
43734335 const { configFileName } = projectService.openClientFile(app.path);
43744336 assert.equal(configFileName, tsconfigJson.path, `should find config`);
4375- const watchedModuleLocations = arrayFrom(getNodeModulesWatchedDirectories( appFolder, ["lodash"]).keys()) ;
4337+ const recursiveWatchedDirectories: string[] = [ appFolder, "/"] ;
43764338 verifyProject();
43774339
43784340 let timeoutAfterReloadFs = timeoutDuringPartialInstallation;
@@ -4450,7 +4412,8 @@ namespace ts.projectSystem {
44504412
44514413 const lodashIndexPath = "/a/b/node_modules/@types/lodash/index.d.ts";
44524414 projectFiles.push(find(filesAndFoldersToAdd, f => f.path === lodashIndexPath));
4453- watchedModuleLocations.length = indexOf(watchedModuleLocations, getDirectoryPath(lodashIndexPath));
4415+ // we would now not have failed lookup in the parent of appFolder since lodash is available
4416+ recursiveWatchedDirectories.length = 1;
44544417 // npm installation complete, timeout after reload fs
44554418 timeoutAfterReloadFs = true;
44564419 verifyAfterPartialOrCompleteNpmInstall(2);
@@ -4475,8 +4438,8 @@ namespace ts.projectSystem {
44754438
44764439 const filesWatched = filter(projectFilePaths, p => p !== app.path);
44774440 checkWatchedFiles(host, filesWatched);
4478- checkWatchedDirectories(host, [appFolder] , /*recursive*/ true);
4479- checkWatchedDirectories(host, watchedModuleLocations , /*recursive*/ false);
4441+ checkWatchedDirectories(host, recursiveWatchedDirectories , /*recursive*/ true);
4442+ checkWatchedDirectories(host, [] , /*recursive*/ false);
44804443 }
44814444 }
44824445
0 commit comments