Skip to content

Commit

Permalink
fix(build): allow build command to override plugin's build and opti…
Browse files Browse the repository at this point in the history
…on to disable warning
  • Loading branch information
folke committed Jun 30, 2023
1 parent de0a911 commit 189371c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ return {
-- leave nil when passing the spec as the first argument to setup()
spec = nil, ---@type LazySpec
lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
concurrency = jit.os:find("Windows") and (vim.loop.available_parallelism() * 2) or nil, ---@type number limit the maximum amount of concurrent tasks
git = {
-- defaults for the `Lazy log` command
-- log = { "-10" }, -- show the last 10 commits
Expand Down Expand Up @@ -439,6 +439,12 @@ return {
skip_if_doc_exists = true,
},
state = vim.fn.stdpath("state") .. "/lazy/state.json", -- state info for checker and other things
build = {
-- Plugins can provide a `build.lua` file that will be executed when the plugin is installed
-- or updated. When the plugin spec also has a `build` command, the plugin's `build.lua` not be
-- executed. In this case, a warning message will be shown.
warn_on_override = true,
},
}
```

Expand Down Expand Up @@ -500,6 +506,7 @@ Any operation can be started from the UI, with a sub command or an API function:
| `:Lazy load {plugins}` | `require("lazy").load(opts)` | Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`. Use `:Lazy! load` to skip `cond` checks. |
| `:Lazy log [plugins]` | `require("lazy").log(opts?)` | Show recent updates |
| `:Lazy profile` | `require("lazy").profile()` | Show detailed profiling |
| `:Lazy reload {plugins}` | `require("lazy").reload(opts)` | Reload a plugin (experimental!!) |
| `:Lazy restore [plugins]` | `require("lazy").restore(opts?)` | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
| `:Lazy sync [plugins]` | `require("lazy").sync(opts?)` | Run install, clean and update |
| `:Lazy update [plugins]` | `require("lazy").update(opts?)` | Update plugins. This will also update the lockfile |
Expand Down
6 changes: 6 additions & 0 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ M.defaults = {
skip_if_doc_exists = true,
},
state = vim.fn.stdpath("state") .. "/lazy/state.json", -- state info for checker and other things
build = {
-- Plugins can provide a `build.lua` file that will be executed when the plugin is installed
-- or updated. When the plugin spec also has a `build` command, the plugin's `build.lua` not be
-- executed. In this case, a warning message will be shown.
warn_on_override = true,
},
debug = false,
}

Expand Down
18 changes: 11 additions & 7 deletions lua/lazy/manage/task/plugin.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Util = require("lazy.util")
local Loader = require("lazy.core.loader")
local Config = require("lazy.core.config")

---@type table<string, LazyTaskDef>
local M = {}
Expand Down Expand Up @@ -32,14 +33,17 @@ M.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
if Config.options.build.warn_on_override then
Util.warn(
("Plugin **%s** provides its own build script, but you also defined a `build` command.\nThe `build.lua` file will not be used"):format(
self.plugin.name
)
)
)
end
builders = function()
Loader.source(build_file)
end
else
builders = function()
Loader.source(build_file)
end
end
end
if builders then
Expand Down

0 comments on commit 189371c

Please sign in to comment.