Skip to content

Commit

Permalink
put all dependencies in the one panel
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 11, 2020
1 parent 39c06e9 commit d40efee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
1 change: 1 addition & 0 deletions pkg/commands/config_parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func UnmarshalPackageConfig(r io.Reader) (*PackageConfig, error) {
})
}
}

value, dataType, _, err := jsonparser.Get(configData, "contributors")
if err != nil {
if err != jsonparser.KeyPathNotFoundError {
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Dependency struct {
Present bool
PackageConfig *PackageConfig
Path string
Kind string
}

func (d *Dependency) Linked() bool {
Expand Down
58 changes: 40 additions & 18 deletions pkg/commands/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type PackageConfig struct {
DevDependencies map[string]string
PeerDependencies map[string]string
OptionalDependencies map[string]string
SortedDependencies []*Dependency
Engines struct {
Node string
Npm string
Expand Down Expand Up @@ -82,26 +83,47 @@ type Package struct {
LinkedGlobally bool
}

func (p *Package) SortedDepsGeneric(depMap map[string]string) []*Dependency {
deps := make([]*Dependency, 0, len(depMap))
for name, version := range depMap {
deps = append(deps, &Dependency{Name: name, Version: version})
func (p *Package) SortedDependencies() []*Dependency {
deps := make([]*Dependency, 0, len(p.Config.Dependencies)+len(p.Config.DevDependencies)+len(p.Config.PeerDependencies)+len(p.Config.OptionalDependencies))

type blah struct {
kind string
depMap map[string]string
}
sort.Slice(deps, func(i, j int) bool { return strings.Compare(deps[i].Name, deps[j].Name) < 0 })
return deps
}

func (p *Package) SortedDependencies() []*Dependency {
return p.SortedDepsGeneric(p.Config.Dependencies)
}
func (p *Package) SortedDevDependencies() []*Dependency {
return p.SortedDepsGeneric(p.Config.DevDependencies)
}
func (p *Package) SortedPeerDependencies() []*Dependency {
return p.SortedDepsGeneric(p.Config.PeerDependencies)
}
func (p *Package) SortedOptionalDependencies() []*Dependency {
return p.SortedDepsGeneric(p.Config.OptionalDependencies)
them := []blah{
{
kind: "prod",
depMap: p.Config.Dependencies,
},
{
kind: "dev",
depMap: p.Config.DevDependencies,
},
{
kind: "peer",
depMap: p.Config.PeerDependencies,
},
{
kind: "optional",
depMap: p.Config.OptionalDependencies,
},
}

for _, mapping := range them {
depsForKind := make([]*Dependency, 0, len(mapping.depMap))
for name, constraint := range mapping.depMap {
depsForKind = append(depsForKind, &Dependency{
Name: name,
Version: constraint,
Kind: mapping.kind,
})
}
sort.Slice(depsForKind, func(i, j int) bool { return strings.Compare(depsForKind[i].Name, depsForKind[j].Name) < 0 })
deps = append(deps, depsForKind...)
}

return deps
}

func (p *Package) SortedScripts() []*Script {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/presentation/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func getDepDisplayStrings(d *commands.Dependency) []string {
localVersionCol = utils.ColoredString("missing", color.FgRed)
}

return []string{d.Name, utils.ColoredString(d.Version, color.FgMagenta), localVersionCol}
return []string{d.Name, d.Kind, utils.ColoredString(d.Version, color.FgMagenta), localVersionCol}
}

func statusMap() map[int]string {
Expand Down

0 comments on commit d40efee

Please sign in to comment.