fix(pkg): correctly pre-load package specs and remove them when needed during resolve

This commit is contained in:
Folke Lemaitre 2024-06-23 17:49:19 +02:00
parent ee2ca39f67
commit 4326d4b487
6 changed files with 87 additions and 38 deletions

View file

@ -7,6 +7,7 @@ local M = {}
---@class LazyPkg
---@field source string
---@field name string
---@field file string
---@field spec? LazySpec
---@field chunk? string|fun():LazySpec
@ -30,6 +31,7 @@ function M.update()
for _, source in ipairs(sources) do
local spec = source.get(plugin)
if spec then
spec.name = plugin.name
if type(spec.chunk) == "function" then
spec.chunk = string.dump(spec.chunk)
end
@ -81,6 +83,25 @@ function M.get(plugin)
return ret
end
function M.spec()
if not M.cache then
_load()
end
---@type table<string,LazyPluginSpec>
local ret = {}
for dir in pairs(M.cache) do
local pkg = M.get({ dir = dir })
local spec = pkg and pkg.spec
if pkg and spec then
spec = type(spec) == "table" and vim.deepcopy(spec) or spec
ret[dir] = { pkg.name, specs = spec }
end
end
return ret
end
---@param plugin LazyPlugin
---@return LazySpec?
function M.get_spec(plugin)

View file

@ -29,24 +29,27 @@ function M.get(plugin)
end
---@type RockSpec?
---@diagnostic disable-next-line: missing-fields
local rockspec = {}
local ret, err = loadfile(rockspec_file, "t", rockspec)
if not ret then
local load, err = loadfile(rockspec_file, "t", rockspec)
if not load then
error(err)
end
ret()
return rockspec
and rockspec.package
load()
---@param dep string
local rocks = vim.tbl_filter(function(dep)
local name = dep:gsub("%s.*", "")
return not vim.tbl_contains(M.skip, name)
end, rockspec and rockspec.dependencies or {})
return #rocks > 0
and {
source = "rockspec",
file = rockspec_file,
spec = {
dir = plugin.dir,
url = plugin.url,
rocks = vim.tbl_filter(function(dep)
local name = dep:gsub("%s.*", "")
return not vim.tbl_contains(M.skip, name)
end, rockspec.dependencies),
plugin.name,
rocks = rocks,
},
}
or nil