Skip to content

fix: main detection across :ZPack reload and in-session updates - #59

Merged
zuqini merged 8 commits into
mainfrom
zpack.nvim-audit-since-3.0
Nov 15, 2026
Merged

zuqini merged 8 commits into
mainfrom
zpack.nvim-audit-since-3.0

Conversation

@zuqini

@zuqini zuqini commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Follow-ups to #55, #57 and #58 from an audit of what they changed.

Fixes

  • reload: a main module found on the first load is detected again on :ZPack reload, as in lazy.nvim. After an update renamed the plugin's module, reload ran the old module's setup() from package.loaded.
  • utils: the "main not found" cache is gone, so a reload after an update that adds the module finds it.
  • hooks: the PackChanged handler resets vim.loader's index for the updated plugin. zpack enables vim.loader by default, and it lists each plugin's top-level modules once, so a module an update added or renamed couldn't be required until restart.
  • plugin_loader: a detected main is set before a plugin's opts functions run, so opts functions see it as config does.
  • health: the "not yet on disk" warning advises a restart. :ZPack update can't install a plugin that was never installed.

Docs

  • :ZPack! load and its completion skip plugins whose cond is false (README, vimdoc).
  • plugin.main is detected before opts functions and config on each load, :ZPack reload included (vimdoc, docs/spec.md, types.lua).
  • A keymap.maparg comment said ! is read as normal mode; it is read as :map's modes.

Testing

  • Each fix has a test that fails without it. The resolve_main caching tests, which stopped testing anything when fix: main detection beside a compiled module, and the spec's main on the plugin in every hook #57 dropped the spec argument, now pin the cache.
  • luacheck and LuaLS are clean. The suite passes on nightly (1519) and v0.12.0 (1518).
  • zb check against the base: no lazy flips, structural or opts differences.
  • zb perf --rows matrix (36 rows, both nvims) against the base: no row slower with a CI excluding 0. The rows flagged as not faster than lazy.nvim (trig150, ftd150 and fton150 on 0.12) are flagged at the base too.
  • In a real Neovim with real vim.pack, a git plugin whose update renames its module then gets the new module's setup() on :ZPack reload, on nightly and v0.12.0.

resolve_main cached a miss per src until the plugin was deleted, so after an
in-session update added the module, :ZPack reload still found no main. Its
only caller runs once per load, so the cache saved a cached lsdir walk on a
manual reload. Drop it; a found main stays cached on plugin.main.
…gument

The two caching tests asserted the spec's main, which registration puts on the
plugin, and changed spec.main, which resolve_main no longer reads, so neither
failed when a detected main wasn't kept on plugin.main.
A detected main stayed on plugin.main for the session, so after an update
renamed the plugin's module, :ZPack reload called the old module's setup
from package.loaded. Reload now puts the spec's main back on the plugin
after deactivate, so init, opts and config see what they see on a first
load, and detection runs again.
vim.loader lists each 'runtimepath' entry's top-level modules once, so
after an update added or renamed one, requiring it failed until restart
(zpack enables vim.loader by default), and :ZPack reload reported
"Failed to require" for the module it had just detected. The PackChanged
handler now resets that plugin's entry beside zpack's own caches.
A plugin with no explicit main got its detected module on plugin.main only
after its opts functions, so an opts function saw nil there while config saw
the module. Detection now runs first, so both see it on every load.
The installing count told the user to run :ZPack update, which fails for a
plugin that was never installed (its install prompt declined or failed).
vim.pack.add installs synchronously, so nothing is still installing once
setup() returns; a restart is what installs it.
@zuqini
zuqini merged commit 324559a into main Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant