iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.67k stars 277 forks source link

npm install with lazy error #616

Open miguelbarao opened 11 months ago

miguelbarao commented 11 months ago

Describe the bug

Using lazy package manager. Since a few weeks, markdown-preview installed with npm gives an error message:

        You have local changes in `/.../.local/share/nvim/lazy/markdown-preview.nvim`:
          * app/yarn.lock
        Please remove them to update.
        You can also press `x` to remove the plugin and then `I` to install it again.

I have to manually uninstall and reinstall every time this error appears. Maybe this yarn.lock file shouldn't be tracked by git?

To Reproduce

Use the follow config in lazy:

{
  'iamcco/markdown-preview.nvim',
  lazy = true,
  build = 'cd app && npm install',
  cmd = { 'MarkdownPreviewToggle', 'MarkdownPreview', 'MarkdownPreviewStop' },
  ft = { 'markdown' },
  keys = {
    { '<f5>', '<Cmd>MarkdownPreviewToggle<CR>', desc = 'Toggle MarkdownPreview'}
  },
  config = function()
    vim.g.mkdp_filetypes = { 'markdown' }
    vim.g.mkdp_theme = 'light'
  end,
}

Desktop (please complete the following information):

daUnknownCoder commented 11 months ago

same issue, check #612

pysan3 commented 11 months ago

It is impossible to solve if you use npm as the installer due to this open issue: https://github.com/npm/cli/issues/5126

So, I think you should not mention npm as an installation method in the README: https://github.com/iamcco/markdown-preview.nvim/blob/a923f5fc5ba36a3b17e289dc35dc17f66d0548ee/README.md?plain=1#L109

The commands that should work property are

daUnknownCoder commented 11 months ago

It is impossible to solve if you use npm as the installer due to this open issue: npm/cli#5126

So, I think you should not mention npm as an installation method in the README:

https://github.com/iamcco/markdown-preview.nvim/blob/a923f5fc5ba36a3b17e289dc35dc17f66d0548ee/README.md?plain=1#L109

The commands that should work property are

* `cd app && npx --yes yarn install`

* `cd app && npm install && rm -f package-lock.json && git restore .`

what works for now is:

      local job = require("plenary.job")
      local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
      local cmd = "bash"

      if vim.fn.has("win64") == 1 then
        cmd = "pwsh"
      end

      job
        :new({
          command = cmd,
          args = { "-c", "npm install && git restore ." },
          cwd = install_path,
          on_exit = function()
            print("Finished installing markdown-preview.nvim")
          end,
          on_stderr = function(_, data)
            print(data)
          end,
        })
        :start()

      -- Options
      vim.g.mkdp_auto_close = 0