Skip to content

Commit 4c26421

Browse files
authored
feat(build): added support for build.lua, build/init.lua (#903)
1 parent 2772cc5 commit 4c26421

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lua/lazy/manage/task/plugin.lua

+25-1
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,44 @@ local Loader = require("lazy.core.loader")
44
---@type table<string, LazyTaskDef>
55
local M = {}
66

7+
---@param plugin LazyPlugin
8+
local function get_build_file(plugin)
9+
for _, path in ipairs({ "build.lua", "build/init.lua" }) do
10+
path = plugin.dir .. "/" .. path
11+
if Util.file_exists(path) then
12+
return path
13+
end
14+
end
15+
end
16+
717
M.build = {
818
---@param opts? {force:boolean}
919
skip = function(plugin, opts)
1020
if opts and opts.force then
1121
return false
1222
end
13-
return not (plugin._.dirty and plugin.build)
23+
return not (plugin._.dirty and (plugin.build or get_build_file(plugin)))
1424
end,
1525
run = function(self)
1626
vim.cmd([[silent! runtime plugin/rplugin.vim]])
1727

1828
Loader.load(self.plugin, { task = "build" })
1929

2030
local builders = self.plugin.build
31+
32+
local build_file = get_build_file(self.plugin)
33+
if build_file then
34+
if builders then
35+
Util.warn(
36+
("Plugin **%s** provides its own build script.\nPlease remove the `build` option from the plugin's spec"):format(
37+
self.plugin.name
38+
)
39+
)
40+
end
41+
builders = function()
42+
Loader.source(build_file)
43+
end
44+
end
2145
if builders then
2246
builders = type(builders) == "table" and builders or { builders }
2347
---@cast builders (string|fun(LazyPlugin))[]

0 commit comments

Comments
 (0)