Skip to content

Commit 853d4d5

Browse files
committed
fix(cache): added support for top level lua linked directories. Fixes #233
1 parent 8544c38 commit 853d4d5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Diff for: lua/lazy/core/cache.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function M.check_loaded(modname)
114114
end
115115

116116
---@param modname string
117-
---@return any
117+
---@return fun()|string
118118
function M.loader(modname)
119119
modname = modname:gsub("/", ".")
120120
local entry = M.cache[modname]
@@ -139,7 +139,7 @@ function M.loader(modname)
139139
end
140140
end
141141
end
142-
return chunk or (err and error(err)) or "not found in lazy cache"
142+
return chunk or err or ("module " .. modname .. " not found")
143143
end
144144

145145
---@param modpath string
@@ -197,8 +197,12 @@ function M.load(modkey, modpath)
197197
end
198198

199199
function M.require(modname)
200+
local chunk = M.loader(modname)
201+
if type(chunk) == "string" then
202+
error(chunk)
203+
end
200204
---@diagnostic disable-next-line: no-unknown
201-
local mod = M.loader(modname)()
205+
local mod = chunk()
202206
---@diagnostic disable-next-line: no-unknown
203207
package.loaded[modname] = mod
204208
return mod
@@ -216,10 +220,10 @@ function M._index(path)
216220
M.indexed[path] = true
217221
Util.ls(path .. "/lua", function(_, name, t)
218222
local topname
219-
if t == "directory" then
220-
topname = name
221-
elseif name:sub(-4) == ".lua" then
223+
if name:sub(-4) == ".lua" then
222224
topname = name:sub(1, -5)
225+
elseif t == "link" or t == "directory" then
226+
topname = name
223227
end
224228
if topname then
225229
M.topmods[topname] = M.topmods[topname] or {}

0 commit comments

Comments
 (0)