feat(pack): 'packlockfile' option #40562

Problem: No way to configure the lockfile location.

Solution: Add 'packlockfile' option.
This commit is contained in:
Evgeni Chasnovski
2026-07-08 19:23:28 +03:00
committed by GitHub
parent ef130902cf
commit 0653e7a338
10 changed files with 160 additions and 21 deletions

View File

@@ -4888,6 +4888,15 @@ vim.o.opfunc = vim.o.operatorfunc
vim.go.operatorfunc = vim.o.operatorfunc
vim.go.opfunc = vim.go.operatorfunc
--- Path of `vim.pack-lockfile`. Must be set before the first usage of any
--- `vim.pack` function. Environment variables are expanded `:set_env`.
---
--- @type string
vim.o.packlockfile = "$XDG_CONFIG_HOME/nvim/nvim-pack-lock.json"
vim.o.plf = vim.o.packlockfile
vim.go.packlockfile = vim.o.packlockfile
vim.go.plf = vim.go.packlockfile
--- Directories used to find packages.
--- See `packages` and `packages-runtimepath`.
--- Environment variables are expanded `:set_env`.

View File

@@ -16,8 +16,8 @@
---Like `v1.2.0` or `1.2.0`, but not `1.2` or `v1`.
---
---The latest state of all managed plugins is stored inside a [vim.pack-lockfile]()
---located at `$XDG_CONFIG_HOME/nvim/nvim-pack-lock.json`. It is a JSON file that
---is used to persistently track data about plugins.
---located at |'packlockfile'|.
---It is a JSON file that is used to persistently track data about plugins.
---For a more robust config treat lockfile like its part: put under version control, etc.
---In this case all plugins from the lockfile will be installed at once (in alphabetical order) and
---at lockfile's revision (instead of inferring from `version`). This is done on the very first
@@ -258,10 +258,6 @@ local function get_plug_dir()
return vim.fs.joinpath(vim.fn.stdpath('data'), 'site', 'pack', 'core', 'opt')
end
local function lock_get_path()
return vim.fs.joinpath(vim.fn.stdpath('config'), 'nvim-pack-lock.json')
end
-- Git ------------------------------------------------------------------------
--- @async
@@ -871,9 +867,8 @@ local function lock_write()
end
end
local path = lock_get_path()
vim.fn.mkdir(vim.fs.dirname(path), 'p')
local fd = assert(uv.fs_open(path, 'w', 438))
vim.fn.mkdir(vim.fs.dirname(M._plugin_lock_path), 'p')
local fd = assert(uv.fs_open(M._plugin_lock_path, 'w', 438))
local data = vim.json.encode(lock, { indent = ' ', sort_keys = true })
assert(uv.fs_write(fd, data .. '\n'))
@@ -998,7 +993,8 @@ local function lock_read(confirm, specs)
return
end
local fd = uv.fs_open(lock_get_path(), 'r', 438)
M._plugin_lock_path = vim.go.packlockfile
local fd = uv.fs_open(M._plugin_lock_path, 'r', 438)
if fd then
local stat = assert(uv.fs_fstat(fd))
local data = assert(uv.fs_read(fd, stat.size, 0))

View File

@@ -3,7 +3,7 @@ local M = {}
local health = vim.health
local function get_lockfile_path()
return vim.fs.joinpath(vim.fn.stdpath('config'), 'nvim-pack-lock.json')
return vim.pack._plugin_lock_path or vim.go.packlockfile
end
local function get_plug_dir()
@@ -159,7 +159,8 @@ end
local function check_lockfile()
health.start('vim.pack: lockfile')
local can_read, text = pcall(vim.fn.readblob, get_lockfile_path())
local path = get_lockfile_path()
local can_read, text = pcall(vim.fn.readblob, path)
if not can_read then
health.error('Could not read lockfile. Delete it and restart Nvim.')
return
@@ -177,6 +178,18 @@ local function check_lockfile()
end
local is_good = true
if path ~= vim.go.packlockfile then
health.warn(
"Lockfile path is not the same as 'packlockfile' option value. "
.. "Set 'packlockfile' before the first usage of `vim.pack` function."
)
is_good = false
end
if path ~= vim.fs.abspath(path) then
health.warn('Lockfile path is not absolute. Make sure that this is intentional.')
is_good = false
end
--- @cast data { plugins: table<string,table> }
for plug_name, lock_data in pairs(data.plugins) do
is_good = check_plugin_lock_data(plug_name, lock_data) and is_good