2024-06-18 20:54:54 +01:00
|
|
|
--# selene:allow(incorrect_standard_library_use)
|
|
|
|
|
|
|
|
local Util = require("lazy.core.util")
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
2024-06-24 13:14:41 +01:00
|
|
|
M.dev_suffix = "-1.rockspec"
|
2024-06-18 20:54:54 +01:00
|
|
|
M.skip = { "lua" }
|
|
|
|
|
|
|
|
---@class RockSpec
|
|
|
|
---@field rockspec_format string
|
|
|
|
---@field package string
|
|
|
|
---@field version string
|
|
|
|
---@field dependencies string[]
|
|
|
|
|
|
|
|
---@param plugin LazyPlugin
|
2024-06-24 13:14:41 +01:00
|
|
|
---@return LazyPkgSpec?
|
2024-06-18 20:54:54 +01:00
|
|
|
function M.get(plugin)
|
|
|
|
local rockspec_file ---@type string?
|
|
|
|
Util.ls(plugin.dir, function(path, name, t)
|
|
|
|
if t == "file" and name:sub(-#M.dev_suffix) == M.dev_suffix then
|
|
|
|
rockspec_file = path
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
if not rockspec_file then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
---@type RockSpec?
|
2024-06-23 16:49:19 +01:00
|
|
|
---@diagnostic disable-next-line: missing-fields
|
2024-06-18 20:54:54 +01:00
|
|
|
local rockspec = {}
|
2024-06-23 16:49:19 +01:00
|
|
|
local load, err = loadfile(rockspec_file, "t", rockspec)
|
|
|
|
if not load then
|
2024-06-18 20:54:54 +01:00
|
|
|
error(err)
|
|
|
|
end
|
2024-06-23 16:49:19 +01:00
|
|
|
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 {})
|
|
|
|
|
2024-06-24 13:14:41 +01:00
|
|
|
local use = #rocks > 0
|
|
|
|
use = true
|
|
|
|
|
|
|
|
local lazy = nil
|
|
|
|
if not vim.uv.fs_stat(plugin.dir .. "/lua") then
|
|
|
|
lazy = false
|
|
|
|
end
|
|
|
|
|
|
|
|
return use
|
2024-06-18 20:54:54 +01:00
|
|
|
and {
|
2024-06-23 21:00:48 +01:00
|
|
|
file = vim.fn.fnamemodify(rockspec_file, ":t"),
|
2024-06-18 20:54:54 +01:00
|
|
|
spec = {
|
2024-06-23 16:49:19 +01:00
|
|
|
plugin.name,
|
2024-06-24 13:14:41 +01:00
|
|
|
build = "rockspec",
|
|
|
|
lazy = lazy,
|
2024-06-18 20:54:54 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
or nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|