add support for modules again
This commit is contained in:
29
lua/dep.lua
29
lua/dep.lua
@ -27,14 +27,14 @@ function M.benchmark(name, code, ...)
|
||||
end
|
||||
|
||||
--- recurse over all packages and register them
|
||||
---@param speclist spec[] table of specs
|
||||
---@param speclist speclist table of specs
|
||||
---@param overrides spec? a package spec that is used to override options
|
||||
function M.registertree(speclist, overrides)
|
||||
overrides = overrides or {}
|
||||
|
||||
-- recurse the packages
|
||||
local over = overrides
|
||||
for _, spec in pairs(speclist) do
|
||||
for _, spec in ipairs(speclist) do
|
||||
-- make sure the overrides override and take into account the packages spec
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
over = {
|
||||
@ -47,6 +47,31 @@ function M.registertree(speclist, overrides)
|
||||
-- keep working plugins from loading because an unrelated one doesn't load.
|
||||
packager:new(spec, overrides)
|
||||
end
|
||||
|
||||
if speclist.modules then
|
||||
for _, module in ipairs(speclist.modules) do
|
||||
local name = "<unnamed module>"
|
||||
|
||||
if type(module) == "string" then
|
||||
if speclist.modules.prefix then
|
||||
if speclist.modules.prefix:sub(#speclist.modules.prefix) ~= "." and
|
||||
module:sub(1, 2) ~= "." then
|
||||
module = "."..module
|
||||
end
|
||||
module = speclist.modules.prefix..module
|
||||
end
|
||||
|
||||
name, module = module, require(module)
|
||||
end
|
||||
|
||||
name = module.name or name
|
||||
|
||||
local ok, err = pcall(M.registertree, module, overrides)
|
||||
if not ok then
|
||||
error(string.format("%s <- %s", err, name))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--- reload all packages in package table spec
|
||||
|
@ -1,5 +1,13 @@
|
||||
local logger = require('dep.log')
|
||||
|
||||
---@class modules
|
||||
---@field prefix string prefix to prepend to the modules
|
||||
---@field [integer] string list of all modules to load
|
||||
|
||||
---@class speclist
|
||||
---@field modules modules a list of modules
|
||||
---@field [integer] spec a spec
|
||||
|
||||
---@class spec
|
||||
---@field [1] string id
|
||||
---@field setup function? code to run before the package is loaded
|
||||
|
Reference in New Issue
Block a user