From 4c26421785be8c49f1d8eaa5bdb55b73c7be5127 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 30 Jun 2023 18:22:39 +0200 Subject: [PATCH] feat(build): added support for build.lua, build/init.lua (#903) --- lua/lazy/manage/task/plugin.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lua/lazy/manage/task/plugin.lua b/lua/lazy/manage/task/plugin.lua index 9e6d84a..00dd262 100644 --- a/lua/lazy/manage/task/plugin.lua +++ b/lua/lazy/manage/task/plugin.lua @@ -4,13 +4,23 @@ local Loader = require("lazy.core.loader") ---@type table local M = {} +---@param plugin LazyPlugin +local function get_build_file(plugin) + for _, path in ipairs({ "build.lua", "build/init.lua" }) do + path = plugin.dir .. "/" .. path + if Util.file_exists(path) then + return path + end + end +end + M.build = { ---@param opts? {force:boolean} skip = function(plugin, opts) if opts and opts.force then return false end - return not (plugin._.dirty and plugin.build) + return not (plugin._.dirty and (plugin.build or get_build_file(plugin))) end, run = function(self) vim.cmd([[silent! runtime plugin/rplugin.vim]]) @@ -18,6 +28,20 @@ M.build = { Loader.load(self.plugin, { task = "build" }) local builders = self.plugin.build + + local build_file = get_build_file(self.plugin) + if build_file then + if builders then + Util.warn( + ("Plugin **%s** provides its own build script.\nPlease remove the `build` option from the plugin's spec"):format( + self.plugin.name + ) + ) + end + builders = function() + Loader.source(build_file) + end + end if builders then builders = type(builders) == "table" and builders or { builders } ---@cast builders (string|fun(LazyPlugin))[]