From 8c22f4d02288c90b318cd37f810b43d625286b47 Mon Sep 17 00:00:00 2001 From: Theo Cavignac Date: Wed, 2 Aug 2023 02:06:21 +0200 Subject: [PATCH] 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. --- lua/lazy/manage/task/plugin.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/lazy/manage/task/plugin.lua b/lua/lazy/manage/task/plugin.lua index fd6153b..17b18ec 100644 --- a/lua/lazy/manage/task/plugin.lua +++ b/lua/lazy/manage/task/plugin.lua @@ -15,6 +15,13 @@ local function get_build_file(plugin) 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 = { ---@param opts? {force:boolean} skip = function(plugin, opts) @@ -52,9 +59,13 @@ M.build = { for _, build in ipairs(builders) do if type(build) == "string" and build:sub(1, 1) == ":" then local cmd = vim.api.nvim_parse_cmd(build:sub(2), {}) - self.output = vim.api.nvim_cmd(cmd, { output = true }) + do_in_dir(self.plugin.dir, function() + self.output = vim.api.nvim_cmd(cmd, { output = true }) + end) elseif type(build) == "function" then - build(self.plugin) + do_in_dir(self.plugin.dir, function() + build(self.plugin) + end) else local shell = vim.env.SHELL or vim.o.shell local shell_args = shell:find("cmd.exe", 1, true) and "/c" or "-c"