Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

"kpm restore" prints out the dependency graph after restore #450

Merged
merged 1 commit into from
Jul 21, 2014

Conversation

ChengTian
Copy link
Contributor

parent #447

npm is using archy (https://github.com/substack/node-archy/blob/master/index.js) to print the dependency graph and I mimic the logic in archy to implement this feature.

Note that we print dependency graph for each target framework. Here are the dependency graphs for PackageManager itself:

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [.NETFramework,Version=v4.5]
├── Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT
│ ├─┬ Microsoft.Bcl.Metadata 1.0.11-alpha
│ │ └── Microsoft.Bcl.Immutable 1.1.20-beta
│ └── Newtonsoft.Json 5.0.8
├── Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT
├── Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT
└─┬ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT
  └─┬ K.Roslyn 1.0.0-alpha3-10032
    ├─┬ Microsoft.CodeAnalysis.Common 0.7.4060502-beta
    │ ├── Microsoft.Bcl.Immutable 1.1.20-beta
    │ └── Microsoft.Bcl.Metadata 1.0.11-alpha
    └── Microsoft.CodeAnalysis.CSharp 0.7.4060502-beta

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [K,Version=v1.0]
├── Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT
│ ├─┬ Microsoft.Bcl.Metadata 1.0.11-alpha
│ │ └── Microsoft.Bcl.Immutable 1.1.20-beta
│ └── Newtonsoft.Json 5.0.8
├── Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT
├── Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT
│ ├─┬ K.Roslyn 1.0.0-alpha3-10032
│ │ ├─┬ Microsoft.CodeAnalysis.Common 0.7.4060502-beta
│ │ │ ├── Microsoft.Bcl.Immutable 1.1.20-beta
│ │ │ └── Microsoft.Bcl.Metadata 1.0.11-alpha
│ │ └── Microsoft.CodeAnalysis.CSharp 0.7.4060502-beta
│ ├── System.Resources.ResourceWriter 4.0.0.0
│ ├── System.Runtime.Handles 4.0.0.0
│ └── System.Text.Encoding 4.0.20.0
├── System.Collections 4.0.10.0
├── System.Collections.Concurrent 4.0.0.0
├── System.ComponentModel 4.0.0.0
├── System.Console 4.0.0.0
├── System.Diagnostics.Debug 4.0.10.0
├── System.Diagnostics.Tools 4.0.0.0
├─┬ System.Dynamic.Runtime 4.0.0.0
│ └── System.Linq.Expressions 4.0.0.0
├── System.Globalization 4.0.10.0
├─┬ System.IO 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├─┬ System.IO.Compression 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├─┬ System.IO.FileSystem 4.0.10.0
│ ├── System.IO.FileSystem.Primitives 4.0.10.0
│ ├── System.Runtime.Handles 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├── System.IO.FileSystem.Watcher 4.0.0.0
├── System.Linq 4.0.0.0
├── System.ObjectModel 4.0.0.0
├─┬ System.Reflection 4.0.10.0
│ └── System.Reflection.Primitives 4.0.0.0
├── System.Reflection.Extensions 4.0.0.0
├── System.Reflection.TypeExtensions 4.0.0.0
├── System.Resources.ResourceManager 4.0.0.0
├── System.Runtime 4.0.20.0
├── System.Runtime.Extensions 4.0.10.0
├─┬ System.Runtime.InteropServices 4.0.20.0
│ ├── System.Reflection.Primitives 4.0.0.0
│ └── System.Runtime.Handles 4.0.0.0
├── System.Runtime.Loader 4.0.0.0
├── System.Runtime.Serialization.Primitives 4.0.0.0
├── System.Security.Cryptography.Encryption 4.0.0.0
├─┬ System.Security.Cryptography.Hashing.Algorithms 4.0.0.0
│ └── System.Security.Cryptography.Hashing 4.0.0.0
├── System.Text.RegularExpressions 4.0.0.0
├── System.Threading 4.0.0.0
├── System.Threading.Timer 4.0.0.0
├── System.Threading.Tasks 4.0.10.0
├── System.Threading.Thread 4.0.0.0
├─┬ System.Xml.ReaderWriter 4.0.10.0
│ └── System.Text.Encoding 4.0.10.0
├── System.Xml.XDocument 4.0.0.0
└── System.Xml.XmlSerializer 4.0.0.0

@davidfowl
Copy link
Member

Looks a little chatty, maybe we should only show a few levels instead of the entire graph. 2 or so.

@lodejard
Copy link
Contributor

See an example of npm install for an app that references express, as an example

for

 "dependencies": {
    "express": ">3.3.0",
    "jade": "*"
  }

summary

express@4.6.1 node_modules\express
├── merge-descriptors@0.0.2
├── utils-merge@1.0.0
├── parseurl@1.1.3
├── cookie@0.1.2
├── escape-html@1.0.1
├── cookie-signature@1.0.4
├── finalhandler@0.0.3
├── range-parser@1.0.0
├── fresh@0.2.2
├── vary@0.1.0
├── media-typer@0.2.0
├── qs@0.6.6
├── methods@1.1.0
├── serve-static@1.3.2
├── buffer-crc32@0.2.3
├── depd@0.3.0
├── path-to-regexp@0.1.3
├── debug@1.0.3 (ms@0.6.2)
├── proxy-addr@1.0.1 (ipaddr.js@0.1.2)
├── type-is@1.3.2 (mime-types@1.0.1)
├── send@0.6.0 (ms@0.6.2, mime@1.2.11, finished@1.2.2)
└── accepts@1.0.7 (negotiator@0.4.7, mime-types@1.0.1)

jade@1.4.2 node_modules\jade
├── character-parser@1.2.0
├── commander@2.1.0
├── mkdirp@0.5.0 (minimist@0.0.8)
├── monocle@1.1.51 (readdirp@0.2.5)
├── transformers@2.1.0 (promise@2.0.0, css@1.0.8, uglify-js@2.2.5)
├── with@3.0.0 (uglify-js@2.4.15)
└── constantinople@2.0.1 (uglify-js@2.4.15)

so it shows 3 levels: 1st is listed, 2nd is indented under 1st, 3rd is parenthetical in 2nd

@ChengTian
Copy link
Contributor Author

@lodejard , npm can make 3rd level dependencies parenthetical in 2nd because npm packages have short names. If we do the same thing, we will get a super long line if a 2nd level dependency has several dependencies:

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [K,Version=v1.0]
└── Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT (K.Roslyn 1.0.0-alpha3-10032, System.Resources.ResourceWriter 4.0.0.0, System.Runtime.Handles 4.0.0.0, System.Text.Encoding 4.0.20.0) 

@lodejard @davidfowl , the latest commit prints at most 3 levels of dependencies. Please find an example output below:

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [.NETFramework,Version=v4.5]
├── Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT
│ ├── Microsoft.Bcl.Metadata 1.0.11-alpha
│ └── Newtonsoft.Json 5.0.8
├── Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT
├── Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT
└─┬ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT
  └── K.Roslyn 1.0.0-alpha3-10032

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [K,Version=v1.0]
├── Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT
│ ├── Microsoft.Bcl.Metadata 1.0.11-alpha
│ └── Newtonsoft.Json 5.0.8
├── Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT
├── Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT
├─┬ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT
│ ├── K.Roslyn 1.0.0-alpha3-10032
│ ├── System.Resources.ResourceWriter 4.0.0.0
│ ├── System.Runtime.Handles 4.0.0.0
│ └── System.Text.Encoding 4.0.20.0
├── System.Collections 4.0.10.0
├── System.Collections.Concurrent 4.0.0.0
├── System.ComponentModel 4.0.0.0
├── System.Console 4.0.0.0
├── System.Diagnostics.Debug 4.0.10.0
├── System.Diagnostics.Tools 4.0.0.0
├─┬ System.Dynamic.Runtime 4.0.0.0
│ └── System.Linq.Expressions 4.0.0.0
├── System.Globalization 4.0.10.0
├─┬ System.IO 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├─┬ System.IO.Compression 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├─┬ System.IO.FileSystem 4.0.10.0
│ ├── System.IO.FileSystem.Primitives 4.0.10.0
│ ├── System.Runtime.Handles 4.0.0.0
│ └── System.Text.Encoding 4.0.10.0
├── System.IO.FileSystem.Watcher 4.0.0.0
├── System.Linq 4.0.0.0
├── System.ObjectModel 4.0.0.0
├─┬ System.Reflection 4.0.10.0
│ └── System.Reflection.Primitives 4.0.0.0
├── System.Reflection.Extensions 4.0.0.0
├── System.Reflection.TypeExtensions 4.0.0.0
├── System.Resources.ResourceManager 4.0.0.0
├── System.Runtime 4.0.20.0
├── System.Runtime.Extensions 4.0.10.0
├─┬ System.Runtime.InteropServices 4.0.20.0
│ ├── System.Reflection.Primitives 4.0.0.0
│ └── System.Runtime.Handles 4.0.0.0
├── System.Runtime.Loader 4.0.0.0
├── System.Runtime.Serialization.Primitives 4.0.0.0
├── System.Security.Cryptography.Encryption 4.0.0.0
├─┬ System.Security.Cryptography.Hashing.Algorithms 4.0.0.0
│ └── System.Security.Cryptography.Hashing 4.0.0.0
├── System.Text.RegularExpressions 4.0.0.0
├── System.Threading 4.0.0.0
├── System.Threading.Timer 4.0.0.0
├── System.Threading.Tasks 4.0.10.0
├── System.Threading.Thread 4.0.0.0
├─┬ System.Xml.ReaderWriter 4.0.10.0
│ └── System.Text.Encoding 4.0.10.0
├── System.Xml.XDocument 4.0.0.0
└── System.Xml.XmlSerializer 4.0.0.0

@ChengTian
Copy link
Contributor Author

Moreover, do we want kpm restore --full-graph, which shows full graph? It can help us to determine where a package comes from even the dependency hides deeply in a dependency chain

@davidfowl
Copy link
Member

Prefer the flat list, wrapping is fine

@ChengTian
Copy link
Contributor Author

@davidfowl @lodejard , thanks for the feedbacks. Here is the output of latest version:

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [.NETFramework,Version=v4.5]
├─ Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT ()
├─ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT (Microsoft.Bcl.Metadata 1.0.11-alpha, Newtonsoft.Json 5.0.8)
├─ Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT ()
├─ Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT ()
└─ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT (K.Roslyn 1.0.0-alpha3-10032)

Microsoft.Framework.PackageManager 1.0.0-SNAPSHOT [K,Version=v1.0]
├─ Microsoft.Framework.CommandLineUtils 1.0.0-SNAPSHOT ()
├─ Microsoft.Framework.Runtime 1.0.0-SNAPSHOT (Microsoft.Bcl.Metadata 1.0.11-alpha, Newtonsoft.Json 5.0.8)
├─ Microsoft.Framework.Runtime.Common 1.0.0-SNAPSHOT ()
├─ Microsoft.Framework.Runtime.Interfaces 1.0.0-SNAPSHOT ()
├─ Microsoft.Framework.Runtime.Roslyn 1.0.0-SNAPSHOT (K.Roslyn 1.0.0-alpha3-10032, System.Resources.ResourceWriter 4.0.0
.0, System.Runtime.Handles 4.0.0.0, System.Text.Encoding 4.0.20.0)
├─ System.Collections 4.0.10.0 ()
├─ System.Collections.Concurrent 4.0.0.0 ()
├─ System.ComponentModel 4.0.0.0 ()
├─ System.Console 4.0.0.0 ()
├─ System.Diagnostics.Debug 4.0.10.0 ()
├─ System.Diagnostics.Tools 4.0.0.0 ()
├─ System.Dynamic.Runtime 4.0.0.0 (System.Linq.Expressions 4.0.0.0)
├─ System.Globalization 4.0.10.0 ()
├─ System.IO 4.0.0.0 (System.Text.Encoding 4.0.10.0)
├─ System.IO.Compression 4.0.0.0 (System.Text.Encoding 4.0.10.0)
├─ System.IO.FileSystem 4.0.10.0 (System.IO.FileSystem.Primitives 4.0.10.0, System.Runtime.Handles 4.0.0.0, System.Text.
Encoding 4.0.10.0)
├─ System.IO.FileSystem.Watcher 4.0.0.0 ()
├─ System.Linq 4.0.0.0 ()
├─ System.ObjectModel 4.0.0.0 ()
├─ System.Reflection 4.0.10.0 (System.Reflection.Primitives 4.0.0.0)
├─ System.Reflection.Extensions 4.0.0.0 ()
├─ System.Reflection.TypeExtensions 4.0.0.0 ()
├─ System.Resources.ResourceManager 4.0.0.0 ()
├─ System.Runtime 4.0.20.0 ()
├─ System.Runtime.Extensions 4.0.10.0 ()
├─ System.Runtime.InteropServices 4.0.20.0 (System.Reflection.Primitives 4.0.0.0, System.Runtime.Handles 4.0.0.0)
├─ System.Runtime.Loader 4.0.0.0 ()
├─ System.Runtime.Serialization.Primitives 4.0.0.0 ()
├─ System.Security.Cryptography.Encryption 4.0.0.0 ()
├─ System.Security.Cryptography.Hashing.Algorithms 4.0.0.0 (System.Security.Cryptography.Hashing 4.0.0.0)
├─ System.Text.RegularExpressions 4.0.0.0 ()
├─ System.Threading 4.0.0.0 ()
├─ System.Threading.Timer 4.0.0.0 ()
├─ System.Threading.Tasks 4.0.10.0 ()
├─ System.Threading.Thread 4.0.0.0 ()
├─ System.Xml.ReaderWriter 4.0.10.0 (System.Text.Encoding 4.0.10.0)
├─ System.Xml.XDocument 4.0.0.0 ()
└─ System.Xml.XmlSerializer 4.0.0.0 ()

@davidfowl
Copy link
Member

Get rid of the empty parenthesis

@Eilon
Copy link
Member

Eilon commented Jul 19, 2014

Just use a smaller font :trollface:

var dependencyNum = dependencies.Count();
for (int i = 0; i < dependencyNum; i++)
{
var branchChar = '\u251C';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having some consts for the Unicode characters and to give them some nice names (maybe look up what Unicode calls them? Though those names are probably unwieldy...).

@ChengTian
Copy link
Contributor Author

@davidfowl @Eilon thanks for feedbacks. Improved in the latest commit.

@Eilon
Copy link
Member

Eilon commented Jul 21, 2014

Beautiful. :shipit:

@ChengTian ChengTian merged commit a2a93ac into dev Jul 21, 2014
@ChengTian ChengTian deleted the kpm-restore-print-dependency-graph branch July 21, 2014 21:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants