dep can now search for modules as long as it's provided with a prefix
This commit is contained in:
@ -59,6 +59,7 @@ end
|
|||||||
-- basically the main function of our program
|
-- basically the main function of our program
|
||||||
---@param opts speclist
|
---@param opts speclist
|
||||||
return function(opts)
|
return function(opts)
|
||||||
|
M.config_path = debug.getinfo(2, "S").source:sub(2)
|
||||||
logger.pipe = logger:setup()
|
logger.pipe = logger:setup()
|
||||||
bench:setup()
|
bench:setup()
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ return function(opts)
|
|||||||
|
|
||||||
-- setup all packages and modules
|
-- setup all packages and modules
|
||||||
if opts.modules then
|
if opts.modules then
|
||||||
modules:setup(opts)
|
modules:setup(opts, nil, M.config_path)
|
||||||
end
|
end
|
||||||
packager.register_speclist(opts)
|
packager.register_speclist(opts)
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
local h = require('dep.helpers')
|
||||||
|
local logger = require('dep.log')
|
||||||
local module = require("dep.modules.module")
|
local module = require("dep.modules.module")
|
||||||
|
|
||||||
---@class modules
|
---@class modules
|
||||||
@ -10,7 +12,7 @@ local modules = {}
|
|||||||
---@param overrides spec? overrides
|
---@param overrides spec? overrides
|
||||||
---@return modules modules manager
|
---@return modules modules manager
|
||||||
---@nodisacard
|
---@nodisacard
|
||||||
function modules:setup(speclist, overrides)
|
function modules:setup(speclist, overrides, config_path)
|
||||||
overrides = overrides or {}
|
overrides = overrides or {}
|
||||||
|
|
||||||
local o = {}
|
local o = {}
|
||||||
@ -21,6 +23,49 @@ function modules:setup(speclist, overrides)
|
|||||||
-- create a list of modules
|
-- create a list of modules
|
||||||
o.modules = {}
|
o.modules = {}
|
||||||
|
|
||||||
|
if (speclist.modules[1] == "*" or #speclist.modules == 0)
|
||||||
|
and speclist.modules.prefix then
|
||||||
|
|
||||||
|
local path = vim.fs.joinpath(config_path:gsub("[^/]*$", ""),
|
||||||
|
"lua", (speclist.modules.prefix:gsub("%.", "/"))
|
||||||
|
)
|
||||||
|
|
||||||
|
h.uv.fs_scandir(path, function(err, handle)
|
||||||
|
if err then
|
||||||
|
logger:log("error", "failed to load modules; reason: %s", err)
|
||||||
|
else
|
||||||
|
while handle do
|
||||||
|
local name = h.uv.fs_scandir_next(handle)
|
||||||
|
if name then
|
||||||
|
-- skip non-lua files
|
||||||
|
if name:sub(#name - 3) ~= ".lua" then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove the file extension from the name so that lua doesn't fail
|
||||||
|
-- when attempting to load it
|
||||||
|
name = name:sub(0, #name - 4)
|
||||||
|
|
||||||
|
-- attempt to load the module
|
||||||
|
local mod = module.new(nil, name, speclist.modules.prefix, overrides)
|
||||||
|
if not mod then
|
||||||
|
goto continue
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(o.modules, mod)
|
||||||
|
::continue::
|
||||||
|
elseif name == nil then
|
||||||
|
-- no more entries
|
||||||
|
break
|
||||||
|
else
|
||||||
|
-- if there's a single error bail out
|
||||||
|
logger:log("error", "failed to run clean uv.fs_scandir_next failed")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
-- loop through all modules and initialize them
|
-- loop through all modules and initialize them
|
||||||
for _, modpath in ipairs(speclist.modules) do
|
for _, modpath in ipairs(speclist.modules) do
|
||||||
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
|
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
|
||||||
@ -31,6 +76,7 @@ function modules:setup(speclist, overrides)
|
|||||||
table.insert(o.modules, mod)
|
table.insert(o.modules, mod)
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user