Skip to content

Commit b84f5e2

Browse files
committed
#430 Add from existing code should ignore any filepaths that include
node_modules and bower_components by default - Remove 'exclude node_modules' checkbox - Exclude node_modules subdirectories - Exclude bower_components subdirectories close #495 ================================= Squashed commit of the following: commit bfbd26df970628204b7863783598d2ce70ad2c4d Merge: 141c6bf 0a61329 Author: Sara Itani <sitani@microsoft.com> Date: Fri Feb 19 17:21:06 2016 -0800 Merge branch 'AlwaysExcludeNodeModules' of https://github.com/hoanhtien/nodejstools into hoanhtien-AlwaysExcludeNodeModules commit 0a61329 Author: Tien Nguyen <tihoanh@microsoft.com> Date: Fri Oct 16 14:14:14 2015 -0700 Brace on same line. commit 1dd9930 Author: Tien Nguyen <tihoanh@microsoft.com> Date: Fri Oct 16 14:11:30 2015 -0700 Add a test case for importing bower_components. commit f0c29a1 Merge: d5729ab b801b60 Author: Tien Nguyen <tihoanh@microsoft.com> Date: Fri Oct 16 13:58:40 2015 -0700 Merge remote-tracking branch 'microsoft/master' into AlwaysExcludeNodeModules commit d5729ab Author: Tien Nguyen <tihoanh@microsoft.com> Date: Fri Oct 16 13:57:58 2015 -0700 Remove binding ExcludeNodeModules. commit f5651fb Author: Tien Nguyen <tihoanh@microsoft.com> Date: Tue Sep 29 15:13:08 2015 -0700 Exclude bower_components folders. commit 963b453 Author: Tien Nguyen <tihoanh@microsoft.com> Date: Tue Sep 29 14:06:31 2015 -0700 Exlude node_modules subfolders. commit 85ccff4 Author: Tien Nguyen <tihoanh@microsoft.com> Date: Mon Sep 28 19:19:33 2015 -0700 Remove 'exclude node_modules' checkbox.
1 parent 141c6bf commit b84f5e2

7 files changed

Lines changed: 31 additions & 55 deletions

File tree

Nodejs/Product/Nodejs/NodejsConstants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ internal class NodejsConstants {
4040

4141
internal const string NodeModulesFolder = "node_modules";
4242
internal const string NodeModulesStagingFolder = "node_modules\\.staging\\";
43+
internal const string BowerComponentsFolder = "bower_components";
4344
internal const string AnalysisIgnoredDirectories = "AnalysisIgnoredDirectories";
4445
internal const string AnalysisMaxFileSize = "AnalysisMaxFileSize";
4546
internal const string DefaultIntellisenseCompletionCommittedBy = "{}[]().,:;+-*/%&|^!~=<>?@#'\"\\";

Nodejs/Product/Nodejs/Project/ImportWizard/FileSourcePage.xaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<RowDefinition Height="*" />
2020
<RowDefinition Height="auto" />
2121
</Grid.RowDefinitions>
22-
22+
2323
<wpf:LabelledControl Title="Choose which file to run when F5 is pressed."
2424
HelpText="If it is not in this list, you can right-click any file in your project and choose &quot;Set as startup file&quot;"
2525
Grid.Row="0">
@@ -52,12 +52,5 @@
5252
</ListView.ItemTemplate>
5353
</ListView>
5454
</wpf:LabelledControl>
55-
56-
<wpf:LabelledControl Title="Select any other options for your project."
57-
Grid.Row="1">
58-
<StackPanel Orientation="Vertical">
59-
<CheckBox IsChecked="{Binding ExcludeNodeModules}">Exclude node__modules</CheckBox>
60-
</StackPanel>
61-
</wpf:LabelledControl>
6255
</Grid>
6356
</Page>

Nodejs/Product/Nodejs/Project/ImportWizard/ImportSettings.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
using System.Threading.Tasks;
2525
using System.Windows;
2626
using System.Xml;
27-
using Microsoft.NodejsTools.Telemetry;
27+
using Microsoft.NodejsTools.Telemetry;
2828
using Microsoft.VisualStudio.Language.Intellisense;
2929
using Microsoft.VisualStudioTools;
3030

@@ -63,18 +63,12 @@ public string StartupFile {
6363
set { SetValue(StartupFileProperty, value); }
6464
}
6565

66-
public bool ExcludeNodeModules {
67-
get { return (bool)GetValue(ExcludeNodeModulesProperty); }
68-
set { SetValue(ExcludeNodeModulesProperty, value); }
69-
}
70-
7166
public static readonly DependencyProperty ProjectPathProperty = DependencyProperty.Register("ProjectPath", typeof(string), typeof(ImportSettings), new PropertyMetadata(ProjectPath_Updated));
7267
public static readonly DependencyProperty SourcePathProperty = DependencyProperty.Register("SourcePath", typeof(string), typeof(ImportSettings), new PropertyMetadata(SourcePath_Updated));
7368
public static readonly DependencyProperty FiltersProperty = DependencyProperty.Register("Filters", typeof(string), typeof(ImportSettings), new PropertyMetadata());
7469
private static readonly DependencyPropertyKey TopLevelJavaScriptFilesPropertyKey = DependencyProperty.RegisterReadOnly("TopLevelJavaScriptFiles", typeof(ObservableCollection<string>), typeof(ImportSettings), new PropertyMetadata());
7570
public static readonly DependencyProperty TopLevelJavaScriptFilesProperty = TopLevelJavaScriptFilesPropertyKey.DependencyProperty;
7671
public static readonly DependencyProperty StartupFileProperty = DependencyProperty.Register("StartupFile", typeof(string), typeof(ImportSettings), new PropertyMetadata());
77-
public static readonly DependencyProperty ExcludeNodeModulesProperty = DependencyProperty.Register("ExcludeNodeModules", typeof(bool), typeof(ImportSettings), new PropertyMetadata(true));
7872

7973
public bool IsValid {
8074
get { return (bool)GetValue(IsValidProperty); }
@@ -206,16 +200,17 @@ public Task<string> CreateRequestedProjectAsync() {
206200
string sourcePath = SourcePath;
207201
string filters = Filters;
208202
string startupFile = StartupFile;
203+
209204
bool excludeNodeModules = ExcludeNodeModules;
210205
return Task.Run<string>(() => {
211206
bool success = false;
212207
Guid projectGuid;
213208
try {
214209
using (var writer = GetDefaultWriter(projectPath)) {
215-
WriteProjectXml(writer, projectPath, sourcePath, filters, startupFile, excludeNodeModules, out projectGuid);
210+
WriteProjectXml(writer, projectPath, sourcePath, filters, startupFile, true, out projectGuid);
216211
}
217212
if (NodejsPackage.Instance != null) {
218-
NodejsPackage.Instance.TelemetryLogger.ReportEvent(TelemetryEvents.ProjectImported, TelemetryProperties.ProjectGuid, projectGuid.ToString("B"));
213+
NodejsPackage.Instance.TelemetryLogger.ReportEvent(TelemetryEvents.ProjectImported, TelemetryProperties.ProjectGuid, projectGuid.ToString("B"));
219214
}
220215
success = true;
221216
return projectPath;
@@ -247,6 +242,15 @@ private static bool ShouldIncludeDirectory(string dirName) {
247242
return !dirName.Split(new char[] { '/', '\\' }).Any(name => name.StartsWith("."));
248243
}
249244

245+
/// <summary>
246+
/// Checks whether a relative and double-backslashed seperated path contains a folder name.
247+
/// </summary>
248+
private static bool ContainsNodeModulesOrBowerComponentsFolder(string path) {
249+
string tmp = "\\" + path + "\\";
250+
return tmp.IndexOf("\\" + NodejsConstants.NodeModulesFolder + "\\", StringComparison.OrdinalIgnoreCase) >= 0 ||
251+
tmp.IndexOf("\\" + NodejsConstants.BowerComponentsFolder + "\\", StringComparison.OrdinalIgnoreCase) >= 0;
252+
}
253+
250254
internal static void WriteProjectXml(
251255
XmlWriter writer,
252256
string projectPath,
@@ -323,10 +327,12 @@ out Guid projectGuid
323327
)
324328
.Where(ShouldIncludeDirectory)
325329
);
330+
331+
// Exclude node_modules and bower_components folders.
326332
if (excludeNodeModules) {
327-
folders.Remove(NodejsConstants.NodeModulesFolder);
328-
folders.RemoveWhere(folder => folder.StartsWith(NodejsConstants.NodeModulesFolder + "\\", StringComparison.OrdinalIgnoreCase));
333+
folders.RemoveWhere(folder => ContainsNodeModulesOrBowerComponentsFolder(folder));
329334
}
335+
330336
writer.WriteStartElement("ItemGroup");
331337
foreach (var file in EnumerateAllFiles(sourcePath, filters, excludeNodeModules)) {
332338
var ext = Path.GetExtension(file);
@@ -426,7 +432,7 @@ private static IEnumerable<string> EnumerateAllFiles(string source, string filte
426432
}
427433

428434
foreach (var dir in directories) {
429-
if (excludeNodeModules && dir.Contains("\\node_modules\\")) {
435+
if (excludeNodeModules && ContainsNodeModulesOrBowerComponentsFolder(dir)) {
430436
continue;
431437
}
432438
try {
@@ -442,10 +448,6 @@ private static IEnumerable<string> EnumerateAllFiles(string source, string filte
442448
.Select(path => path.Substring(source.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
443449
.Distinct(StringComparer.OrdinalIgnoreCase);
444450

445-
if(excludeNodeModules) {
446-
res = res.Where(x => !x.StartsWith("node_modules\\", StringComparison.OrdinalIgnoreCase));
447-
}
448-
449451
return res;
450452
}
451453

Nodejs/Tests/Core/ImportWizardTests.cs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,34 +169,13 @@ public void ImportWizardStartupFile() {
169169
Assert.AreEqual("server.js", proj.Descendant("StartupFile").Value);
170170
}
171171

172-
[TestMethod, Priority(0)]
173-
public void ImportWizardIncludeNodeModules() {
174-
var settings = new ImportSettings();
175-
176-
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld3\\");
177-
settings.Filters = "*.js;*.njsproj";
178-
settings.StartupFile = "server.js";
179-
settings.ExcludeNodeModules = false;
180-
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\Subdirectory\\ProjectName.njsproj");
181-
182-
var path = settings.CreateRequestedProject();
183-
184-
Assert.AreEqual(settings.ProjectPath, path);
185-
var proj = XDocument.Load(path);
186-
187-
AssertUtil.ContainsExactly(proj.Descendants(proj.GetName("Compile")).Select(x => x.Attribute("Include").Value),
188-
"server.js",
189-
"node_modules\\mymod.js");
190-
}
191-
192172
[TestMethod, Priority(0)]
193173
public void ImportWizardExcludeNodeModules() {
194174
var settings = new ImportSettings();
195175

196176
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld3\\");
197177
settings.Filters = "*.js;*.njsproj";
198178
settings.StartupFile = "server.js";
199-
settings.ExcludeNodeModules = true;
200179
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\Subdirectory\\ProjectName.njsproj");
201180

202181
var path = settings.CreateRequestedProject();
@@ -215,7 +194,6 @@ public void ImportWizardExcludeDotPrefixedFolders() {
215194
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld5\\");
216195
settings.Filters = "*.js;*.njsproj";
217196
settings.StartupFile = "server.js";
218-
settings.ExcludeNodeModules = true;
219197
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\Subdirectory\\ProjectName.njsproj");
220198

221199
var path = settings.CreateRequestedProject();
@@ -240,7 +218,6 @@ public void ImportWizardEmptyFolders() {
240218
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld4");
241219
settings.Filters = "*.js";
242220
settings.StartupFile = "server.js";
243-
settings.ExcludeNodeModules = true;
244221
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\Subdirectory\\ProjectName.njsproj");
245222

246223
var path = settings.CreateRequestedProject();
@@ -250,16 +227,15 @@ public void ImportWizardEmptyFolders() {
250227

251228
AssertUtil.ContainsExactly(proj.Descendants(proj.GetName("Folder")).Select(x => x.Attribute("Include").Value),
252229
"Baz");
253-
}
254-
230+
}
231+
255232
[TestMethod, Priority(0)]
256-
public void ImportWizardEmptyFoldersDontExcludeNodeModules() {
233+
public void ImportWizardExcludeBowerComponents() {
257234
var settings = new ImportSettings();
258235

259-
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld4\\");
236+
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld6");
260237
settings.Filters = "*.js";
261238
settings.StartupFile = "server.js";
262-
settings.ExcludeNodeModules = false;
263239
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\Subdirectory\\ProjectName.njsproj");
264240

265241
var path = settings.CreateRequestedProject();
@@ -268,7 +244,7 @@ public void ImportWizardEmptyFoldersDontExcludeNodeModules() {
268244
var proj = XDocument.Load(path);
269245

270246
AssertUtil.ContainsExactly(proj.Descendants(proj.GetName("Folder")).Select(x => x.Attribute("Include").Value),
271-
"Baz", "node_modules");
247+
"Baz");
272248
}
273249

274250
[TestMethod, Priority(0)]
@@ -279,7 +255,6 @@ public void ProjectFileAlreadyExists() {
279255
settings.SourcePath = TestData.GetPath("TestData\\HelloWorld3");
280256
settings.Filters = "*.js";
281257
settings.StartupFile = "server.js";
282-
settings.ExcludeNodeModules = true;
283258
await Dispatcher.Yield();
284259
Assert.AreEqual("HelloWorld31.njsproj", Path.GetFileName(settings.ProjectPath));
285260
});
@@ -292,7 +267,6 @@ public void ImportWizardTypeScript() {
292267
settings.SourcePath = TestData.GetPath("TestData\\HelloWorldTypeScript\\");
293268
settings.Filters = "*.ts;*.md;*.json";
294269
settings.StartupFile = "server.ts";
295-
settings.ExcludeNodeModules = false;
296270
settings.ProjectPath = TestData.GetPath("TestData\\TestDestination\\TsSubdirectory\\ProjectName.njsproj");
297271

298272
var path = settings.CreateRequestedProject();

Nodejs/Tests/TestData/HelloWorld6/Baz/.gitignore

Whitespace-only changes.

Nodejs/Tests/TestData/HelloWorld6/bower_components/.gitignore

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var http = require('http');
2+
var port = process.env.port || 1337;
3+
http.createServer(function (req, res) {
4+
res.writeHead(200, { 'Content-Type': 'text/plain' });
5+
res.end('Hello World\n');
6+
}).listen(port);

0 commit comments

Comments
 (0)