Skip to content

Commit

Permalink
allow uninstalling dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 12, 2020
1 parent d40efee commit 774e098
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pkg/gui/dependencies_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,64 @@ func (gui *Gui) handleOpenDepPackageConfig() error {

return gui.openFile(selectedDep.ConfigPath())
}

func (gui *Gui) handleDepUninstall() error {
selectedDep := gui.getSelectedDependency()
if selectedDep == nil {
return nil
}

var menuItems []*menuItem

if selectedDep.Kind == "peer" {
// I have no idea how peer dependencies work, so we're just using the one option here
uninstallStr := fmt.Sprintf("npm uninstall %s", selectedDep.Name)

menuItems = []*menuItem{
{
displayStrings: []string{"uninstall", utils.ColoredString(uninstallStr, color.FgYellow)},
onPress: func() error {
cmd := gui.OSCommand.ExecutableFromString(uninstallStr)
if err := gui.newPtyTask("main", cmd, uninstallStr); err != nil {
gui.Log.Error(err)
}
return nil
},
},
}
} else {
kindMap := map[string]string{
"prod": " --save",
"dev": " --save-dev",
"optional": " --save-optional",
}

uninstallCmdStr := fmt.Sprintf("npm uninstall --no-save %s", selectedDep.Name)
uninstallAndSaveCmdStr := fmt.Sprintf("npm uninstall%s %s", kindMap[selectedDep.Kind], selectedDep.Name)

menuItems = []*menuItem{
{
displayStrings: []string{"uninstall and save", utils.ColoredString(uninstallAndSaveCmdStr, color.FgYellow)},
onPress: func() error {
cmd := gui.OSCommand.ExecutableFromString(uninstallAndSaveCmdStr)
if err := gui.newPtyTask("main", cmd, uninstallAndSaveCmdStr); err != nil {
gui.Log.Error(err)
}
return nil
},
},
{
displayStrings: []string{"just uninstall", utils.ColoredString(uninstallCmdStr, color.FgYellow)},
onPress: func() error {
cmd := gui.OSCommand.ExecutableFromString(uninstallCmdStr)
if err := gui.newPtyTask("main", cmd, uninstallCmdStr); err != nil {
gui.Log.Error(err)
}
return nil
},
},
}
}

return gui.createMenu("Uninstall dependency", menuItems, createMenuOptions{showCancel: true})
}
7 changes: 7 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.wrappedHandler(gui.handleDepUpdate),
Description: "`npm update` dependency",
},
{
ViewName: "deps",
Key: gui.getKey("universal.remove"),
Modifier: gocui.ModNone,
Handler: gui.wrappedHandler(gui.handleDepUninstall),
Description: "`npm uninstall` dependency",
},
}

for _, viewName := range []string{"status", "packages", "deps", "scripts", "menu"} {
Expand Down

0 comments on commit 774e098

Please # to comment.