fix(meta): resolve deps from meta instead of fragments. Fixes #1566

This commit is contained in:
Folke Lemaitre 2024-06-27 10:21:54 +02:00
parent 24a86d5ca4
commit 6a423278a1
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 77 additions and 27 deletions

View File

@ -198,7 +198,10 @@ function M:_rebuild(name)
-- dependencies -- dependencies
for _, dep in ipairs(fragment.deps or {}) do for _, dep in ipairs(fragment.deps or {}) do
table.insert(plugin.dependencies, self.fragments:get(dep).name) local dep_meta = self.frag_to_meta[dep]
if dep_meta then
table.insert(plugin.dependencies, dep_meta.name)
end
end end
end end
end end

View File

@ -8,20 +8,27 @@ local function inspect(obj)
return vim.inspect(obj):gsub("%s+", " ") return vim.inspect(obj):gsub("%s+", " ")
end end
---@param plugins LazyPlugin[]|LazyPlugin ---@param plugin LazyPlugin
local function resolve(plugin)
local meta = getmetatable(plugin)
local ret = meta and type(meta.__index) == "table" and resolve(meta.__index) or {}
for k, v in pairs(plugin) do
ret[k] = v
end
return ret
end
---@param plugins LazyPlugin[]
local function clean(plugins) local function clean(plugins)
local p = plugins return vim.tbl_map(function(plugin)
plugins = type(plugins) == "table" and plugins or { plugins } plugin = resolve(plugin)
for _, plugin in pairs(plugins) do plugin[1] = nil
plugin._.fid = nil
plugin._.fpid = nil
plugin._.fdeps = nil
plugin._.frags = nil plugin._.frags = nil
if plugin._.dep == false then if plugin._.dep == false then
plugin._.dep = nil plugin._.dep = nil
end end
end return plugin
return p end, plugins)
end end
describe("plugin spec url/name", function() describe("plugin spec url/name", function()
@ -168,14 +175,12 @@ describe("plugin spec opt", function()
end end
assert.same({ assert.same({
bar = { bar = {
"foo/bar",
_ = {}, _ = {},
dependencies = { "dep1", "dep2" }, dependencies = { "dep1", "dep2" },
name = "bar", name = "bar",
url = "https://github.com/foo/bar.git", url = "https://github.com/foo/bar.git",
}, },
dep1 = { dep1 = {
"foo/dep1",
_ = { _ = {
dep = true, dep = true,
}, },
@ -183,7 +188,6 @@ describe("plugin spec opt", function()
url = "https://github.com/foo/dep1.git", url = "https://github.com/foo/dep1.git",
}, },
dep2 = { dep2 = {
"foo/dep2",
_ = { _ = {
dep = true, dep = true,
}, },
@ -198,13 +202,13 @@ describe("plugin spec opt", function()
before_each(function() before_each(function()
Handler.init() Handler.init()
end) end)
it("handles dep names", function()
Config.options.defaults.lazy = false Config.options.defaults.lazy = false
local tests = { local tests = {
{ { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } }, "foo/dep1" }, { { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } }, "foo/dep1" },
{ "foo/dep1", { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } } }, { "foo/dep1", { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } } },
} }
for _, test in ipairs(tests) do for _, test in ipairs(tests) do
it("handles dep names " .. inspect(test), function()
local spec = Plugin.Spec.new(vim.deepcopy(test)) local spec = Plugin.Spec.new(vim.deepcopy(test))
assert(#spec.notifs == 0) assert(#spec.notifs == 0)
Config.plugins = spec.plugins Config.plugins = spec.plugins
@ -213,31 +217,74 @@ describe("plugin spec opt", function()
for _, plugin in pairs(spec.plugins) do for _, plugin in pairs(spec.plugins) do
plugin.dir = nil plugin.dir = nil
end end
assert.same(clean(spec.plugins), { assert.same({
bar = { bar = {
"foo/bar",
_ = {}, _ = {},
dependencies = { "dep1", "dep2" }, dependencies = { "dep1", "dep2" },
name = "bar", name = "bar",
url = "https://github.com/foo/bar.git", url = "https://github.com/foo/bar.git",
}, },
dep1 = { dep1 = {
"foo/dep1",
_ = {}, _ = {},
name = "dep1", name = "dep1",
url = "https://github.com/foo/dep1.git", url = "https://github.com/foo/dep1.git",
}, },
dep2 = { dep2 = {
"foo/dep2",
_ = { _ = {
dep = true, dep = true,
}, },
name = "dep2", name = "dep2",
url = "https://github.com/foo/dep2.git", url = "https://github.com/foo/dep2.git",
}, },
}) }, clean(spec.plugins))
end
end) end)
end
Config.options.defaults.lazy = false
local tests = {
{
{ "foo/baz", name = "bar" },
{ "foo/fee", dependencies = { "foo/baz" } },
},
{
{ "foo/fee", dependencies = { "foo/baz" } },
{ "foo/baz", name = "bar" },
},
-- {
-- { "foo/baz", name = "bar" },
-- { "foo/fee", dependencies = { "baz" } },
-- },
{
{ "foo/baz", name = "bar" },
{ "foo/fee", dependencies = { "bar" } },
},
}
for _, test in ipairs(tests) do
it("handles dep names " .. inspect(test), function()
local spec = Plugin.Spec.new(vim.deepcopy(test))
assert(#spec.notifs == 0)
Config.plugins = spec.plugins
Plugin.update_state()
spec = Plugin.Spec.new(test)
spec.meta:rebuild()
for _, plugin in pairs(spec.plugins) do
plugin.dir = nil
end
assert.same({
bar = {
_ = {},
name = "bar",
url = "https://github.com/foo/baz.git",
},
fee = {
_ = {},
name = "fee",
url = "https://github.com/foo/fee.git",
dependencies = { "bar" },
},
}, clean(spec.plugins))
end)
end
it("handles opt from dep", function() it("handles opt from dep", function()
Config.options.defaults.lazy = false Config.options.defaults.lazy = false