From 189371c8d8ac8205687522dd4c3601edc7b7a927 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Fri, 30 Jun 2023 21:19:30 +0200 Subject: [PATCH] fix(build): allow `build` command to override plugin's build and option to disable warning --- README.md | 9 ++++++++- lua/lazy/core/config.lua | 6 ++++++ lua/lazy/manage/task/plugin.lua | 18 +++++++++++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 86107612..a30e6514 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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, + }, } ``` @@ -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 | diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index b655b9bb..9a25a7d6 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -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, } diff --git a/lua/lazy/manage/task/plugin.lua b/lua/lazy/manage/task/plugin.lua index 00dd262a..fd6153b2 100644 --- a/lua/lazy/manage/task/plugin.lua +++ b/lua/lazy/manage/task/plugin.lua @@ -1,5 +1,6 @@ local Util = require("lazy.util") local Loader = require("lazy.core.loader") +local Config = require("lazy.core.config") ---@type table local M = {} @@ -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