folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.04k stars 336 forks source link

feature: Update bootstrap.lua #1732

Closed hoofcushion closed 21 hours ago

hoofcushion commented 2 weeks ago

Did you check the docs?

Is your feature request related to a problem? Please describe.

lazy.nvim can not update the bootstrap.lua. It has to be fetch manually.

Describe the solution you'd like

Use a steady code to always do these thing:

  1. Check if bootstrap.lua exists.
  2. If it does not exist, Try to get bootstrap.lua from internet, and store it in somewhere in the stdpath.
  3. Otherwise, just require it normally, pass some options, and do the bootstrap.
  4. Once bootstrap is done, lazy.nvim could try to update the bootstrap.lua whenever lazy.nvim itself has an update.
  5. Repeat 3~4, then bootstrap.lua will always be updated.

Describe alternatives you've considered

pass

Additional context

No response

hoofcushion commented 2 weeks ago

This is my solution:

local lazypath=vim.fs.joinpath(vim.fn.stdpath("data"),"lazy")
local bspath=vim.fs.joinpath(lazypath,"bootstrap.lua")
if not vim.uv.fs_stat(bspath) then
 vim.fn.system({
  "curl",
  "-o",bspath,
  "-s","https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua",
 })
end
local Bootstrap=loadfile(bspath)()
-- Option for bootstrap still not implemented yet.
-- Bootstrap.setup({
--  lazypath=lazypath,
-- })
-- The update logic should be hold by lazy.nvim
---@return boolean
local function is_samefile(filename1,filename2)
 local f1=vim.uv.fs_stat(filename1)
 local f2=vim.uv.fs_stat(filename2)
 return f1 and f2
  and f1.size==f2.size
  and f1.type==f2.type
  and f1.mtime==f2.mtime
  and f1.ino==f2.ino
end
vim.api.nvim_create_autocmd("User",{
 pattern="LazyUpdate",
 callback=function()
  local new=vim.fs.joinpath(lazypath,"lazy.nvim","bootstrap.lua")
  if not is_samefile(new,bspath) then
   vim.uv.fs_unlink(bspath)
   vim.uv.fs_copyfile(new,bspath)
  end
 end,
})
max397574 commented 2 weeks ago

just install lazy.nvim as a plugin? You only need the bootstrap file if lazy isn't installed at all

hoofcushion commented 2 weeks ago

I know that, I mean it's better that lazy have a way to update the bootstrap.lua.

Then whenever bootstrap.lua an update, you don't have to copy and paste. all the time.

max397574 commented 2 weeks ago

imo this makes just no sense if the bootstrap would ever be updated it would still just be required to install lazy.nvim so if you have lazy.nvim installed you don't need to reload the bootstrap.lua file even if it would change

hoofcushion commented 2 weeks ago

I don't understand what you said, if lazy.nvim update, then bootstrap also needs update.

I think you mean the lazy will never needs to change the way to bootstrap, but it was not guaranteed.

Whenever bootstrap.lua outdated, everyone needs to fetch manually again and again.

So the new bookstrap way is:

  1. Fetch it manually in the first place.
  2. Once the initial bootstrap is ready, lazy can keep update it automatically.

Then whenever neovim or lazy.nvim has a breaking change that deprecate the old bootstrap, lazy still can fix that by update it.

max397574 commented 2 weeks ago

no bootstrap doesn't need to be updated even if it ever will be changed it is really highly unlikely that it will do something different than installing lazy.nvim so if you already installed lazy you just don't need to care

hoofcushion commented 2 weeks ago

You're right in short term. And I was talking about a long term problem. That bootstrap must will be outdated.

Design a new way to update bootstrapb is a work that takes once, but works forever.

Maybe bootstrap won't be outdated in few months, but in a year or two, It's unlikely.