diff options
| author | Ahmed El Gabri <ahmed@gabri.me> | 2018-06-11 21:13:19 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-17 13:05:55 +0200 |
| commit | 3cc350696576f26fe1e978ef78125a1a6c7410ab (patch) | |
| tree | 84cfffaf377939aaf3e6ed7463487b58f1cc3b15 /runtime/autoload/provider/node.vim | |
| parent | 8192267deacdf958848324f6b7f99e72551c56e6 (diff) | |
| download | rneovim-3cc350696576f26fe1e978ef78125a1a6c7410ab.tar.gz rneovim-3cc350696576f26fe1e978ef78125a1a6c7410ab.tar.bz2 rneovim-3cc350696576f26fe1e978ef78125a1a6c7410ab.zip | |
checkhealth: node.js: also search yarn #8528
- "neovim" package may be installed with yarn. Check yarn if npm fails.
- Use filereadable() instead of glob(). closes #8552
Diffstat (limited to 'runtime/autoload/provider/node.vim')
| -rw-r--r-- | runtime/autoload/provider/node.vim | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim index 39b5dc63b8..bdc21514da 100644 --- a/runtime/autoload/provider/node.vim +++ b/runtime/autoload/provider/node.vim @@ -22,6 +22,28 @@ function! s:is_minimum_version(version, min_major, min_minor) abort \ && str2nr(v_list[1]) >= str2nr(a:min_minor))) endfunction +function! s:find_node_client(package_manager) abort + if !executable(a:package_manager) + return '' + endif + let is_yarn = a:package_manager ==# 'yarn' + let cmd = is_yarn ? 'yarn global dir' : 'npm root -g' + let global_modules_dir = get(split(system(cmd), "\n"), 0, '') + if v:shell_error || !isdirectory(global_modules_dir) + return '' + endif + " `yarn global dir` returns the parent of '/node_modules'. + let global_modules_dir = is_yarn ? global_modules_dir . '/node_modules' : global_modules_dir + if !isdirectory(global_modules_dir) + return '' + endif + let entry_point = global_modules_dir . '/neovim/bin/cli.js' + if !filereadable(entry_point) + return '' + endif + return entry_point +endfunction + " Support for --inspect-brk requires node 6.12+ or 7.6+ or 8+ " Return 1 if it is supported " Return 0 otherwise @@ -41,17 +63,11 @@ function! provider#node#Detect() abort if exists('g:node_host_prog') return g:node_host_prog endif - let global_modules = get(split(system('npm root -g'), "\n"), 0, '') - if v:shell_error || !isdirectory(global_modules) - return '' - endif if !s:is_minimum_version(v:null, 6, 0) return '' endif - let entry_point = glob(global_modules . '/neovim/bin/cli.js') - if !filereadable(entry_point) - return '' - endif + let entry_point = s:find_node_client('npm') + let entry_point = !empty(entry_point) ? entry_point : s:find_node_client('yarn') return entry_point endfunction |