From 5443f5f0672ec53b564b3b2aeb38ac3a6713845a Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Mon, 6 Nov 2023 07:36:10 +0100 Subject: [PATCH] chore(nvim): re-add Get_project_node_modules_path --- vim/lua/formatter_config.lua | 2 +- vim/lua/helpers.lua | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vim/lua/formatter_config.lua b/vim/lua/formatter_config.lua index 3ad391c..2a39c97 100644 --- a/vim/lua/formatter_config.lua +++ b/vim/lua/formatter_config.lua @@ -1,6 +1,6 @@ local prettier = function() return { - exe = vim.fn.getcwd() .. "/node_modules/.bin/prettier", + exe = Get_project_node_modules_path() .. "/.bin/prettier", args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" }, stdin = true, } diff --git a/vim/lua/helpers.lua b/vim/lua/helpers.lua index 9db7bcf..6b049ff 100644 --- a/vim/lua/helpers.lua +++ b/vim/lua/helpers.lua @@ -1,3 +1,16 @@ +-- Return the node_modules path for this project. If the project root contains a +-- frontend/ directory, assume node_modules lives there. +function Get_project_node_modules_path() + local root_path = vim.fn.getcwd() + local frontend_path = root_path .. "/frontend" + local is_frontend = vim.fn.isdirectory(frontend_path) ~= 0 + local base_path = root_path + if is_frontend then + base_path = frontend_path + end + return base_path .. "/node_modules" +end + -- Return the project's go module path from go.mod, or an empty string if the file cannot be read. function Get_project_go_module_path() local root_path = vim.fn.getcwd()