-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4c507e
commit 4ea4d0a
Showing
6 changed files
with
154 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# nodejs tool Layer | ||
|
||
## Table of Contents | ||
|
||
<!-- vim-markdown-toc GFM --> | ||
* [Description](#description) | ||
* [Install](#install) | ||
* [Building](#building) | ||
* [MS Windows](#ms-windows) | ||
|
||
<!-- vim-markdown-toc --> | ||
|
||
## Description | ||
|
||
Folowing the zero-install philosophy, this layer adds the Node.js tool, built from source if needed. | ||
|
||
If `node` is found on $PATH, or $NODE points to `node`, and either is of sufficient version, that will be used instead of building from source. | ||
|
||
The curated node will be added to `$PATH` for use by other plugins and language servers. Including yarn/npm which language servers may use to download dependencies. | ||
|
||
## Install | ||
|
||
To use this layer, add it to your `~/.spacevim`. | ||
|
||
### Building | ||
|
||
On building from source, around 200MiB is installed into the prefix `./install` relative to the plugin directory. The building process requires around 4GiB, which will be deleted on completion. | ||
|
||
If the automated building doesn't work, you may navigate to the plugin directory and build manually, into the prefix `./install`; installing system-wide isn't required. Or install prebuilt binaries and set $PATH or $NODE accordingly. | ||
|
||
#### MS Windows | ||
|
||
You have two ABI choices: GNU and MSVC (comes with Visual Studio Tools). Your choice depends on the C/C++ libraries you want to interoperate with. | ||
|
||
Automated building from source isn't tested. However it should work in Cygwin or with the environmental variables as defined by `msys2_shell.cmd` or `vcvars64.bat` per the desired ABI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim' | ||
|
||
let location = spacevim#vim#plug#LocateDependency('node') | ||
if location[0] ==# 'none' | ||
call spacevim#util#warn('nodejs layer failure, try ":call dein#get('. | ||
\ '"node").hook_post_update()" to build as plugin, or set $NODE/'. | ||
\ '$PATH to existing build, or install system-wide with version >= '. | ||
\ join(g:spacevim#vim#plug#native_dependency['node'].v_req, '.').'.') | ||
else | ||
" Don't install devDependencies on `npm install` | ||
let $NODE_ENV = 'production' | ||
let f = expand(g:spacevim.state_base.'/node_npm_configured_v'.location[1][0].'.'.location[1][1]) | ||
if location[0] ==# 'plugin' && !filereadable(f) | ||
" npm install packages into {prefix}/lib/node_modules | ||
call system('npm config set location global') | ||
" node-gpy needs to know where headers are | ||
call system('npm config set nodedir '.fnamemodify(location[2], ':h')) | ||
call writefile([], f, 'S') | ||
endif | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function! Build(native) abort | ||
if !a:native.posix_compiler | ||
" vcbuild appears to not have '--prefix' equivalent but can improvise | ||
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '. | ||
\ '-pos=tab -post='. | ||
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '. | ||
\ '.\\vcbuild openssl-no-asm') | ||
else | ||
let configure_log = a:native.temppath.'/nodejs_configure.log' | ||
call system(a:native.plugpath.'/configure --prefix='. | ||
\ a:native.plugpath.'/install'.a:native.ninja_flag.' > '. | ||
\ configure_log) | ||
call rename(configure_log, a:native.plugpath.'/configure.log') | ||
call execute('AsyncRun -cwd='.a:native.plugpath.'/build -mode=term '. | ||
\ '-pos=tab -program=make -post='. | ||
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''node'') @ '. | ||
\ 'install'.a:native.jobs_flag) | ||
endif | ||
endfunction | ||
|
||
function! PostBuild(native) abort | ||
call delete('config.gypi') | ||
call delete('config.mk') | ||
call delete('config.status') | ||
call delete('icu_config.gypi') | ||
call delete('deps', 'rf') | ||
call delete('node') | ||
call delete('__pycache__', 'rf') | ||
call delete('tools', 'rf') | ||
|
||
execute 'tcd' a:native.binpath | ||
call system('node corepack enable') | ||
endfunction | ||
|
||
let g:spacevim#vim#plug#native_dependency = get(g:, 'spacevim#vim#plug#native_dependency', {}) | ||
let g:spacevim#vim#plug#native_dependency['node'] = { | ||
\ 'bin': 'node', | ||
\ 'override': '$NODE', | ||
\ 'repo': 'nodejs/node', | ||
\ 'vregex': '\Vv\(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)', | ||
\ 'v_req': [16, 10, 0], | ||
\ 'Build': function('Build'), | ||
\ 'PostBuild': function('PostBuild'), | ||
\ } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim' | ||
|
||
" v >= 16.10 is required for corepack | ||
" v < 17 required for tree-sitter | ||
" https://github.com/tree-sitter/node-tree-sitter/issues/102 | ||
if spacevim#vim#plug#LocateDependency('node')[0] ==# 'none' | ||
MP 'nodejs/node', { 'merged': v:false, 'rtp': '', | ||
\ 'rev': 'v16.16.0', | ||
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['node']) } | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters