- Display latest package versions as virtual text
- Upgrade package on current line to latest version
- Delete package on current line
- Install a different version of a package on current line
- Install new package
- Reinstall dependencies
- Automatic package manager detection
- Loading animation hook (to be placed in status bar or anywhere else)
Runs npm outdated --json
in the background and then compares the output with versions in package.json
and displays them as virtual text.
vim.api.nvim_set_keymap(
"n",
"<leader>ns",
"<cmd>lua require('package-info').show()<cr>",
{ silent = true, noremap = true }
)
- NOTE: after the first outdated dependency fetch, it will show the cached results for the next hour instead of re-fetching every time.
- If you would like to force re-fetching every time you can provide
force = true
like in the example below:
vim.api.nvim_set_keymap(
"n",
"<leader>ns",
"<cmd>lua require('package-info').show({ force = true })<cr>",
{ silent = true, noremap = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>nd",
"<cmd>lua require('package-info').delete()<cr>",
{ silent = true, noremap = true }
)
Runs npm install package@version
or yarn upgrade package@version
in the background and reloads the buffer.
vim.api.nvim_set_keymap(
"n",
"<leader>np",
"<cmd>lua require('package-info').change_version()<cr>",
{ silent = true, noremap = true }
)
vim.api.nvim_set_keymap(
"n",
"<leader>ni",
"<cmd>lua require('package-info').install()<cr>",
{ silent = true, noremap = true }
)
Runs rm -rf node_modules && yarn
or rm -rf node_modules && npm install
in the background and reloads the buffer.
vim.api.nvim_set_keymap(
"n",
"<leader>nr",
"<cmd>lua require('package-info').reinstall()<cr>",
{ silent = true, noremap = true }
)
- It can be used anywhere in
neovim
by invokingreturn require('package-info').get_status()
local package = require("package-info")
-- Galaxyline
section.left[10] = {
PackageInfoStatus = {
provider = function()
return package.get_status()
end,
},
}
-- Feline
components.right.active[5] = {
provider = function()
return package.get_status()
end,
hl = {
style = "bold",
},
left_sep = " ",
right_sep = " ",
}
- Neovim >= 0.5.0
- Npm
- Patched font if you want icons
use({
"vuki656/package-info.nvim",
requires = "MunifTanjim/nui.nvim",
})
require('package-info').setup()
{
colors = {
up_to_date = "#3C4048", -- Text color for up to date package virtual text
outdated = "#d19a66", -- Text color for outdated package virtual text
},
icons = {
enable = true, -- Whether to display icons
style = {
up_to_date = "| ", -- Icon for up to date packages
outdated = "| ", -- Icon for outdated packages
},
},
autostart = true -- Whether to autostart when `package.json` is opened
hide_up_to_date = true -- It hides up to date versions when displaying virtual text
hide_unstable_versions = false, -- It hides unstable versions from version list e.g next-11.1.3-canary3
-- Can be `npm` or `yarn`. Used for `delete`, `install` etc...
-- The plugin will try to auto-detect the package manager based on
-- `yarn.lock` or `package-lock.json`. If none are found it will use the
-- provided one, if nothing is provided it will use `yarn`
package_manager = `yarn`
}
- If the vim option
termguicolors
is false, package-info switches to 256 color mode. - In this mode cterm color numbers are used instead of truecolor hex codes and the color defaults are:
colors = {
up_to_date = "237", -- cterm Grey237
outdated = "173", -- cterm LightSalmon3
}
Package info has no default Keybindings.
You can copy the ones below:
-- Show package versions
vim.api.nvim_set_keymap("n", "<leader>ns", ":lua require('package-info').show()<CR>", { silent = true, noremap = true })
-- Hide package versions
vim.api.nvim_set_keymap("n", "<leader>nc", ":lua require('package-info').hide()<CR>", { silent = true, noremap = true })
-- Update package on line
vim.api.nvim_set_keymap("n", "<leader>nu", ":lua require('package-info').update()<CR>", { silent = true, noremap = true })
-- Delete package on line
vim.api.nvim_set_keymap("n", "<leader>nd", ":lua require('package-info').delete()<CR>", { silent = true, noremap = true })
-- Install a new package
vim.api.nvim_set_keymap("n", "<leader>ni", ":lua require('package-info').install()<CR>", { silent = true, noremap = true })
-- Reinstall dependencies
vim.api.nvim_set_keymap("n", "<leader>nr", ":lua require('package-info').reinstall()<CR>", { silent = true, noremap = true })
-- Install a different package version
vim.api.nvim_set_keymap("n", "<leader>np", ":lua require('package-info').change_version()<CR>", { silent = true, noremap = true })
-
If you want to test out new features use the
develop
branch.master
should be stable and tested by me. I test features on develop for a couple of days before merging them to master -
Display might be slow on a project with a lot of packages. This is due to the
npm outdated
command taking a long time. Nothing can be done about that -
Idea was inspired by akinsho and his dependency-assist.nvim
-
Readme template stolen from folke
-
This is my first
neovim
plugin so please don't hesitate to open an issue an tell me if you find anything stupid in the code :D.