fix(pack): handle plugin name normalization properly
This commit is contained in:
+21
-5
@@ -30,20 +30,30 @@ end
|
||||
---@field name string
|
||||
---@field path string
|
||||
|
||||
---@param name string
|
||||
---@return string?
|
||||
local function normalize_name(name)
|
||||
name = name:match("[^.]+")
|
||||
if name then
|
||||
return name:lower()
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
---@param plugin ow.Pack.Plugin
|
||||
local function load(plugin)
|
||||
local name = plugin.name:match("[^.]+")
|
||||
local name = normalize_name(plugin.name)
|
||||
if not name then
|
||||
log.error("Invalid plugin name: %s", plugin.name)
|
||||
return
|
||||
end
|
||||
name = name:lower()
|
||||
local path = string.format("%s/lua/plugins/%s.lua", config_dir, name)
|
||||
|
||||
if vim.uv.fs_stat(path) then
|
||||
local ok, err = exec(path)
|
||||
if not ok then
|
||||
log.error("Failed to load %s: %s", name, err)
|
||||
log.error("Failed to load %s: %s", plugin.name, err)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -126,7 +136,7 @@ end
|
||||
---@type uv.uv_fs_event_t?
|
||||
local watcher = nil
|
||||
|
||||
---@type table<string, uv.uv_timer_t?>
|
||||
---@type table<string, uv.uv_timer_t>
|
||||
local timers = {}
|
||||
|
||||
---@class ow.Pack
|
||||
@@ -147,7 +157,13 @@ end
|
||||
|
||||
---@param name string
|
||||
function M.reload(name)
|
||||
local path = string.format("%s/lua/plugins/%s.lua", config_dir, name)
|
||||
local normalized = normalize_name(name)
|
||||
if not normalized then
|
||||
log.error("Invalid plugin name: %s", name)
|
||||
return
|
||||
end
|
||||
|
||||
local path = string.format("%s/lua/plugins/%s.lua", config_dir, normalized)
|
||||
|
||||
if not vim.uv.fs_stat(path) then
|
||||
log.error("No config file found for %s", name)
|
||||
|
||||
Reference in New Issue
Block a user