Skip to content

Commit 5d9d354

Browse files
committed
feat(util): utility method to walk over all modules in a directory
1 parent 26a67e3 commit 5d9d354

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lua/lazy/core/util.lua

+16
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ function M.walk(path, fn)
201201
end)
202202
end
203203

204+
---@param root string
205+
---@param fn fun(modname:string, modpath:string)
206+
---@param modname? string
207+
function M.walkmods(root, fn, modname)
208+
modname = modname and (modname:gsub("%.$", "") .. ".") or ""
209+
M.ls(root, function(path, name, type)
210+
if name == "init.lua" then
211+
fn(modname:gsub("%.$", ""), path)
212+
elseif (type == "file" or type == "link") and name:sub(-4) == ".lua" then
213+
fn(modname .. name:sub(1, -5), path)
214+
elseif type == "directory" then
215+
M.walkmods(path, fn, modname .. name .. ".")
216+
end
217+
end)
218+
end
219+
204220
---@param modname string
205221
---@param fn fun(modname:string, modpath:string)
206222
function M.lsmod(modname, fn)

0 commit comments

Comments
 (0)