fix: Always run build tasks in the plugin directory

Before this, only shell commands were run in the plugin directory.
This ensures a coherent behavior by always changing to the plugin
directory for build tasks.
This commit is contained in:
Theo Cavignac 2023-08-02 02:06:21 +02:00 committed by Théo Cavignac
commit 8c22f4d022

View file

@ -15,6 +15,13 @@ local function get_build_file(plugin)
end end
end end
local function do_in_dir(dir, fn)
local d = vim.loop.getcwd()
vim.loop.chdir(dir)
fn()
vim.loop.chdir(d)
end
M.build = { M.build = {
---@param opts? {force:boolean} ---@param opts? {force:boolean}
skip = function(plugin, opts) skip = function(plugin, opts)
@ -52,9 +59,13 @@ M.build = {
for _, build in ipairs(builders) do for _, build in ipairs(builders) do
if type(build) == "string" and build:sub(1, 1) == ":" then if type(build) == "string" and build:sub(1, 1) == ":" then
local cmd = vim.api.nvim_parse_cmd(build:sub(2), {}) local cmd = vim.api.nvim_parse_cmd(build:sub(2), {})
do_in_dir(self.plugin.dir, function()
self.output = vim.api.nvim_cmd(cmd, { output = true }) self.output = vim.api.nvim_cmd(cmd, { output = true })
end)
elseif type(build) == "function" then elseif type(build) == "function" then
do_in_dir(self.plugin.dir, function()
build(self.plugin) build(self.plugin)
end)
else else
local shell = vim.env.SHELL or vim.o.shell local shell = vim.env.SHELL or vim.o.shell
local shell_args = shell:find("cmd.exe", 1, true) and "/c" or "-c" local shell_args = shell:find("cmd.exe", 1, true) and "/c" or "-c"