mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
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
This commit is contained in:
parent
8192267dea
commit
3cc3506965
@ -502,10 +502,10 @@ function! s:check_node() abort
|
||||
return
|
||||
endif
|
||||
|
||||
if !executable('node') || !executable('npm')
|
||||
if !executable('node') || (!executable('npm') && !executable('yarn'))
|
||||
call health#report_warn(
|
||||
\ '`node` and `npm` must be in $PATH.',
|
||||
\ ['Install Node.js and verify that `node` and `npm` commands work.'])
|
||||
\ '`node` and `npm` (or `yarn`) must be in $PATH.',
|
||||
\ ['Install Node.js and verify that `node` and `npm` (or `yarn`) commands work.'])
|
||||
return
|
||||
endif
|
||||
let node_v = get(split(s:system('node -v'), "\n"), 0, '')
|
||||
@ -521,9 +521,9 @@ function! s:check_node() abort
|
||||
|
||||
let host = provider#node#Detect()
|
||||
if empty(host)
|
||||
call health#report_warn('Missing "neovim" npm package.',
|
||||
call health#report_warn('Missing "neovim" npm (or yarn) package.',
|
||||
\ ['Run in shell: npm install -g neovim',
|
||||
\ 'Is the npm bin directory in $PATH?'])
|
||||
\ 'Run in shell (if you use yarn): yarn global add neovim'])
|
||||
return
|
||||
endif
|
||||
call health#report_info('Neovim node.js host: '. host)
|
||||
@ -559,7 +559,7 @@ function! s:check_node() abort
|
||||
\ current_npm, latest_npm),
|
||||
\ ['Run in shell: npm install -g neovim'])
|
||||
else
|
||||
call health#report_ok('Latest "neovim" npm package is installed: '. current_npm)
|
||||
call health#report_ok('Latest "neovim" npm/yarn package is installed: '. current_npm)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user