diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim index 69f0b711fc..55fa1ff65e 100644 --- a/runtime/autoload/health/provider.vim +++ b/runtime/autoload/health/provider.vim @@ -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 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