fix(pack)!: do not trigger PackChanged[Pre] kind=update during install

Problem: `PackChanged[Pre]` events with `kind=update` are triggered both
  during plugin's initial installation and after already installed
  plugin was updated.

  It was a deliberate decision to allow writing only a single update
  hook to act as a dedicated "build" entry point (like execute `make` or
  `cargo build —release`). This mimics how other plugin managers have a
  single "build" command.

  This was a result of 'mini.deps' experience with the different
  approach: "update" hooks are not run during install. This proved to be
  confusing as it requires to write two hooks. But also the reason might
  be that 'mini.deps' names it "checkout" hook instead of "update".

  However, the `vim.pack` event approach makes it lower cost to handle
  separate "update" and "install" events. Something like
  `if ev.data.kind == 'install' or ev.data.kind == 'update' then`
  instead of two autocommands.
  Plus this makes clearer separation of events.

Solution: do not trigger `PackChanged[Pre] kind=update` event during
  install.
This commit is contained in:
Evgeni Chasnovski
2025-10-23 18:35:27 +03:00
parent a9db6ec6fa
commit 16a6559ec6
2 changed files with 13 additions and 31 deletions

View File

@@ -674,23 +674,13 @@ describe('vim.pack', function()
local find_event = make_find_packchanged(log)
local installpre_basic = find_event('Pre', 'install', 'basic', 'feat-branch', false)
local installpre_defbranch = find_event('Pre', 'install', 'defbranch', nil, false)
local updatepre_basic = find_event('Pre', 'update', 'basic', 'feat-branch', false)
local updatepre_defbranch = find_event('Pre', 'update', 'defbranch', nil, false)
local update_basic = find_event('', 'update', 'basic', 'feat-branch', false)
local update_defbranch = find_event('', 'update', 'defbranch', nil, false)
local install_basic = find_event('', 'install', 'basic', 'feat-branch', false)
local install_defbranch = find_event('', 'install', 'defbranch', nil, false)
eq(8, #log)
eq(4, #log)
-- NOTE: There is no guaranteed installation order among separate plugins (as it is async)
eq(true, installpre_basic < updatepre_basic)
eq(true, updatepre_basic < update_basic)
-- NOTE: "Install" is after "update" to indicate installation at correct version
eq(true, update_basic < install_basic)
eq(true, installpre_defbranch < updatepre_defbranch)
eq(true, updatepre_defbranch < update_defbranch)
eq(true, update_defbranch < install_defbranch)
eq(true, installpre_basic < install_basic)
eq(true, installpre_defbranch < install_defbranch)
end)
it('recognizes several `version` types', function()