the spec no longer fixes itself...
modules are more reliable cleanup some typos
This commit is contained in:
25
lua/dep.lua
25
lua/dep.lua
@ -3,6 +3,7 @@ local git = require('dep.git')
|
||||
local fs = require('dep.fs')
|
||||
local packager = require('dep.package')
|
||||
local h = require('dep.helpers')
|
||||
local spec_man = require("dep.spec")
|
||||
|
||||
-- all functions for convenience
|
||||
local M = {}
|
||||
@ -38,14 +39,14 @@ function M.registertree(speclist, overrides)
|
||||
-- make sure the overrides override and take into account the packages spec
|
||||
---@diagnostic disable-next-line: missing-fields
|
||||
over = {
|
||||
pin = over.pin or spec.pin,
|
||||
disable = over.disable or spec.disable
|
||||
pin = overrides.pin or spec.pin,
|
||||
disable = overrides.disable or spec.disable
|
||||
}
|
||||
|
||||
-- While a package can fail to load we just don't care, it will work itself
|
||||
-- out. The goal is to make sure every plugin that can load does load, not
|
||||
-- keep working plugins from loading because an unrelated one doesn't load.
|
||||
packager:new(spec, overrides)
|
||||
packager:new(spec, over)
|
||||
end
|
||||
|
||||
if speclist.modules then
|
||||
@ -63,9 +64,14 @@ function M.registertree(speclist, overrides)
|
||||
|
||||
name, module = module, require(module)
|
||||
end
|
||||
|
||||
name = module.name or name
|
||||
|
||||
-- allow a module to be a spec
|
||||
if spec_man.check(module, true) ~= false then
|
||||
---@diagnostic disable-next-line: cast-local-type
|
||||
module = { module }
|
||||
end
|
||||
|
||||
local ok, err = pcall(M.registertree, module, overrides)
|
||||
if not ok then
|
||||
error(string.format("%s <- %s", err, name))
|
||||
@ -125,7 +131,7 @@ function M.synctree(tree, cb)
|
||||
end
|
||||
end
|
||||
|
||||
for _, package in ipairs(tree) do
|
||||
for _, package in pairs(tree) do
|
||||
local co = coroutine.create(function()
|
||||
-- if the package provided prefers a local source then use the local
|
||||
-- source instead of the git repository
|
||||
@ -160,7 +166,8 @@ return function(opts)
|
||||
-- register all packages
|
||||
local root = packager:new({
|
||||
"squibid/dep",
|
||||
url = "https://git.squi.bid/dep",
|
||||
url = "https://git.squi.bid/squibid/dep.git",
|
||||
branch = "lazy",
|
||||
pin = true
|
||||
})
|
||||
if not root then
|
||||
@ -170,7 +177,7 @@ return function(opts)
|
||||
M.registertree(opts)
|
||||
|
||||
-- sort package dependencies
|
||||
for _, package in ipairs(packager.get_packages()) do
|
||||
for _, package in pairs(packager.get_packages()) do
|
||||
table.sort(package.requirements, comp)
|
||||
table.sort(package.dependents, comp)
|
||||
end
|
||||
@ -183,7 +190,7 @@ return function(opts)
|
||||
end)
|
||||
|
||||
-- load packages
|
||||
M.reload()
|
||||
M.reload(false)
|
||||
|
||||
--- check if a package should be synced
|
||||
---@param package table package table spec
|
||||
@ -198,7 +205,7 @@ return function(opts)
|
||||
|
||||
-- get all package that need syncing
|
||||
local targets = {}
|
||||
for _, package in ipairs(packager.get_packages()) do
|
||||
for _, package in pairs(packager.get_packages()) do
|
||||
if shouldsync(package) then
|
||||
table.insert(targets, package)
|
||||
end
|
||||
|
@ -46,7 +46,6 @@ end
|
||||
---@param package package package to install
|
||||
---@param cb function callback
|
||||
function git.install(package, cb)
|
||||
|
||||
if not package.enabled then
|
||||
cb()
|
||||
return
|
||||
@ -99,13 +98,9 @@ function git.update(package, cb)
|
||||
return
|
||||
end
|
||||
|
||||
local function logerr(err)
|
||||
logger:log("error", "failed to update %s; reason: %s", package.id, err)
|
||||
end
|
||||
|
||||
proc.git_rev_parse(package.dir, "HEAD", function(err, before)
|
||||
if err then
|
||||
logerr(before)
|
||||
log_err(before)
|
||||
cb(err)
|
||||
else
|
||||
if package.commit then
|
||||
|
@ -65,7 +65,7 @@ function package:new(spec, overrides)
|
||||
overrides = overrides or {}
|
||||
|
||||
-- ensure that the spec is ok
|
||||
local new_spec = spec_man.check(spec)
|
||||
local new_spec = spec_man.check(spec_man.correct_spec(spec))
|
||||
if new_spec == false then
|
||||
logger:log("spec", vim.inspect(spec))
|
||||
logger:log("error", "spec check failed, check DepLog")
|
||||
@ -144,7 +144,7 @@ function package:new(spec, overrides)
|
||||
if spec.reqs then
|
||||
---it is the correct type as asserted in check_spec()
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
for _, req in ipairs(spec.reqs) do
|
||||
for _, req in pairs(spec.reqs) do
|
||||
local pkg = package:new(req)
|
||||
if type(pkg) == "table" then
|
||||
o:link_dependency(pkg, o)
|
||||
@ -156,7 +156,7 @@ function package:new(spec, overrides)
|
||||
if spec.deps then
|
||||
---it is the correct type as asserted in check_spec()
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
for _, dep in ipairs(spec.deps) do
|
||||
for _, dep in pairs(spec.deps) do
|
||||
local pkg = package:new(dep)
|
||||
if not pkg then
|
||||
return false
|
||||
@ -206,7 +206,7 @@ function package.get_root()
|
||||
end
|
||||
|
||||
--- get the packages in dep
|
||||
---@return package root
|
||||
---@return package[] packages
|
||||
---@nodiscard
|
||||
function package.get_packages()
|
||||
return packages
|
||||
@ -254,7 +254,7 @@ function package:ensureadded(force)
|
||||
---@param pkg package
|
||||
local function loadpkg(pkg)
|
||||
-- make sure to load the dependencies first
|
||||
for _, p in ipairs(pkg.requirements) do
|
||||
for _, p in pairs(pkg.requirements) do
|
||||
if not p.loaded then
|
||||
p:ensureadded(true)
|
||||
end
|
||||
@ -335,7 +335,7 @@ function package:loadtree(force)
|
||||
|
||||
-- if the package isn't lazy check that it's requirements are loaded
|
||||
if not self.lazy then
|
||||
for _, requirement in ipairs(self.requirements) do
|
||||
for _, requirement in pairs(self.requirements) do
|
||||
if not requirement.loaded and not requirement.lazy then
|
||||
return false
|
||||
end
|
||||
@ -355,7 +355,7 @@ function package:loadtree(force)
|
||||
self.subtree_loaded = true
|
||||
|
||||
-- make sure the dependants are loaded
|
||||
for _, dependant in ipairs(self.dependents) do
|
||||
for _, dependant in pairs(self.dependents) do
|
||||
self.subtree_loaded = dependant:loadtree(force) and self.subtree_loaded
|
||||
end
|
||||
|
||||
@ -365,12 +365,12 @@ end
|
||||
--- unconfigure a packages tree
|
||||
function package:unconfiguretree()
|
||||
-- unconfigure requirements
|
||||
for _, requirement in ipairs(self.requirements) do
|
||||
for _, requirement in pairs(self.requirements) do
|
||||
requirement.subtree_loaded = false
|
||||
end
|
||||
|
||||
-- unconfigure dependents
|
||||
for _, dependant in ipairs(self.dependents) do
|
||||
for _, dependant in pairs(self.dependents) do
|
||||
dependant.loaded = false
|
||||
dependant.added = false
|
||||
dependant.configured = false
|
||||
@ -431,7 +431,7 @@ function package.findcycle(pkgs)
|
||||
end
|
||||
|
||||
-- actually check the cycle
|
||||
for _, pkg in ipairs(pkgs) do
|
||||
for _, pkg in pairs(pkgs) do
|
||||
if not indexes[package.id] then
|
||||
local cycle = connect(pkg)
|
||||
if cycle then
|
||||
|
@ -122,7 +122,8 @@ function proc.git_resolve_branch(url, branch, cb)
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
return proc
|
||||
|
@ -43,13 +43,35 @@ function spec:get_name()
|
||||
return self[1]:match("^[%w-_.]+/([%w-_.]+)$")
|
||||
end
|
||||
|
||||
--- check a spec to see if it's correct
|
||||
--- attempt to correct a spec
|
||||
---@param self table|string spec to check
|
||||
---@return spec|false spec if the spec is ok or false
|
||||
function spec:check()
|
||||
-- make sure spec is a table
|
||||
---@return spec spec
|
||||
function spec:correct_spec()
|
||||
if type(self) == "string" then
|
||||
self = { self }
|
||||
return { self }
|
||||
elseif type(self) == "table" then
|
||||
repeat
|
||||
if type(self[1]) ~= "string" then
|
||||
self = self[1]
|
||||
end
|
||||
until type(self[1]) == "string"
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
-- store the logger temporarily to prevent any logs from being printed when
|
||||
-- being run in silent mode
|
||||
local __logger
|
||||
|
||||
--- check a spec to see if it's correct
|
||||
---@param self table spec to check
|
||||
---@param silent boolean? should the checker report errors
|
||||
---@return spec|false spec if the spec is ok or false
|
||||
function spec:check(silent)
|
||||
if silent == true then
|
||||
__logger = logger
|
||||
logger = { log = function() end }
|
||||
end
|
||||
|
||||
-- make sure all the data is correct
|
||||
@ -176,6 +198,9 @@ function spec:check()
|
||||
end
|
||||
end
|
||||
|
||||
if silent == true then
|
||||
logger = __logger
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user