feat(build): added support for build.lua, build/init.lua

This commit is contained in:
Folke Lemaitre 2023-06-30 18:09:41 +02:00
parent 2772cc587e
commit 21dcfb1d13
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
1 changed files with 25 additions and 1 deletions

View File

@ -4,13 +4,23 @@ local Loader = require("lazy.core.loader")
---@type table<string, LazyTaskDef> ---@type table<string, LazyTaskDef>
local M = {} 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 = { M.build = {
---@param opts? {force:boolean} ---@param opts? {force:boolean}
skip = function(plugin, opts) skip = function(plugin, opts)
if opts and opts.force then if opts and opts.force then
return false return false
end end
return not (plugin._.dirty and plugin.build) return not (plugin._.dirty and (plugin.build or get_build_file(plugin)))
end, end,
run = function(self) run = function(self)
vim.cmd([[silent! runtime plugin/rplugin.vim]]) vim.cmd([[silent! runtime plugin/rplugin.vim]])
@ -18,6 +28,20 @@ M.build = {
Loader.load(self.plugin, { task = "build" }) Loader.load(self.plugin, { task = "build" })
local builders = self.plugin.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 if builders then
builders = type(builders) == "table" and builders or { builders } builders = type(builders) == "table" and builders or { builders }
---@cast builders (string|fun(LazyPlugin))[] ---@cast builders (string|fun(LazyPlugin))[]