feat: symlinking local plugins is no longer needed

This commit is contained in:
Folke Lemaitre 2022-12-03 15:31:21 +01:00
parent 7b272b6ed6
commit 37c7366ab0
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 25 additions and 50 deletions

View file

@ -1,52 +1,31 @@
local Util = require("lazy.util")
local Config = require("lazy.core.config")
---@type table<string, LazyTaskDef>
local M = {}
M.clean = {
skip = function(plugin)
return plugin._.is_local
end,
run = function(self)
local dir = self.plugin.dir:gsub("/+$", "")
local stat = vim.loop.fs_lstat(dir)
assert(dir:find(Config.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")
if stat.type == "directory" then
Util.walk(dir, function(path, _, type)
if type == "directory" then
vim.loop.fs_rmdir(path)
else
vim.loop.fs_unlink(path)
end
end)
vim.loop.fs_rmdir(dir)
else
vim.loop.fs_unlink(dir)
end
local stat = vim.loop.fs_lstat(dir)
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")
Util.walk(dir, function(path, _, type)
if type == "directory" then
vim.loop.fs_rmdir(path)
else
vim.loop.fs_unlink(path)
end
end)
vim.loop.fs_rmdir(dir)
self.plugin._.installed = false
end,
}
M.symlink = {
skip = function(plugin)
if not plugin._.is_local then
return true
end
return not plugin._.is_symlink and plugin._.installed
end,
run = function(self)
local stat = vim.loop.fs_lstat(self.plugin.dir)
if stat then
if vim.loop.fs_realpath(self.plugin.uri) == vim.loop.fs_realpath(self.plugin.dir) then
self.plugin._.installed = true
return
else
vim.loop.fs_unlink(self.plugin.dir)
end
end
vim.loop.fs_symlink(self.plugin.uri, self.plugin.dir, { dir = true })
vim.opt.runtimepath:append(self.plugin.uri)
self.plugin._.installed = true
self.plugin._.cloned = true
end,
}
return M