1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
# dep
> This readme is a work in progress.
A versatile, declarative and correct
[neovim](https://neovim.io/) package manager in [lua](https://www.lua.org/).
Written for personal use by [phosphene47](https://github.com/phosphene47).
What does that mean?
1. `versatile` - packages can be declared in any lua file in any order of your liking.
2. `declarative` - packages are declared using simple lua tables.
3. `correct` - packages are always loaded in a correct and consistent order.
## Requirements
- [neovim](https://neovim.io/) 0.5+
- [git](https://git-scm.com/)
## Setup
1. Create `lua/bootstrap.lua` in your neovim config directory.
```lua
-- ~/.config/nvim/lua/bootstrap.lua:
-- automatically install `chiyadev/dep` on startup
local path = vim.fn.stdpath("data") .. "/site/pack/deps/opt/dep"
if vim.fn.empty(vim.fn.glob(path)) > 0 then
vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/chiyadev/dep", path })
end
vim.cmd("packadd dep")
```
2. In `init.lua`, call `dep` with an array of package specifications.
```lua
require "bootstrap"
require "dep" {
-- list of package specs...
}
```
## Commands
- `:DepSync` - installs new packages, updates packages to the latest versions,
cleans removed packages and reloads packages as necessary.
- `:DepClean` - cleans removed packages.
- `:DepReload` - reloads all packages.
- `:DepList` - prints the package list, performance metrics and dependency graphs.
- `:DepLog` - opens the log file.
- `:DepConfig` - opens the file that called dep, for convenience.
## Package specification
A package must be declared in the following format.
```lua
{
-- [string] Specifies the full name of the package.
-- This is the only required field; all other fields are optional.
"user/package",
-- [function] Code to run after the package is loaded into neovim.
function()
require "package".setup(...)
end,
-- [function] Code to run before the package is loaded into neovim.
setup = function()
vim.g.package_config = ...
end,
-- [function] Code to run after the package is installed or updated.
config = function()
os.execute(...)
end,
-- [string] Overrides the short name of the package.
-- Defaults to a substring of the full name after '/'.
as = "custom_package",
-- [string] Overrides the URL of the git repository to clone.
-- Defaults to "https://github.com/{full_name}.git".
url = "https://git.chiya.dev/user/package.git",
-- [string] Overrides the name of the branch to clone.
-- Defaults to whatever the remote configured as their HEAD, which is usually "master".
branch = "develop",
-- [boolean] Prevents the package from being loaded.
disable = true,
-- [boolean] Prevents the package from being updated.
pin = true,
-- [string|array] Specifies dependencies that must be loaded before the package.
-- If given a string, it is wrapped into an array.
requires = {...},
-- [string|array] Specifies dependents that must be loaded after the package.
-- If given a string, it is wrapped into an array.
deps = {...}
}
```
When a string is given where a package specification table is expected,
it is assumed to be the package's full name.
```lua
require "dep" {
-- these two are equivalent
"user/package",
{ "user/package" },
}
```
A package can be declared multiple times. Multiple declarations of the same package are
combined into one. This is useful when declaring dependencies, which is explored later.
```lua
require "dep" {
{
"user/package",
requires = "user/dependency",
disabled = true,
config = function()
print "my config hook"
end
},
{
"user/package",
requires = "user/another_dependency",
deps = "user/dependent",
disabled = false,
config = function()
os.execute("make")
end
}
}
-- the above is equivalent to
require "dep" {
{
"user/package",
requires = { "user/dependency", "user/another_dependency" },
deps = "user/dependent",
disabled = true,
config = function()
print "my config hook"
os.execute("make")
end
}
}
```
## Declaring dependencies
The dependencies and dependents declared in a package specification are themselves
package specifications. If a dependency or dependent is declared multiple times,
they are combined into one just like normal package specifications.
```lua
require "dep" {
{
"user/package",
requires = {
{
"user/dependency1",
requires = "user/dependency2"
}
}
}
}
-- the above is equivalent to
require "dep" {
{
"user/dependency2",
deps = {
{
"user/dependency1",
deps = "user/package"
}
}
}
}
-- which is equivalent to
require "dep" {
{
"user/dependency1",
requires = "user/dependency2",
deps = "user/package"
}
}
-- which is equivalent to
require "dep" {
{
"user/dependency1",
requires = "user/dependency2"
},
{
"user/package",
requires = "user/dependency1"
}
}
-- which is equivalent to
require "dep" {
{
"user/dependency2",
deps = "user/dependency1"
},
{
"user/dependency1",
deps = "user/package"
}
}
-- all of the above are guaranteed to load in the following order: dependency2, dependency1, package
```
If dep detects a circular dependency cycle, it reports the problematic packages
instead of hanging or crashing.
```lua
-- this throws an error saying package1 depends on package2 which depends on package1
require "dep" {
{
"user/package1",
requires = "user/package2"
},
{
"user/package2",
requires = "user/package1"
}
}
```
A dependency can be marked as disabled, which disables all dependents automatically.
```lua
require "dep" {
{
"user/dependency",
disabled = true
},
{
"user/package1",
disabled = true, -- implied
requires = "user/dependency"
},
{
"user/package2",
disabled = true, -- implied
requires = "user/dependency"
}
}
```
If a dependency fails to load for some reason, all of its dependents are guaranteed to not load.
```lua
require "dep" {
{
"user/problematic",
function()
error("bad hook")
end
},
{
"user/dependent",
requires = "user/problematic",
function()
print "unreachable"
end
}
}
```
## 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](https://github.com/nvim-telescope/telescope.nvim) and
[vim-fugitive](https://github.com/tpope/vim-fugitive) 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.
```lua
require "dep" {
-- [string] Specifies when dep should automatically synchronize.
-- "never": disable this behavior
-- "new": only install newly declared packages (default)
-- "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 = "",
},
-- list of package specs...
}
```
## License
dep is licensed under the [MIT License](LICENSE).
|