diff --git a/lua/one/plugin-manager/init.lua b/lua/one/plugin-manager/init.lua index bb766f1..1e1f76d 100644 --- a/lua/one/plugin-manager/init.lua +++ b/lua/one/plugin-manager/init.lua @@ -171,6 +171,8 @@ local function setupUserPlugins(optPlugins) end for i, p in pairs(optPlugins or {}) do + if not p then goto continue end + local ok, plugOpts = xpcall(normalizeOpts, debug.traceback, p) if not ok then notify(string.format('Invalid user plugin at opts.plugins[%s]. Reason: %s', i, plugOpts), 'error') @@ -178,6 +180,8 @@ local function setupUserPlugins(optPlugins) userPlugins[plugOpts.id] = plugOpts userPluginList[#userPluginList + 1] = plugOpts -- For keeping plugins order + + ::continue:: end return userPluginList diff --git a/lua/one/plugin-manager/use-plug.lua b/lua/one/plugin-manager/use-plug.lua index 4dab84a..d50ebd1 100644 --- a/lua/one/plugin-manager/use-plug.lua +++ b/lua/one/plugin-manager/use-plug.lua @@ -43,22 +43,34 @@ local function usePlug(pm, loadPlug, repo, opts) -- Must load dependent plugins first, then load current plugin. -- If current plugin is disabled, no need to load dependent plugins. if not opts.disable then - for index, dep in pairs(opts.requires or {}) do + local requires = {} + for _, dep in pairs(opts.requires or {}) do + if not dep then goto continue end + local depPlug = usePlug(pm, loadPlug, dep) - opts.requires[index] = depPlug + requires[#requires + 1] = depPlug if depPlug.disable then opts.disable = true opts.reason = string.format('Its required plugin "%s" is disabled', depPlug.id) end + + ::continue:: end + opts.requires = requires end if not opts.disable then - for index, dep in pairs(opts.deps or {}) do + local deps = {} + for _, dep in pairs(opts.deps or {}) do + if not dep then goto continue end + local depPlug = usePlug(pm, loadPlug, dep) - opts.deps[index] = depPlug + deps[#deps + 1] = depPlug + + ::continue:: end + opts.deps = deps end plugMap[id] = opts diff --git a/lua/one/plugin-manager/use-plug_spec.lua b/lua/one/plugin-manager/use-plug_spec.lua index 6effb05..a81bf91 100644 --- a/lua/one/plugin-manager/use-plug_spec.lua +++ b/lua/one/plugin-manager/use-plug_spec.lua @@ -34,15 +34,34 @@ describe('usePlug()', function() assert.are.same('g/g2', plugs[8].repo) assert.are.same('g/g', plugs[9].repo) - assert.are.same({ id = 'g/h1', repo = 'g/h1' }, plugs[10]) + assert.are.same({ _normalized = true, id = 'g/h1', repo = 'g/h1' }, plugs[10]) - assert.are.same({ id = 'g/h2', repo = 'g/h2', disable = true }, plugs[11]) + assert.are.same({ _normalized = true, id = 'g/h2', repo = 'g/h2', disable = true }, plugs[11]) assert.are.same({ + _normalized = true, id = 'g/h', repo = 'g/h', requires = { { id = 'g/h1', repo = 'g/h1' }, { id = 'g/h2', repo = 'g/h2', disable = true } }, }, plugs[12]) end) + + it('requires and deps contain false', function() + local P = { count = 0, plugs = {}, plugMap = {}, userPlugins = {} } + + usePlug(P, loadPlug, { + 'p', + deps = { false, { 'd1' }, false, 'd2' }, + requires = { false, { 'r1' }, false, { 'r2' } }, + }) + + assert.are.same({ + _normalized = true, + id = 'p', + deps = { { id = 'd1' }, { id = 'd2' } }, + requires = { { id = 'r1' }, { id = 'r2' } }, + }, P.plugs[1]) + + end) end)