Skip to content

Commit ec2ee9f

Browse files
committed
Ignore anything starting with ".git"
Fixes microsoft#29782
1 parent 79a1f29 commit ec2ee9f

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

src/compiler/resolutionCache.ts

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

74-
export function isPathInNodeModulesStartingWithDot(path: Path) {
75-
return stringContains(path, "/node_modules/.");
74+
export function isPathIgnored(path: Path) {
75+
return some(ignoredPaths, searchPath => stringContains(path, searchPath));
7676
}
7777

7878
export const maxNumberOfFilesToIterateForInvalidation = 256;
@@ -696,7 +696,7 @@ namespace ts {
696696
}
697697
else {
698698
// If something to do with folder/file starting with "." in node_modules folder, skip it
699-
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return false;
699+
if (isPathIgnored(fileOrDirectoryPath)) return false;
700700

701701
// Some file or directory in the watching directory is created
702702
// Return early if it does not have any of the watching extension or not the custom failed lookup path

src/compiler/sys.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ namespace ts {
326326
: FileWatcherEventKind.Changed;
327327
}
328328

329+
/*@internal*/
330+
export const ignoredPaths = ["/node_modules/.", "/.git"];
331+
329332
/*@internal*/
330333
export interface RecursiveDirectoryWatcherHost {
331334
watchDirectory: HostWatchDirectory;
@@ -371,7 +374,7 @@ namespace ts {
371374
else {
372375
directoryWatcher = {
373376
watcher: host.watchDirectory(dirName, fileName => {
374-
if (isInNodeModulesStartingWithDot(fileName)) return;
377+
if (isIgnoredPath(fileName)) return;
375378

376379
// Call the actual callback
377380
callbackCache.forEach((callbacks, rootDirName) => {
@@ -428,7 +431,7 @@ namespace ts {
428431
const childFullName = getNormalizedAbsolutePath(child, parentDir);
429432
// Filter our the symbolic link directories since those arent included in recursive watch
430433
// which is same behaviour when recursive: true is passed to fs.watch
431-
return !isInNodeModulesStartingWithDot(childFullName) && filePathComparer(childFullName, normalizePath(host.realpath(childFullName))) === Comparison.EqualTo ? childFullName : undefined;
434+
return !isIgnoredPath(childFullName) && filePathComparer(childFullName, normalizePath(host.realpath(childFullName))) === Comparison.EqualTo ? childFullName : undefined;
432435
}) : emptyArray,
433436
existingChildWatches,
434437
(child, childWatcher) => filePathComparer(child, childWatcher.dirName),
@@ -455,8 +458,8 @@ namespace ts {
455458
}
456459
}
457460

458-
function isInNodeModulesStartingWithDot(path: string) {
459-
return isInPath(path, "/node_modules/.");
461+
function isIgnoredPath(path: string) {
462+
return some(ignoredPaths, searchPath => isInPath(path, searchPath));
460463
}
461464

462465
function isInPath(path: string, searchPath: string) {

src/compiler/watch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ namespace ts {
987987
}
988988
nextSourceFileVersion(fileOrDirectoryPath);
989989

990-
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
990+
if (isPathIgnored(fileOrDirectoryPath)) return;
991991

992992
// If the the added or created file or directory is not supported file name, ignore the file
993993
// But when watched directory is added/removed, we need to reload the file list

src/server/editorServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ namespace ts.server {
10021002
fileOrDirectory => {
10031003
const fileOrDirectoryPath = this.toPath(fileOrDirectory);
10041004
project.getCachedDirectoryStructureHost().addOrDeleteFileOrDirectory(fileOrDirectory, fileOrDirectoryPath);
1005-
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
1005+
if (isPathIgnored(fileOrDirectoryPath)) return;
10061006
const configFilename = project.getConfigFilePath();
10071007

10081008
// If the the added or created file or directory is not supported file name, ignore the file
@@ -2071,7 +2071,7 @@ namespace ts.server {
20712071
watchDir,
20722072
(fileOrDirectory) => {
20732073
const fileOrDirectoryPath = this.toPath(fileOrDirectory);
2074-
if (isPathInNodeModulesStartingWithDot(fileOrDirectoryPath)) return;
2074+
if (isPathIgnored(fileOrDirectoryPath)) return;
20752075

20762076
// Has extension
20772077
Debug.assert(result.refCount > 0);

src/testRunner/unittests/tsserver/watchEnvironment.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ namespace ts.projectSystem {
183183
host.checkTimeoutQueueLength(0);
184184
verifyProject();
185185

186+
const gitIgnoredFileFromIgnoreDirectory: File = {
187+
path: `${projectFolder}/.git/someFile.d.ts`,
188+
content: ""
189+
};
190+
host.ensureFileOrFolder(gitIgnoredFileFromIgnoreDirectory);
191+
host.checkTimeoutQueueLength(0);
192+
verifyProject();
193+
194+
const gitIgnoredFile: File = {
195+
path: `${projectFolder}/.gitCache.d.ts`,
196+
content: ""
197+
};
198+
host.ensureFileOrFolder(gitIgnoredFile);
199+
host.checkTimeoutQueueLength(0);
200+
verifyProject();
201+
186202
function verifyProject() {
187203
checkWatchedDirectories(host, emptyArray, /*recursive*/ true);
188204
checkWatchedFilesDetailed(host, expectedWatchedFiles);

0 commit comments

Comments
 (0)