From b7df1fd7acb09fd0421b5f719fcc86d8f577f308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3bal=20Gajardo=20Vera?= Date: Sun, 1 Sep 2024 19:40:38 -0400 Subject: [PATCH] fix(markdown-preview-nvim): build using yarn when possible, else throw --- .../markdown-preview-nvim/README.md | 3 +++ .../markdown-preview-nvim/init.lua | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/README.md b/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/README.md index 0c6515845..5d32ba743 100644 --- a/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/README.md +++ b/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/README.md @@ -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:** diff --git a/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/init.lua b/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/init.lua index c34db128c..5ee39911b 100644 --- a/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/init.lua +++ b/lua/astrocommunity/markdown-and-latex/markdown-preview-nvim/init.lua @@ -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()