-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from mousetraps/npm3
- Loading branch information
Showing
24 changed files
with
432 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
Nodejs/Product/Analysis/Analysis/Analyzer/RequireAnalysisUnit.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//*********************************************************// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// | ||
// Apache 2.0 License | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
//*********************************************************// | ||
|
||
using System.Diagnostics; | ||
using System.Threading; | ||
|
||
namespace Microsoft.NodejsTools.Analysis.Analyzer { | ||
class RequireAnalysisUnit : AnalysisUnit { | ||
private string _dependency; | ||
private ModuleTree _tree; | ||
private ModuleTable _table; | ||
|
||
internal RequireAnalysisUnit(ModuleTree tree, ModuleTable table, ProjectEntry entry, string dependency) : base (entry.Tree, entry.EnvironmentRecord) { | ||
_tree = tree; | ||
_table = table; | ||
_dependency = dependency; | ||
} | ||
|
||
internal override void AnalyzeWorker(DDG ddg, CancellationToken cancel) { | ||
ModuleTree module = _table.RequireModule(this, _dependency, _tree); | ||
if (module == null) { | ||
return; | ||
} | ||
|
||
AddChildVisibilitiesExcludingNodeModules(module); | ||
} | ||
|
||
private void AddChildVisibilitiesExcludingNodeModules(ModuleTree moduleTree) { | ||
foreach (var childTree in moduleTree.GetChildrenExcludingNodeModules()) { | ||
Debug.Assert(childTree.Name != AnalysisConstants.NodeModulesFolder); | ||
if (childTree.ProjectEntry == null) { | ||
AddChildVisibilitiesExcludingNodeModules(childTree); | ||
} else { | ||
_table.AddVisibility(_tree, childTree.ProjectEntry); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//*********************************************************// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// | ||
// Apache 2.0 License | ||
// | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
// | ||
//*********************************************************// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.NodejsTools.Analysis { | ||
internal static class ModuleTreeExtensions { | ||
internal static IEnumerable<ModuleTree> GetChildrenExcludingNodeModules(this ModuleTree moduleTree) { | ||
if (moduleTree == null) { | ||
return Enumerable.Empty<ModuleTree>(); | ||
} | ||
// Children.Values returns an IEnumerable | ||
// The process of resolving modules can lead us to add entries into the underlying array | ||
// doing so results in exceptions b/c the array has changed under the enumerable | ||
// To avoid this, we call .ToArray() to create a copy of the array locally which we then Enumerate | ||
return moduleTree.Children.Values.ToArray().Where(mod => !String.Equals(mod.Name, AnalysisConstants.NodeModulesFolder, StringComparison.OrdinalIgnoreCase)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.