Skip to content

Commit 0625493

Browse files
committed
feat!: local plugins now always need to set Plugin.dir
1 parent 2a7466a commit 0625493

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

lua/lazy/core/config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ M.defaults = {
1717
-- log = { "-10" }, -- last 10 commits
1818
log = { "--since=1 days ago" }, -- commits from the last 3 days
1919
timeout = 120, -- processes taking over 2 minutes will be killed
20+
url_format = "https://github.com/%s.git",
2021
},
2122
-- Any plugin spec that contains one of the patterns will use your
2223
-- local repo in the projects folder instead of fetchig it from github

lua/lazy/core/plugin.lua

+34-31
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,48 @@ function Spec.new(spec)
6161
return self
6262
end
6363

64+
-- PERF: optimized code to get package name without using lua patterns
65+
function Spec.get_name(pkg)
66+
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg
67+
local slash = name:reverse():find("/", 1, true) --[[@as number?]]
68+
return slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
69+
end
70+
6471
---@param plugin LazyPlugin
6572
---@param is_dep? boolean
6673
function Spec:add(plugin, is_dep)
67-
local pkg = plugin[1]
68-
if type(pkg) ~= "string" then
69-
Util.error("Invalid plugin spec " .. vim.inspect(plugin))
74+
if not plugin.url and plugin[1] then
75+
plugin.url = Config.options.git.url_format:format(plugin[1])
7076
end
7177

72-
if not plugin.url then
73-
local c = pkg:sub(1, 1)
74-
if c == "~" then
75-
plugin.url = vim.loop.os_getenv("HOME") .. pkg:sub(2)
76-
elseif c == "/" or pkg:sub(1, 4) == "http" or pkg:sub(1, 3) == "ssh" then
77-
plugin.url = pkg
78+
if plugin.dir then
79+
-- local plugin
80+
plugin.name = plugin.name or Spec.get_name(plugin.dir)
81+
elseif plugin.url then
82+
plugin.name = plugin.name or Spec.get_name(plugin.url)
83+
-- check for dev plugins
84+
if plugin.dev == nil then
85+
for _, pattern in ipairs(Config.options.dev.patterns) do
86+
if plugin.url:find(pattern, 1, true) then
87+
plugin.dev = true
88+
break
89+
end
90+
end
91+
end
92+
-- dev plugins
93+
if plugin.dev then
94+
plugin.dir = Config.options.dev.path .. "/" .. plugin.name
7895
else
79-
plugin.url = ("https://github.com/" .. pkg .. ".git")
96+
-- remote plugin
97+
plugin.dir = Config.options.root .. "/" .. plugin.name
8098
end
81-
end
82-
83-
-- PERF: optimized code to get package name without using lua patterns
84-
if not plugin.name then
85-
local name = pkg:sub(-4) == ".git" and pkg:sub(1, -5) or pkg
86-
local slash = name:reverse():find("/", 1, true) --[[@as number?]]
87-
plugin.name = slash and name:sub(#name - slash + 2) or pkg:gsub("%W+", "_")
99+
else
100+
Util.error("Invalid plugin spec " .. vim.inspect(plugin))
88101
end
89102

90103
plugin._ = {}
91104
plugin._.dep = is_dep
92105

93-
-- check for plugins that should be local
94-
for _, pattern in ipairs(Config.options.dev.patterns) do
95-
if plugin.dev or (plugin[1]:find(pattern, 1, true) and plugin.dev ~= false) then
96-
plugin.url = Config.options.dev.path .. "/" .. plugin.name
97-
break
98-
end
99-
end
100-
101106
local other = self.plugins[plugin.name]
102107
self.plugins[plugin.name] = other and self:merge(other, plugin) or plugin
103108
return self.plugins[plugin.name]
@@ -171,14 +176,12 @@ function M.update_state()
171176
or plugin.cmd
172177
plugin.lazy = lazy and true or false
173178
end
174-
if plugin.url:sub(1, 4) ~= "http" and plugin.url:sub(1, 3) ~= "git" then
175-
plugin._.is_local = true
176-
plugin.dir = plugin.url
177-
plugin._.installed = true -- user should make sure the directory exists
178-
else
179-
plugin.dir = Config.options.root .. "/" .. plugin.name
179+
if plugin.dir:find(Config.options.root) == 1 then
180180
plugin._.installed = installed[plugin.name] ~= nil
181181
installed[plugin.name] = nil
182+
else
183+
plugin._.is_local = true
184+
plugin._.installed = true -- local plugins are managed by the user
182185
end
183186
end
184187

0 commit comments

Comments
 (0)