Skip to content

Commit

Permalink
feat: symlinking local plugins is no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Dec 3, 2022
1 parent 7b272b6 commit 37c7366
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 49 deletions.
20 changes: 9 additions & 11 deletions lua/lazy/core/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local M = {}
---@field dirty? boolean
---@field updated? {from:string, to:string}
---@field is_local boolean
---@field is_symlink? boolean
---@field cloned? boolean
---@field dep? boolean True if this plugin is only in the spec as a dependency

Expand Down Expand Up @@ -165,11 +164,13 @@ function M.update_state()
or plugin.cmd
plugin.lazy = lazy and true or false
end
plugin.dir = Config.root .. "/" .. plugin.name
plugin._.is_local = plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git"
plugin._.is_symlink = installed[plugin.name] == "link"
plugin._.installed = installed[plugin.name] ~= nil
if plugin._.is_local == plugin._.is_symlink then
if plugin.uri:sub(1, 4) ~= "http" and plugin.uri:sub(1, 3) ~= "git" then
plugin._.is_local = true
plugin.dir = plugin.uri
plugin._.installed = true -- user should make sure the directory exists
else
plugin.dir = Config.root .. "/" .. plugin.name
plugin._.installed = installed[plugin.name] ~= nil
installed[plugin.name] = nil
end
end
Expand Down Expand Up @@ -240,11 +241,8 @@ end
-- Finds the plugin that has this path
---@param path string
function M.find(path)
if path:find(Config.root, 1, true) == 1 then
local plugin = path:sub(#Config.root + 2)
local idx = plugin:find("/", 1, true)
return idx and Config.plugins[plugin:sub(1, idx - 1)] or nil
end
local name = path:match("/([^/]+)/lua") or path:match("/([^/]+)/?$")
return name and Config.plugins[name] or nil
end

return M
2 changes: 0 additions & 2 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ end
function M.install(opts)
M.run({
pipeline = {
"fs.symlink",
"git.clone",
"git.checkout",
"plugin.docs",
Expand All @@ -72,7 +71,6 @@ function M.update(opts)
opts = opts or {}
M.run({
pipeline = {
"fs.symlink",
"git.branch",
"git.fetch",
{ "git.checkout", lockfile = opts.lockfile },
Expand Down
51 changes: 15 additions & 36 deletions lua/lazy/manage/task/fs.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
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)

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
assert(dir:find(Config.root, 1, true) == 1, self.plugin.dir .. " should be under packpath!")

self.plugin._.installed = false
end,
}
local stat = vim.loop.fs_lstat(dir)
assert(stat.type == "directory", self.plugin.dir .. " should be a directory!")

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
Util.walk(dir, function(path, _, type)
if type == "directory" then
vim.loop.fs_rmdir(path)
else
vim.loop.fs_unlink(self.plugin.dir)
vim.loop.fs_unlink(path)
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)
vim.loop.fs_rmdir(dir)

self.plugin._.installed = false
end,
}

Expand Down

0 comments on commit 37c7366

Please sign in to comment.