Skip to content

Commit

Permalink
fix(cache): added support for top level lua linked directories. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 29, 2022
1 parent 8544c38 commit 853d4d5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lua/lazy/core/cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function M.check_loaded(modname)
end

---@param modname string
---@return any
---@return fun()|string
function M.loader(modname)
modname = modname:gsub("/", ".")
local entry = M.cache[modname]
Expand All @@ -139,7 +139,7 @@ function M.loader(modname)
end
end
end
return chunk or (err and error(err)) or "not found in lazy cache"
return chunk or err or ("module " .. modname .. " not found")
end

---@param modpath string
Expand Down Expand Up @@ -197,8 +197,12 @@ function M.load(modkey, modpath)
end

function M.require(modname)
local chunk = M.loader(modname)
if type(chunk) == "string" then
error(chunk)
end
---@diagnostic disable-next-line: no-unknown
local mod = M.loader(modname)()
local mod = chunk()
---@diagnostic disable-next-line: no-unknown
package.loaded[modname] = mod
return mod
Expand All @@ -216,10 +220,10 @@ function M._index(path)
M.indexed[path] = true
Util.ls(path .. "/lua", function(_, name, t)
local topname
if t == "directory" then
topname = name
elseif name:sub(-4) == ".lua" then
if name:sub(-4) == ".lua" then
topname = name:sub(1, -5)
elseif t == "link" or t == "directory" then
topname = name
end
if topname then
M.topmods[topname] = M.topmods[topname] or {}
Expand Down

0 comments on commit 853d4d5

Please sign in to comment.