Skip to content

Commit 1fa2cb6

Browse files
committed
refactor: move pack_spec creation from import to merge phase
- Remove pack_spec creation from import.lua (just registers specs now) - Create pack_specs in merge.resolve_all() with correct merged data - Return sorted vim_packs array from resolve_all() - Fix KeySpec type annotation in utils.lua
1 parent b0e80e8 commit 1fa2cb6

File tree

6 files changed

+55
-38
lines changed

6 files changed

+55
-38
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ A thin layer on top of Neovim's native `vim.pack`, adding support for lazy-loadi
1010
```lua
1111
-- ./lua/plugins/fundo.lua
1212
return {
13-
{
14-
'kevinhwang91/nvim-fundo',
15-
dependencies = { "kevinhwang91/promise-async" },
16-
cond = not vim.g.vscode,
17-
version = 'main',
18-
build = function() require('fundo').install() end,
19-
opts = {},
20-
config = function(_, opts)
21-
vim.o.undofile = true
22-
require('fundo').setup(opts)
23-
end,
24-
},
13+
'kevinhwang91/nvim-fundo',
14+
dependencies = { "kevinhwang91/promise-async" },
15+
cond = not vim.g.vscode,
16+
version = 'main',
17+
build = function() require('fundo').install() end,
18+
opts = {},
19+
config = function(_, opts)
20+
vim.o.undofile = true
21+
require('fundo').setup(opts)
22+
end,
2523
}
2624
```
2725

@@ -46,23 +44,23 @@ vim.pack.add({ 'https://github.com/zuqini/zpack.nvim' })
4644
vim.g.mapleader = " "
4745
vim.g.maplocalleader = "\\"
4846

49-
-- automatically import specs from `/lua/plugins/`
47+
-- automatically import specs from `./lua/plugins/`
5048
require('zpack').setup()
5149

52-
-- or import from a custom directory e.g. `/lua/a/b/plugins/`
50+
-- or import from a custom directory e.g. `./lua/a/b/plugins/`
5351
require('zpack').setup({ { import = 'a.b.plugins' } })
5452

5553
-- or add your specs inline in setup
5654
require('zpack').setup({
5755
{ 'neovim/nvim-lspconfig', config = function() ... end },
58-
{ import = 'plugins.mini' }, -- additionally import from `/lua/plugins/mini/`
56+
{ import = 'plugins.mini' }, -- additionally import from `./lua/plugins/mini/`
5957
})
6058

6159
-- or via the spec field
6260
require('zpack').setup({
6361
spec = {
6462
{ 'neovim/nvim-lspconfig', config = function() ... end },
65-
{ import = 'plugins.mini' }, -- additionally import from `/lua/plugins/mini/`
63+
{ import = 'plugins.mini' },
6664
},
6765
})
6866
```
@@ -127,15 +125,15 @@ Plugin-level settings always take precedence over `defaults`.
127125
Neovim 0.12+ includes a built-in package manager (`vim.pack`) that handles plugin installation, updates, and version management. zpack is a thin layer that adds lazy-loading capabilities and support for a lazy.nvim-like declarative spec while completely leveraging the native infrastructure.
128126

129127
#### Features
130-
- z***pack*** is completely native
131-
- Install and manage your plugins _(including zpack)_ all within `vim.pack`.
132-
- ⚡pack is "batteries included":
133-
- Add plugins using the same lazy.nvim spec provided by plugin authors you know and love, with minimal configuration
134-
- 💤pack powers up `vim.pack` without the bells and whistles
128+
- [z***pack***] is completely native
129+
- Install and manage your plugins _(including zpack)_ all within `vim.pack`
130+
- [🔋pack] is "batteries included"
131+
- Add plugins using the same lazy.nvim spec provided by plugin authors you know and love
132+
- Minimal configurations necessary
133+
- [💤pack] powers up `vim.pack` without the bells and whistles
134+
- Powerful lazy-loading triggers
135135
- Build triggers for installation/updates
136136
- Basic plugin management commands
137-
- Powerful lazy-loading triggers
138-
139137

140138
zpack might be for you if:
141139
- you're a lazy.nvim user, love its declarative spec, and its wide adoption by plugin authors, but you don't need most of its advanced features
@@ -347,6 +345,7 @@ return {
347345
{ 'nvim-lua/plenary.nvim' },
348346
{ 'nvim-tree/nvim-web-devicons' },
349347
{ 'nvim-lualine/lualine.nvim', opts = { theme = 'auto' } },
348+
{ import = 'plugins.mini' },
350349
}
351350
```
352351

doc/zpack.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ Install zpack.nvim via vim.pack.add():
5151
vim.g.mapleader = " "
5252
vim.g.maplocalleader = "\\"
5353

54-
-- automatically import specs from `/lua/plugins/`
54+
-- automatically import specs from `./lua/plugins/`
5555
require('zpack').setup()
5656

57-
-- or import from a custom directory e.g. `/lua/a/b/plugins/`
57+
-- or import from a custom directory e.g. `./lua/a/b/plugins/`
5858
require('zpack').setup({ { import = 'a.b.plugins' } })
5959

6060
-- or add your specs inline in setup
6161
require('zpack').setup({
6262
{ 'neovim/nvim-lspconfig', config = function() ... end },
63-
{ import = 'plugins.mini' }, -- additionally import from `/lua/plugins/mini/`
63+
{ import = 'plugins.mini' }, -- additionally import from `./lua/plugins/mini/`
6464
})
6565

6666
-- or via the spec field
@@ -216,7 +216,19 @@ performance (table, optional)
216216
Neovim 0.12+ includes a built-in package manager (`vim.pack`) that handles
217217
plugin installation, updates, and version management. zpack is a thin layer
218218
that adds lazy-loading capabilities and support for a lazy.nvim-like
219-
declarative spec while leveraging the native infrastructure.
219+
declarative spec while completely leveraging the native infrastructure.
220+
221+
Features:
222+
- completely native
223+
- Install and manage your plugins (including zpack) all within `vim.pack`
224+
- batteries included
225+
- Add plugins using the same lazy.nvim spec provided by plugin authors
226+
you know and love
227+
- Minimal configurations necessary
228+
- powers up `vim.pack` without the bells and whistles
229+
- Powerful lazy-loading triggers
230+
- Build triggers for installation/updates
231+
- Basic plugin management commands
220232

221233
zpack might be for you if:
222234
- you're a lazy.nvim user, love its declarative spec, and its wide adoption
@@ -449,6 +461,7 @@ Define multiple plugins in a single file:
449461
{ 'nvim-lua/plenary.nvim' },
450462
{ 'nvim-tree/nvim-web-devicons' },
451463
{ 'nvim-lualine/lualine.nvim', opts = { theme = 'auto' } },
464+
{ import = 'plugins.mini' },
452465
}
453466
<
454467

lua/zpack/import.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@ M.import_specs = function(spec_item_or_list, ctx)
169169
table.insert(state.spec_registry[src].specs, spec)
170170
else
171171
state.spec_registry[src] = { specs = { spec }, load_status = "pending" }
172-
local pack_spec = { src = src, version = utils.normalize_version(spec), name = spec.name }
173-
table.insert(ctx.vim_packs, pack_spec)
174-
state.src_to_pack_spec[src] = pack_spec
175172
end
176173

177174
if spec.dependencies then

lua/zpack/init.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ local M = {}
1616
local function create_context(opts)
1717
opts = opts or {}
1818
return {
19-
vim_packs = {},
2019
src_with_init = {},
2120
registered_startup_packs = {},
2221
registered_lazy_packs = {},
@@ -70,7 +69,7 @@ local process_all = function(ctx)
7069
local state = require('zpack.state')
7170

7271
vim.api.nvim_clear_autocmds({ group = state.lazy_build_group })
73-
require('zpack.merge').resolve_all()
72+
ctx.vim_packs = require('zpack.merge').resolve_all()
7473
hooks.setup_build_tracking()
7574
require('zpack.registration').register_all(ctx)
7675

lua/zpack/merge.lua

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,31 @@ function M.resolve_opts(specs, plugin)
231231
end
232232

233233
---Pre-compute merged_spec for all entries in the registry
234-
---Also updates pack_spec.version based on merged specs
234+
---Creates pack_specs with merged data and returns sorted vim_packs array
235+
---@return vim.pack.Spec[]
235236
function M.resolve_all()
236237
local state = require('zpack.state')
237238
local utils = require('zpack.utils')
238239

240+
local vim_packs = {}
241+
239242
for src, entry in pairs(state.spec_registry) do
240243
if entry.specs and #entry.specs > 0 then
241244
entry.sorted_specs = M.sort_specs(entry.specs)
242245
entry.merged_spec = M.merge_spec_array(entry.sorted_specs)
243246

244-
local pack_spec = state.src_to_pack_spec[src]
245-
if pack_spec then
246-
pack_spec.version = utils.normalize_version(entry.merged_spec)
247-
end
247+
local pack_spec = {
248+
src = src,
249+
version = utils.normalize_version(entry.merged_spec),
250+
name = entry.merged_spec.name,
251+
}
252+
table.insert(vim_packs, pack_spec)
253+
state.src_to_pack_spec[src] = pack_spec
248254
end
249255
end
256+
257+
table.sort(vim_packs, utils.compare_priority)
258+
return vim_packs
250259
end
251260

252261
return M

lua/zpack/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ M.normalize_keys = function(keys)
9595
-- Normalize to always be an array
9696
local key_list = (type(keys) == "string" or (keys[1] and type(keys[1]) == "string"))
9797
and { keys }
98-
or keys --[[@as string[]|KeySpec[] ]]
98+
or keys --[[@as string[]|zpack.KeySpec[] ]]
9999

100100
local result = {}
101101
for _, key in ipairs(key_list) do

0 commit comments

Comments
 (0)