diff --git a/lua/lazyvim/util/plugin.lua b/lua/lazyvim/util/plugin.lua index 19e3d43c..a78a549f 100644 --- a/lua/lazyvim/util/plugin.lua +++ b/lua/lazyvim/util/plugin.lua @@ -111,15 +111,40 @@ function M.fix_imports() ) spec.import = rename end - local dep = M.deprecated_extras[spec and spec.import] + local dep = M.deprecated_extras[spec.import] if dep then dep = dep .. "\n" .. "Please remove the extra from `lazyvim.json` to hide this warning." LazyVim.warn(dep, { title = "LazyVim", once = true, stacktrace = true, stacklevel = 6 }) return false end + + local modname = spec.import + if type(modname) == "string" and vim.startswith(modname, "lazyvim.plugins.extras.") then + M.single_import(spec) + end end) end +---@param spec LazySpecImport +function M.single_import(spec) + local modname = spec.import + if type(modname) ~= "string" then + return + end + spec.name = modname + spec.import = function() + package.loaded[modname] = nil + local ok, mod, foo = pcall(require, modname) ---@type boolean, table?, unknown + if ok and type(mod) == "table" then + if foo then + return nil, "Spec module returned more than one value. Expected a single value." + end + return mod + end + return nil, mod + end +end + function M.fix_renames() ---@param plugin LazyPluginSpec Meta.add = LazyVim.inject.args(Meta.add, function(self, plugin)