pin the correct repo to the top of the plugin list

This commit is contained in:
2023-04-30 19:49:01 -04:00
parent 5b7b7f610f
commit 3d20ae8d2a
4 changed files with 12 additions and 136 deletions

View File

@ -1,6 +1,7 @@
MIT License
Copyright (c) 2021 chiya.dev
(c) 2021 chiya.dev
(c) 2024 squibid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

103
README.md
View File

@ -287,97 +287,6 @@ require "dep" {
}
```
## Separating code into modules
Suppose you split your `init.lua` into two files `packages/search.lua` and
`packages/vcs.lua`, which declare the packages [telescope.nvim][6] and [vim-fugitive][7] respectively.
```lua
-- ~/.config/nvim/lua/packages/search.lua:
return {
{
"nvim-telescope/telescope.nvim",
requires = "nvim-lua/plenary.nvim"
}
}
```
```lua
-- ~/.config/nvim/lua/packages/vcs.lua:
return {
"tpope/vim-fugitive"
}
```
Package specifications from other modules can be loaded using the `modules` option.
```lua
require "dep" {
modules = {
prefix = "packages.",
"search",
"vcs"
}
}
-- the above is equivalent to
require "dep" {
modules = {
"packages.search",
"packages.vcs"
}
}
-- which is equivalent to
local packages = {}
for _, package in ipairs(require "packages.search") do
table.insert(packages, package)
end
for _, package in ipairs(require "packages.vcs") do
table.insert(packages, package)
end
require("dep")(packages)
-- which is ultimately equivalent to
require "dep" {
{
"nvim-telescope/telescope.nvim",
requires = "nvim-lua/plenary.nvim"
},
"tpope/vim-fugitive"
}
-- all of the above are guaranteed to load plenary.nvim before telescope.nvim.
-- order of telescope.nvim and vim-fugitive is consistent but unspecified.
```
Entire modules can be marked as disabled, which disables all top-level packages declared in that module.
```lua
return {
disable = true,
{
"user/package",
disabled = true, -- implied by module
requires = {
{
"user/dependency",
-- disabled = true -- not implied
}
},
deps = {
{
"user/dependent",
disabled = true -- implied by dependency
}
}
}
}
```
## Miscellaneous configuration
dep accepts configuration parameters as named fields in the package list.
@ -390,14 +299,10 @@ require "dep" {
-- "always": synchronize all packages on startup
sync = "new",
-- [array] Specifies the modules to load package specifications from.
-- Defaults to an empty table.
-- Items can be either an array of package specifications,
-- or a string that indicates the name of the module from which the array of package specifications is loaded.
modules = {
-- [string] Prefix string to prepend to all module names.
prefix = "",
},
-- [function] Callback when dep is (re)loaded
-- if a table is returned it will be read as a table of config specs
load = function()
end
-- list of package specs...
}

View File

@ -127,27 +127,6 @@ local function register_recursive(list, overrides)
error(string.format("%s (spec=%s)", err, vim.inspect(list[i])))
end
end
if list.modules then
for i = 1, #list.modules do
local name, module = "<unnamed module>", list.modules[i]
if type(module) == "string" then
if list.modules.prefix then
module = list.modules.prefix .. module
end
name, module = module, require(module)
end
name = module.name or name
local ok, err = pcall(register_recursive, module, overrides)
if not ok then
error(string.format("%s <- %s", err, name))
end
end
end
end
local function sort_dependencies()
@ -851,6 +830,12 @@ return setmetatable({
bench("load", function()
root = register("squibid/dep")
register_recursive(config)
if config["load"] and type(config["load"]) == "function" then
local ok, ret = pcall(config["load"]())
if ok and type(ret) == "table" then
register_recursive(ok)
end
end
sort_dependencies()
ensure_acyclic()
end)

View File

@ -168,7 +168,6 @@ local PackageStore = setmetatable({
assert(type(specs) == "table", "package list must be a table")
assert(specs.pin == nil or type(specs.pin) == "boolean", "package list pin must be a boolean")
assert(specs.disable == nil or type(specs.disable) == "boolean", "package list disable must be a boolean")
assert(specs.modules == nil or type(specs.modules) == "table", "package list module list must be a table")
scope = scope or {}
scope = {
@ -181,20 +180,6 @@ local PackageStore = setmetatable({
for i = 1, #specs do
self:add_spec(specs[i], scope)
end
-- recursively add referenced spec list modules
if specs.modules then
local prefix = specs.modules.prefix or ""
for i = 1, #specs.modules do
local name = specs.modules[i]
assert(type(name) == "string", "package list inner module name must be a string")
name = prefix .. name
local module = require(name)
assert(type(module) == "table", "package list inner module did not return a spec list table")
self:add_specs(module, scope)
end
end
end,
--- Ensures there are no circular dependencies in this package store.