feat(node): add pnpm support #19461

This commit is contained in:
Percy Ma 2022-08-01 22:21:54 +08:00 committed by GitHub
parent 8d1c55e422
commit c6181a672a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 7 deletions

View File

@ -615,10 +615,10 @@ function! s:check_node() abort
return return
endif endif
if !executable('node') || (!executable('npm') && !executable('yarn')) if !executable('node') || (!executable('npm') && !executable('yarn') && !executable('pnpm'))
call health#report_warn( call health#report_warn(
\ '`node` and `npm` (or `yarn`) must be in $PATH.', \ '`node` and `npm` (or `yarn`, `pnpm`) must be in $PATH.',
\ ['Install Node.js and verify that `node` and `npm` (or `yarn`) commands work.']) \ ['Install Node.js and verify that `node` and `npm` (or `yarn`, `pnpm`) commands work.'])
return return
endif endif
let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '') let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '')
@ -634,15 +634,22 @@ function! s:check_node() abort
let [host, err] = provider#node#Detect() let [host, err] = provider#node#Detect()
if empty(host) if empty(host)
call health#report_warn('Missing "neovim" npm (or yarn) package.', call health#report_warn('Missing "neovim" npm (or yarn, pnpm) package.',
\ ['Run in shell: npm install -g neovim', \ ['Run in shell: npm install -g neovim',
\ 'Run in shell (if you use yarn): yarn global add neovim', \ 'Run in shell (if you use yarn): yarn global add neovim',
\ 'Run in shell (if you use pnpm): pnpm install -g neovim',
\ 'You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim']) \ 'You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim'])
return return
endif endif
call health#report_info('Nvim node.js host: '. host) call health#report_info('Nvim node.js host: '. host)
let manager = executable('npm') ? 'npm' : 'yarn' let manager = 'npm'
if executable('yarn')
let manager = 'yarn'
elseif executable('pnpm')
let manager = 'pnpm'
endif
let latest_npm_cmd = has('win32') ? let latest_npm_cmd = has('win32') ?
\ 'cmd /c '. manager .' info neovim --json' : \ 'cmd /c '. manager .' info neovim --json' :
\ manager .' info neovim --json' \ manager .' info neovim --json'
@ -673,9 +680,10 @@ function! s:check_node() abort
\ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s', \ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s',
\ current_npm, latest_npm), \ current_npm, latest_npm),
\ ['Run in shell: npm install -g neovim', \ ['Run in shell: npm install -g neovim',
\ 'Run in shell (if you use yarn): yarn global add neovim']) \ 'Run in shell (if you use yarn): yarn global add neovim',
\ 'Run in shell (if you use pnpm): pnpm install -g neovim'])
else else
call health#report_ok('Latest "neovim" npm/yarn package is installed: '. current_npm) call health#report_ok('Latest "neovim" npm/yarn/pnpm package is installed: '. current_npm)
endif endif
endfunction endfunction

View File

@ -82,6 +82,13 @@ function! provider#node#Detect() abort
let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts) let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts)
endif endif
let pnpm_opts = {}
if executable('pnpm')
let pnpm_opts = deepcopy(s:NodeHandler)
let pnpm_opts.entry_point = '/neovim/bin/cli.js'
let pnpm_opts.job_id = jobstart('pnpm --loglevel silent root -g', pnpm_opts)
endif
" npm returns the directory faster, so let's check that first " npm returns the directory faster, so let's check that first
if !empty(npm_opts) if !empty(npm_opts)
let result = jobwait([npm_opts.job_id]) let result = jobwait([npm_opts.job_id])
@ -97,6 +104,13 @@ function! provider#node#Detect() abort
endif endif
endif endif
if !empty(pnpm_opts)
let result = jobwait([pnpm_opts.job_id])
if result[0] == 0 && pnpm_opts.result != ''
return [pnpm_opts.result, '']
endif
endif
return ['', 'failed to detect node'] return ['', 'failed to detect node']
endfunction endfunction