Skip to content

Commit

Permalink
fix(markdown-preview-nvim): build using yarn when possible, else throw
Browse files Browse the repository at this point in the history
  • Loading branch information
cristobalgvera committed Sep 3, 2024
1 parent 07ff0d8 commit b7df1fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# markdown-preview.nvim

> This plugin requires Node.js to be installed on your system.
> Without it, the installation process will fail, and the plugin won't work.
markdown preview plugin for (neo)vim

**Repository:** <https://github.com/iamcco/markdown-preview.nvim>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
---@type LazySpec
return {
"iamcco/markdown-preview.nvim",
build = function() vim.fn["mkdp#util#install"]() end,
build = function(plugin)
local package_manager = vim.fn.executable "yarn" and "yarn" or vim.fn.executable "npx" and "npx -y yarn" or false

--- HACK: Use `yarn` or `npx` when possible, otherwise throw an error
---@see https://github.com/iamcco/markdown-preview.nvim/issues/690
---@see https://github.com/iamcco/markdown-preview.nvim/issues/695
if not package_manager then error "Missing `yarn` or `npx` in the PATH" end

local cmd = string.format(
"!cd %s && cd app && COREPACK_ENABLE_AUTO_PIN=0 %s install --frozen-lockfile",
plugin.dir,
package_manager
)

vim.cmd(cmd)
end,
ft = { "markdown", "markdown.mdx" },
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
init = function()
Expand Down

0 comments on commit b7df1fd

Please sign in to comment.