Skip to content

Commit

Permalink
feat(commands): added build command to force rebuild of a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 1, 2023
1 parent 205ce42 commit 23c0587
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ Any operation can be started from the UI, with a sub command or an API function:

| Command | Lua | Description |
| ------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `:Lazy build {plugins}` | `require("lazy").build(opts)` | Rebuild a plugin |
| `:Lazy check [plugins]` | `require("lazy").check(opts?)` | Check for updates and show the log (git fetch) |
| `:Lazy clean [plugins]` | `require("lazy").clean(opts?)` | Clean plugins that are no longer needed |
| `:Lazy clear` | `require("lazy").clear()` | Clear finished tasks |
Expand Down
11 changes: 11 additions & 0 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ function M.log(opts)
}, opts)
end

---@param opts? ManagerOpts
function M.build(opts)
opts = M.opts(opts, { mode = "build" })
return M.run({
pipeline = { { "plugin.build", force = true } },
plugins = function()
return false
end,
}, opts)
end

---@param opts? ManagerOpts
function M.sync(opts)
opts = M.opts(opts)
Expand Down
6 changes: 5 additions & 1 deletion lua/lazy/manage/task/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ local Loader = require("lazy.core.loader")
local M = {}

M.build = {
skip = function(plugin)
---@param opts? {force:boolean}
skip = function(plugin, opts)
if opts and opts.force then
return false
end
return not (plugin._.dirty and plugin.build)
end,
run = function(self)
Expand Down
10 changes: 7 additions & 3 deletions lua/lazy/view/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ function M.cmd(cmd, opts)
local command = M.commands[cmd] --[[@as fun(opts)]]
if command == nil then
Util.error("Invalid lazy command '" .. cmd .. "'")
elseif
ViewConfig.commands[cmd]
and ViewConfig.commands[cmd].plugins_required
and not (opts and vim.tbl_count(opts.plugins or {}) > 0)
then
return Util.error("`Lazy " .. cmd .. "` requires at least one plugin")
else
command(opts)
end
Expand Down Expand Up @@ -44,12 +50,10 @@ M.commands = {
end,
---@param opts ManagerOpts
load = function(opts)
if not (opts and opts.plugins and #opts.plugins > 0) then
return Util.error("`Lazy load` requires at least one plugin name to load")
end
require("lazy.core.loader").load(opts.plugins, { cmd = "LazyLoad" })
end,
log = Manage.log,
build = Manage.build,
clean = Manage.clean,
install = Manage.install,
sync = Manage.sync,
Expand Down
7 changes: 7 additions & 0 deletions lua/lazy/view/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ M.commands = {
desc = "Run `:checkhealth lazy`",
id = 14,
},
build = {
desc = "Rebuild a plugin",
id = 13,
plugins = true,
plugins_required = true,
key_plugin = "b",
},
}

return M

0 comments on commit 23c0587

Please sign in to comment.