aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/installers
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2021-09-22 01:35:39 +0200
committerGitHub <noreply@github.com>2021-09-22 01:35:39 +0200
commit12da7fa3fbb65d516a342b869fa0914803630516 (patch)
tree412b77ddf7e348769846789a26a073c7da8ad88b /lua/nvim-lsp-installer/installers
parentadd jdtls (#94) (diff)
downloadmason-12da7fa3fbb65d516a342b869fa0914803630516.tar
mason-12da7fa3fbb65d516a342b869fa0914803630516.tar.gz
mason-12da7fa3fbb65d516a342b869fa0914803630516.tar.bz2
mason-12da7fa3fbb65d516a342b869fa0914803630516.tar.lz
mason-12da7fa3fbb65d516a342b869fa0914803630516.tar.xz
mason-12da7fa3fbb65d516a342b869fa0914803630516.tar.zst
mason-12da7fa3fbb65d516a342b869fa0914803630516.zip
installers/npm: ensure local npm root dir before installing (#97)
Diffstat (limited to 'lua/nvim-lsp-installer/installers')
-rw-r--r--lua/nvim-lsp-installer/installers/npm.lua26
1 files changed, 14 insertions, 12 deletions
diff --git a/lua/nvim-lsp-installer/installers/npm.lua b/lua/nvim-lsp-installer/installers/npm.lua
index f9ea7025..6b5546e4 100644
--- a/lua/nvim-lsp-installer/installers/npm.lua
+++ b/lua/nvim-lsp-installer/installers/npm.lua
@@ -1,4 +1,5 @@
local path = require "nvim-lsp-installer.path"
+local fs = require "nvim-lsp-installer.fs"
local installers = require "nvim-lsp-installer.installers"
local std = require "nvim-lsp-installer.installers.std"
local platform = require "nvim-lsp-installer.platform"
@@ -23,23 +24,24 @@ end
function M.packages(packages)
return ensure_npm(function(server, callback, context)
- process.spawn(npm, {
- args = vim.list_extend({ "install" }, packages),
+ local c = process.chain {
cwd = server.root_dir,
stdio_sink = context.stdio_sink,
- }, callback)
+ }
+ -- stylua: ignore start
+ if not (fs.dir_exists(path.concat { server.root_dir, "node_modules" }) or
+ fs.file_exists(path.concat { server.root_dir, "package.json" }))
+ then
+ c.run(npm, { "init", "--yes" })
+ end
+ -- stylua: ignore end
+ c.run(npm, vim.list_extend({ "install" }, packages))
+ c.spawn(callback)
end)
end
-function M.install(args)
- return ensure_npm(function(server, callback, context)
- process.spawn(npm, {
- args = vim.list_extend({ "install" }, args),
- cwd = server.root_dir,
- stdio_sink = context.stdio_sink,
- }, callback)
- end)
-end
+-- @alias for packages
+M.install = M.packages
function M.exec(executable, args)
return function(server, callback, context)