Skip to content

Commit 6a42327

Browse files
committed
fix(meta): resolve deps from meta instead of fragments. Fixes #1566
1 parent 24a86d5 commit 6a42327

File tree

2 files changed

+77
-27
lines changed

2 files changed

+77
-27
lines changed

lua/lazy/core/meta.lua

+4-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ function M:_rebuild(name)
198198

199199
-- dependencies
200200
for _, dep in ipairs(fragment.deps or {}) do
201-
table.insert(plugin.dependencies, self.fragments:get(dep).name)
201+
local dep_meta = self.frag_to_meta[dep]
202+
if dep_meta then
203+
table.insert(plugin.dependencies, dep_meta.name)
204+
end
202205
end
203206
end
204207
end

tests/core/plugin_spec.lua

+73-26
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ local function inspect(obj)
88
return vim.inspect(obj):gsub("%s+", " ")
99
end
1010

11-
---@param plugins LazyPlugin[]|LazyPlugin
11+
---@param plugin LazyPlugin
12+
local function resolve(plugin)
13+
local meta = getmetatable(plugin)
14+
local ret = meta and type(meta.__index) == "table" and resolve(meta.__index) or {}
15+
for k, v in pairs(plugin) do
16+
ret[k] = v
17+
end
18+
return ret
19+
end
20+
21+
---@param plugins LazyPlugin[]
1222
local function clean(plugins)
13-
local p = plugins
14-
plugins = type(plugins) == "table" and plugins or { plugins }
15-
for _, plugin in pairs(plugins) do
16-
plugin._.fid = nil
17-
plugin._.fpid = nil
18-
plugin._.fdeps = nil
23+
return vim.tbl_map(function(plugin)
24+
plugin = resolve(plugin)
25+
plugin[1] = nil
1926
plugin._.frags = nil
2027
if plugin._.dep == false then
2128
plugin._.dep = nil
2229
end
23-
end
24-
return p
30+
return plugin
31+
end, plugins)
2532
end
2633

2734
describe("plugin spec url/name", function()
@@ -168,22 +175,19 @@ describe("plugin spec opt", function()
168175
end
169176
assert.same({
170177
bar = {
171-
"foo/bar",
172178
_ = {},
173179
dependencies = { "dep1", "dep2" },
174180
name = "bar",
175181
url = "https://github.com/foo/bar.git",
176182
},
177183
dep1 = {
178-
"foo/dep1",
179184
_ = {
180185
dep = true,
181186
},
182187
name = "dep1",
183188
url = "https://github.com/foo/dep1.git",
184189
},
185190
dep2 = {
186-
"foo/dep2",
187191
_ = {
188192
dep = true,
189193
},
@@ -198,13 +202,13 @@ describe("plugin spec opt", function()
198202
before_each(function()
199203
Handler.init()
200204
end)
201-
it("handles dep names", function()
202-
Config.options.defaults.lazy = false
203-
local tests = {
204-
{ { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } }, "foo/dep1" },
205-
{ "foo/dep1", { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } } },
206-
}
207-
for _, test in ipairs(tests) do
205+
Config.options.defaults.lazy = false
206+
local tests = {
207+
{ { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } }, "foo/dep1" },
208+
{ "foo/dep1", { "foo/bar", dependencies = { { "dep1" }, "foo/dep2" } } },
209+
}
210+
for _, test in ipairs(tests) do
211+
it("handles dep names " .. inspect(test), function()
208212
local spec = Plugin.Spec.new(vim.deepcopy(test))
209213
assert(#spec.notifs == 0)
210214
Config.plugins = spec.plugins
@@ -213,31 +217,74 @@ describe("plugin spec opt", function()
213217
for _, plugin in pairs(spec.plugins) do
214218
plugin.dir = nil
215219
end
216-
assert.same(clean(spec.plugins), {
220+
assert.same({
217221
bar = {
218-
"foo/bar",
219222
_ = {},
220223
dependencies = { "dep1", "dep2" },
221224
name = "bar",
222225
url = "https://github.com/foo/bar.git",
223226
},
224227
dep1 = {
225-
"foo/dep1",
226228
_ = {},
227229
name = "dep1",
228230
url = "https://github.com/foo/dep1.git",
229231
},
230232
dep2 = {
231-
"foo/dep2",
232233
_ = {
233234
dep = true,
234235
},
235236
name = "dep2",
236237
url = "https://github.com/foo/dep2.git",
237238
},
238-
})
239-
end
240-
end)
239+
}, clean(spec.plugins))
240+
end)
241+
end
242+
243+
Config.options.defaults.lazy = false
244+
local tests = {
245+
{
246+
{ "foo/baz", name = "bar" },
247+
{ "foo/fee", dependencies = { "foo/baz" } },
248+
},
249+
{
250+
{ "foo/fee", dependencies = { "foo/baz" } },
251+
{ "foo/baz", name = "bar" },
252+
},
253+
-- {
254+
-- { "foo/baz", name = "bar" },
255+
-- { "foo/fee", dependencies = { "baz" } },
256+
-- },
257+
{
258+
{ "foo/baz", name = "bar" },
259+
{ "foo/fee", dependencies = { "bar" } },
260+
},
261+
}
262+
for _, test in ipairs(tests) do
263+
it("handles dep names " .. inspect(test), function()
264+
local spec = Plugin.Spec.new(vim.deepcopy(test))
265+
assert(#spec.notifs == 0)
266+
Config.plugins = spec.plugins
267+
Plugin.update_state()
268+
spec = Plugin.Spec.new(test)
269+
spec.meta:rebuild()
270+
for _, plugin in pairs(spec.plugins) do
271+
plugin.dir = nil
272+
end
273+
assert.same({
274+
bar = {
275+
_ = {},
276+
name = "bar",
277+
url = "https://github.com/foo/baz.git",
278+
},
279+
fee = {
280+
_ = {},
281+
name = "fee",
282+
url = "https://github.com/foo/fee.git",
283+
dependencies = { "bar" },
284+
},
285+
}, clean(spec.plugins))
286+
end)
287+
end
241288

242289
it("handles opt from dep", function()
243290
Config.options.defaults.lazy = false

0 commit comments

Comments
 (0)