feat(pack): rebuild plugins on :PluginUpdate

This commit is contained in:
2026-04-21 23:56:02 +02:00
parent 5723738f47
commit bb06f1818d
3 changed files with 83 additions and 15 deletions
+49 -2
View File
@@ -130,12 +130,45 @@ local watcher = nil
---@type ow.Util.KeyedDebounceHandle<string>?
local on_change_handle = nil
---@alias ow.Pack.Hook fun(ev: ow.Pack.Event.Data)
---@type table<string, ow.Pack.Hook>
local hooks = {}
---@class ow.Pack
---@field plugins ow.Pack.Plugin[]
local M = {
plugins = {},
}
---@param name string
---@param fn ow.Pack.Hook
function M.register_hook(name, fn)
hooks[name] = fn
end
local function setup_event_listener()
local group =
vim.api.nvim_create_augroup("ow.Pack.events", { clear = true })
vim.api.nvim_create_autocmd("PackChanged", {
group = group,
---@param ev ow.Pack.Event
callback = function(ev)
local name = ev.data.spec.name
if not name then
return
end
if ev.data.kind ~= "install" and ev.data.kind ~= "update" then
return
end
local hook = hooks[name]
if hook then
hook(ev.data)
end
end,
})
end
---@return string[]
function M.get_names()
return vim.tbl_map(function(p)
@@ -277,11 +310,25 @@ function M.setup(specs)
end)
for _, plugin in ipairs(M.plugins) do
if plugin.build and changed[plugin.name] then
run_build(plugin)
if plugin.build then
if changed[plugin.name] then
run_build(plugin)
end
M.register_hook(plugin.name, function(ev)
plugin.path = ev.path
run_build(plugin)
end)
end
load(plugin.name, false)
end
setup_event_listener()
end
---@param names? string[]
---@param opts? table
function M.update(names, opts)
vim.pack.update(names, opts)
end
return M