feat: added support for plugin packages by lazy, rockspec and packspec

This commit is contained in:
Folke Lemaitre 2024-06-18 21:54:54 +02:00
parent f1ba2e3d05
commit 3be55a4615
11 changed files with 281 additions and 171 deletions

28
lua/lazy/pkg/lazy.lua Normal file
View file

@ -0,0 +1,28 @@
local Util = require("lazy.util")
local M = {}
M.lazy_file = "lazy.lua"
---@param plugin LazyPlugin
---@return LazyPkg?
function M.get(plugin)
local file = Util.norm(plugin.dir .. "/" .. M.lazy_file)
if Util.file_exists(file) then
---@type fun(): LazySpec
local chunk = Util.try(function()
local ret, err = loadfile(file)
return err and error(err) or ret
end, "`" .. M.lazy_file .. "` for **" .. plugin.name .. "** has errors:")
if not chunk then
Util.error("Invalid `" .. M.lazy_file .. "` for **" .. plugin.name .. "**")
end
return {
source = "lazy",
file = M.lazy_file,
chunk = chunk,
}
end
end
return M