fix(loader): add auto loaded module to package.loaded early to prevent require loops

This commit is contained in:
Folke Lemaitre 2024-07-21 12:41:54 +02:00
parent 9a374a0fb4
commit 18d1c1b47e
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 7 additions and 6 deletions

View File

@ -552,15 +552,16 @@ function M.loader(modname)
end end
if ret then if ret then
M.auto_load(modname, ret.modpath)
local mod = package.loaded[modname] local mod = package.loaded[modname]
if type(mod) == "table" then if type(mod) ~= "table" then
return function() mod = loadfile(ret.modpath, nil, nil, ret.stat)()
return mod
end
end end
package.loaded[modname] = mod
M.auto_load(modname, ret.modpath)
-- selene: allow(incorrect_standard_library_use) -- selene: allow(incorrect_standard_library_use)
return loadfile(ret.modpath, nil, nil, ret.stat) return function()
return mod
end
end end
end end