Skip to content

Commit ec3431e

Browse files
author
Philippe Elsass
committed
Ignoring more or less gracefully node_modules
1 parent cee24b6 commit ec3431e

File tree

5 files changed

+55
-37
lines changed

5 files changed

+55
-37
lines changed

External/Plugins/ProjectManager/Controls/OpenResourceForm.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,12 +392,14 @@ public List<String> GetProjectFolders()
392392
}
393393

394394
/// <summary>
395-
/// Quick filter of hidden/VCS directories
395+
/// Filter out hidden/VCS directories
396396
/// </summary>
397397
private bool isFolderHidden(string folder)
398398
{
399399
String name = Path.GetFileName(folder);
400400
if (name.Length == 0 || !Char.IsLetterOrDigit(name[0])) return true;
401+
foreach (string dir in PluginMain.Settings.ExcludedDirectories)
402+
if (dir == name) return true;
401403
FileInfo info = new FileInfo(folder);
402404
return (info.Attributes & FileAttributes.Hidden) > 0;
403405
}

External/Plugins/ProjectManager/Controls/TreeView/WatcherNode.cs

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,60 +86,73 @@ public void UpdateLater()
8686
updateTimer.Enabled = true;
8787
}
8888

89-
private void AppendPath(FileSystemEventArgs e)
89+
private bool AppendPath(FileSystemEventArgs e)
9090
{
9191
lock (this.changedPaths)
9292
{
93-
String fullPath = e.FullPath.TrimEnd('\\');
94-
String path = Path.GetDirectoryName(fullPath);
95-
if (this.excludedDirs != null) // filter ignored paths
93+
try
9694
{
97-
Char separator = Path.DirectorySeparatorChar;
98-
foreach (String excludedDir in this.excludedDirs)
99-
{
100-
if (path.IndexOf(separator + excludedDir + separator) > 0) return;
101-
}
95+
String fullPath = e.FullPath.TrimEnd('\\');
96+
String path = Path.GetDirectoryName(fullPath);
97+
return AppendToChangedPaths(fullPath, path, e.ChangeType);
10298
}
103-
if (this.excludedFiles != null && File.Exists(fullPath)) // filter ignored filetypes
99+
catch
104100
{
105-
String extension = Path.GetExtension(fullPath);
106-
foreach (String excludedFile in this.excludedFiles)
107-
{
108-
if (extension == excludedFile) return;
109-
}
101+
return false;
110102
}
111-
if (e.ChangeType != WatcherChangeTypes.Created && e.ChangeType != WatcherChangeTypes.Renamed
112-
&& Directory.Exists(fullPath))
103+
}
104+
}
105+
106+
private bool AppendToChangedPaths(string fullPath, string path, WatcherChangeTypes changeType)
107+
{
108+
if (this.excludedDirs != null) // filter ignored paths
109+
{
110+
Char separator = Path.DirectorySeparatorChar;
111+
foreach (String excludedDir in this.excludedDirs)
113112
{
114-
if (!this.changedPaths.Contains(fullPath))
115-
this.changedPaths.Add(fullPath);
113+
if (path.IndexOf(separator + excludedDir + separator) > 0) return false;
116114
}
117-
else if (!this.changedPaths.Contains(path) && Directory.Exists(path))
115+
}
116+
if (this.excludedFiles != null && File.Exists(fullPath)) // filter ignored filetypes
117+
{
118+
String extension = Path.GetExtension(fullPath);
119+
foreach (String excludedFile in this.excludedFiles)
118120
{
119-
this.changedPaths.Add(path);
121+
if (extension == excludedFile) return false;
120122
}
121123
}
124+
if (changeType != WatcherChangeTypes.Created && changeType != WatcherChangeTypes.Renamed
125+
&& Directory.Exists(fullPath))
126+
{
127+
if (!this.changedPaths.Contains(fullPath))
128+
this.changedPaths.Add(fullPath);
129+
}
130+
else if (!this.changedPaths.Contains(path) && Directory.Exists(path))
131+
{
132+
this.changedPaths.Add(path);
133+
}
134+
return true;
122135
}
123136

124137
private void watcher_Changed(object sender, FileSystemEventArgs e)
125138
{
126-
AppendPath(e);
127-
Changed();
139+
if (AppendPath(e))
140+
Changed();
128141
}
129142
private void watcher_Created(object sender, FileSystemEventArgs e)
130143
{
131-
AppendPath(e);
132-
Changed();
144+
if (AppendPath(e))
145+
Changed();
133146
}
134147
private void watcher_Deleted(object sender, FileSystemEventArgs e)
135148
{
136-
AppendPath(e);
137-
Changed();
149+
if (AppendPath(e))
150+
Changed();
138151
}
139152
private void watcher_Renamed(object sender, RenamedEventArgs e)
140153
{
141-
AppendPath(e);
142-
Changed();
154+
if (AppendPath(e))
155+
Changed();
143156
}
144157

145158
private void Changed()

External/Plugins/ProjectManager/PluginMain.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,11 @@ private void PatchSettings()
137137
this.SaveSettings();
138138
}
139139
// add new filtered types if user has old settings
140-
if (Array.IndexOf<string>(Settings.FilteredDirectoryNames, "git") < 0)
140+
if (Array.IndexOf<string>(Settings.ExcludedDirectories, "node_modules") < 0)
141141
{
142-
List<String> fdn = new List<string>(Settings.FilteredDirectoryNames);
143-
fdn.Add("git");
144-
fdn.Add("hg");
145-
Settings.FilteredDirectoryNames = fdn.ToArray();
142+
List<String> list = new List<string>(Settings.ExcludedDirectories);
143+
list.Add("node_modules");
144+
Settings.ExcludedDirectories = list.ToArray();
146145
this.SaveSettings();
147146
}
148147
}

External/Plugins/ProjectManager/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ProjectManagerSettings
3434

3535
// These are string arrays because they are only edited by the propertygrid (which deals with them nicely)
3636
string[] excludedFileTypes = new string[] { ".p", ".abc", ".bak", ".tmp" };
37-
string[] excludedDirectories = new string[] { ".svn", "_svn", ".cvs", "_cvs", "cvs", "_sgbak", ".git", ".hg" };
37+
string[] excludedDirectories = new string[] { ".svn", "_svn", ".cvs", "_cvs", "cvs", "_sgbak", ".git", ".hg", "node_modules" };
3838
string[] executableFileTypes = new string[] { ".exe", ".lnk", ".fla", ".flump", ".doc", ".pps", ".psd", ".png", ".jpg", ".gif", ".xls", ".docproj", ".ttf", ".otf", ".wav", ".mp3", ".ppt", ".pptx", ".docx", ".xlsx", ".ai", ".pdf", ".zip", ".rar" };
3939
string[] filteredDirectoryNames = new string[] { "src", "source", "sources", "as", "as2", "as3", "actionscript", "flash", "classes", "trunk", "svn", "git", "hg", "..", "." };
4040

PluginCore/PluginCore/Utilities/PathWalker.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
6666

6767
void bg_DoWork(object sender, DoWorkEventArgs e)
6868
{
69-
this.ExploreFolder(basePath);
69+
try
70+
{
71+
this.ExploreFolder(basePath);
72+
}
73+
catch { }
7074
}
7175

7276
/// <summary>

0 commit comments

Comments
 (0)