ci: nodejs client acceptance-test #7706

ci: install nodejs 8 in Appveyor, Travis

provider: check node version for debug support
Resolve https://github.com/neovim/neovim/pull/7577#issuecomment-350590592 for Unix.

provider: test if nodejs in ci supports --inspect-brk

nodejs host for neovim requires nodejs 6+ to work properly.
nodejs 6.12+ or 7.6+ is required for debug support via `node --inspect-brk`.

provider: run cli.js of nodejs host directly

npm shims are useless because the user cannot set node to debug mode via
--inspect-brk. This is problematic on Windows which use batchfiles and
shell scripts to compensate for not supporting shebang.

The patch uses `npm root -g` to get the absolute path of the global npm
modules. If that fails, then the user did not install neovim npm package
globally. Use that absolute path to find `neovim/bin/cli.js`, which is
what the npm shim actually runs with node. glob() is for a simple file
check in case bin/ is removed because the npm shims are ignored now.
This commit is contained in:
Jan Edmund Lazo
2017-11-29 01:50:11 -05:00
committed by Justin M. Keyes
parent bfb21f3e01
commit a1adfdc7d5
9 changed files with 138 additions and 15 deletions

View File

@@ -5,8 +5,32 @@ let g:loaded_node_provider = 1
let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')}
" Support for --inspect-brk requires node 6.12+ or 7.6+ or 8+
" Return 1 if it is supported
" Return 0 otherwise
function! provider#node#can_inspect()
if !executable('node')
return 0
endif
let node_v = get(split(system(['node', '-v']), "\n"), 0, '')
if v:shell_error || node_v[0] !=# 'v'
return 0
endif
" [major, minor, patch]
let node_v = split(node_v[1:], '\.')
return len(node_v) == 3 && (
\ (node_v[0] > 7) ||
\ (node_v[0] == 7 && node_v[1] >= 6) ||
\ (node_v[0] == 6 && node_v[1] >= 12)
\ )
endfunction
function! provider#node#Detect() abort
return has('win32') ? exepath('neovim-node-host.cmd') : exepath('neovim-node-host')
let global_modules = get(split(system('npm root -g'), "\n"), 0, '')
if v:shell_error || !isdirectory(global_modules)
return ''
endif
return glob(global_modules . '/neovim/bin/cli.js')
endfunction
function! provider#node#Prog()
@@ -19,18 +43,14 @@ function! provider#node#Require(host) abort
return
endif
if has('win32')
let args = provider#node#Prog()
else
let args = ['node']
let args = ['node']
if !empty($NVIM_NODE_HOST_DEBUG)
call add(args, '--inspect-brk')
endif
call add(args , provider#node#Prog())
if !empty($NVIM_NODE_HOST_DEBUG) && provider#node#can_inspect()
call add(args, '--inspect-brk')
endif
call add(args, provider#node#Prog())
try
let channel_id = jobstart(args, s:job_opts)
if rpcrequest(channel_id, 'poll') ==# 'ok'