Skip to content

Commit d32c1b0

Browse files
committed
Ignore any changes to file or folder that are in node_modules and start with "."
Fixes microsoft#27673
1 parent c97fc64 commit d32c1b0

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/compiler/resolutionCache.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace ts {
7171
nonRecursive?: boolean;
7272
}
7373

74+
export function isPathInNodeModulesStartingWithDot(path: Path) {
75+
return stringContains(path, "/node_modules/.");
76+
}
77+
7478
export const maxNumberOfFilesToIterateForInvalidation = 256;
7579

7680
type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
@@ -688,6 +692,9 @@ namespace ts {
688692
isChangedFailedLookupLocation = location => isInDirectoryPath(fileOrDirectoryPath, resolutionHost.toPath(location));
689693
}
690694
else {
695+
// If something to do with folder/file starting with "." in node_modules folder, skip it
696+
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return false;
697+
691698
// Some file or directory in the watching directory is created
692699
// Return early if it does not have any of the watching extension or not the custom failed lookup path
693700
const dirOfFileOrDirectory = getDirectoryPath(fileOrDirectoryPath);

src/server/editorServices.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,6 +2040,8 @@ namespace ts.server {
20402040
watchDir,
20412041
(fileOrDirectory) => {
20422042
const fileOrDirectoryPath = this.toPath(fileOrDirectory);
2043+
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
2044+
20432045
// Has extension
20442046
Debug.assert(result.refCount > 0);
20452047
if (watchDir === fileOrDirectoryPath) {

src/testRunner/unittests/tsserverProjectSystem.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9039,6 +9039,33 @@ export const x = 10;`
90399039
verifyModuleResolution(/*useNodeFile*/ false);
90409040
});
90419041
});
9042+
9043+
it("ignores files/folder changes in node_modules that start with '.'", () => {
9044+
const projectPath = "/user/username/projects/project";
9045+
const file1: File = {
9046+
path: `${projectPath}/test.js`,
9047+
content: `import { x } from "somemodule";`
9048+
};
9049+
const file2: File = {
9050+
path: `${projectPath}/node_modules/somemodule/index.d.ts`,
9051+
content: `export const x = 10;`
9052+
};
9053+
const files = [libFile, file1, file2];
9054+
const host = createServerHost(files);
9055+
const service = createProjectService(host);
9056+
service.openClientFile(file1.path);
9057+
checkNumberOfProjects(service, { inferredProjects: 1 });
9058+
const project = service.inferredProjects[0];
9059+
(project as ResolutionCacheHost).maxNumberOfFilesToIterateForInvalidation = 1;
9060+
host.checkTimeoutQueueLength(0);
9061+
9062+
const npmCacheFile: File = {
9063+
path: `${projectPath}/node_modules/.cache/babel-loader/89c02171edab901b9926470ba6d5677e.json`,
9064+
content: JSON.stringify({ something: 10 })
9065+
};
9066+
host.ensureFileOrFolder(npmCacheFile);
9067+
host.checkTimeoutQueueLength(0);
9068+
});
90429069
});
90439070

90449071
describe("tsserverProjectSystem watchDirectories implementation", () => {

0 commit comments

Comments
 (0)