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
|
||||
---@param opts speclist
|
||||
return function(opts)
|
||||
M.config_path = debug.getinfo(2, "S").source:sub(2)
|
||||
logger.pipe = logger:setup()
|
||||
bench:setup()
|
||||
|
||||
@ -90,7 +91,7 @@ return function(opts)
|
||||
|
||||
-- setup all packages and modules
|
||||
if opts.modules then
|
||||
modules:setup(opts)
|
||||
modules:setup(opts, nil, M.config_path)
|
||||
end
|
||||
packager.register_speclist(opts)
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
local h = require('dep.helpers')
|
||||
local logger = require('dep.log')
|
||||
local module = require("dep.modules.module")
|
||||
|
||||
---@class modules
|
||||
@ -10,7 +12,7 @@ local modules = {}
|
||||
---@param overrides spec? overrides
|
||||
---@return modules modules manager
|
||||
---@nodisacard
|
||||
function modules:setup(speclist, overrides)
|
||||
function modules:setup(speclist, overrides, config_path)
|
||||
overrides = overrides or {}
|
||||
|
||||
local o = {}
|
||||
@ -21,15 +23,59 @@ function modules:setup(speclist, overrides)
|
||||
-- create a list of modules
|
||||
o.modules = {}
|
||||
|
||||
-- loop through all modules and initialize them
|
||||
for _, modpath in ipairs(speclist.modules) do
|
||||
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
|
||||
if not mod then
|
||||
goto continue
|
||||
end
|
||||
if (speclist.modules[1] == "*" or #speclist.modules == 0)
|
||||
and speclist.modules.prefix then
|
||||
|
||||
table.insert(o.modules, mod)
|
||||
::continue::
|
||||
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
|
||||
for _, modpath in ipairs(speclist.modules) do
|
||||
local mod = module.new(nil, modpath, speclist.modules.prefix, overrides)
|
||||
if not mod then
|
||||
goto continue
|
||||
end
|
||||
|
||||
table.insert(o.modules, mod)
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
return self
|
||||
|
Reference in New Issue
Block a user