From d32c1b091a110b1921cc48c401a269d23da994d1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 29 Oct 2018 11:25:28 -0700 Subject: [PATCH] Ignore any changes to file or folder that are in node_modules and start with "." Fixes #27673 --- src/compiler/resolutionCache.ts | 7 +++++ src/server/editorServices.ts | 2 ++ .../unittests/tsserverProjectSystem.ts | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index b22d90a76f6..d293ce8dab6 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -71,6 +71,10 @@ namespace ts { nonRecursive?: boolean; } + export function isPathInNodeModulesStartingWithDot(path: Path) { + return stringContains(path, "/node_modules/."); + } + export const maxNumberOfFilesToIterateForInvalidation = 256; type GetResolutionWithResolvedFileName = @@ -688,6 +692,9 @@ namespace ts { isChangedFailedLookupLocation = location => isInDirectoryPath(fileOrDirectoryPath, resolutionHost.toPath(location)); } else { + // If something to do with folder/file starting with "." in node_modules folder, skip it + if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return false; + // Some file or directory in the watching directory is created // Return early if it does not have any of the watching extension or not the custom failed lookup path const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 1a7e668b25e..64549c50b94 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -2040,6 +2040,8 @@ namespace ts.server { watchDir, (fileOrDirectory) => { const fileOrDirectoryPath = this.toPath(fileOrDirectory); + if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return; + // Has extension Debug.assert(result.refCount > 0); if (watchDir === fileOrDirectoryPath) { diff --git a/src/testRunner/unittests/tsserverProjectSystem.ts b/src/testRunner/unittests/tsserverProjectSystem.ts index 38d2d4867a0..a348656c24c 100644 --- a/src/testRunner/unittests/tsserverProjectSystem.ts +++ b/src/testRunner/unittests/tsserverProjectSystem.ts @@ -9039,6 +9039,33 @@ export const x = 10;` verifyModuleResolution(/*useNodeFile*/ false); }); }); + + it("ignores files/folder changes in node_modules that start with '.'", () => { + const projectPath = "/user/username/projects/project"; + const file1: File = { + path: `${projectPath}/test.js`, + content: `import { x } from "somemodule";` + }; + const file2: File = { + path: `${projectPath}/node_modules/somemodule/index.d.ts`, + content: `export const x = 10;` + }; + const files = [libFile, file1, file2]; + const host = createServerHost(files); + const service = createProjectService(host); + service.openClientFile(file1.path); + checkNumberOfProjects(service, { inferredProjects: 1 }); + const project = service.inferredProjects[0]; + (project as ResolutionCacheHost).maxNumberOfFilesToIterateForInvalidation = 1; + host.checkTimeoutQueueLength(0); + + const npmCacheFile: File = { + path: `${projectPath}/node_modules/.cache/babel-loader/89c02171edab901b9926470ba6d5677e.json`, + content: JSON.stringify({ something: 10 }) + }; + host.ensureFileOrFolder(npmCacheFile); + host.checkTimeoutQueueLength(0); + }); }); describe("tsserverProjectSystem watchDirectories implementation", () => {