feat(rocks): use hererocks to install luarocks when luarocks is not found

This commit is contained in:
Folke Lemaitre 2024-06-25 07:55:30 +02:00
commit d87da76679
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
5 changed files with 58 additions and 2 deletions

View file

@ -49,6 +49,8 @@ M.defaults = {
enabled = true,
root = vim.fn.stdpath("data") .. "/lazy-rocks",
server = "https://nvim-neorocks.github.io/rocks-binaries/",
-- use hererocks to install luarocks.
hererocks = vim.fn.executable("luarocks") == 0,
},
dev = {
---@type string | fun(plugin: LazyPlugin): string directory where you store your local plugin projects

View file

@ -33,7 +33,9 @@ function M:load_pkgs()
if not Config.options.pkg.enabled then
return
end
local have_rockspec = false
for _, pkg in ipairs(Pkg.get()) do
have_rockspec = have_rockspec or pkg.source == "rockspec"
local meta, fragment = self:add(pkg.spec)
if meta and fragment then
meta._.pkg = pkg
@ -46,6 +48,12 @@ function M:load_pkgs()
self.pkgs[pkg.dir] = fragment.id
end
end
if have_rockspec then
local hererocks = Pkg.hererocks()
if hererocks then
self:add(hererocks)
end
end
end
--- Remove a plugin and all its fragments.

View file

@ -264,8 +264,10 @@ function M.update_rocks_state()
end)
for _, plugin in pairs(Config.plugins) do
if plugin._.pkg and plugin._.pkg.source == "rockspec" and plugin.build == "rockspec" then
if plugin.build == "rockspec" then
plugin._.build = not installed[plugin.name]
elseif plugin.name == "hererocks" then
plugin._.build = not vim.uv.fs_stat(Config.options.rocks.root .. "/hererocks")
end
end
end