The current implementation did it like this (example from linters/biomejs)
-- local binary_name = "biome"
cmd = function()
local local_binary = vim.fn.fnamemodify('./node_modules/.bin/' .. binary_name, ':p')
return vim.loop.fs_stat(local_binary) and local_binary or binary_name
end,
The problem is if we did not open an nvim instance on the folder that contains the node_modules folder (e.g. when working with multiple projects), this does not work.
Solution Idea
By using vim.fs.find we can find the node_modules directory relative to the open buffer and now the problem is gone.
-- local binary_name = "biome"
cmd = function()
local dirname = vim.fs.dirname(vim.api.nvim_buf_get_name(0))
local node_folders =
vim.fs.find("node_modules/.bin/" .. binary_name, { upward = true, path = dirname })
for _, result in ipairs(node_folders) do
if vim.fn.executable(result) == 1 then
return result
end
end
-- fallback
return binary_name
end
Problem
The current implementation did it like this (example from linters/biomejs)
The problem is if we did not open an nvim instance on the folder that contains the
node_modules
folder (e.g. when working with multiple projects), this does not work.Solution Idea
By using
vim.fs.find
we can find thenode_modules
directory relative to the open buffer and now the problem is gone.I can open a PR to implement this, if it's okay.