-
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
953d9ba
commit 64f18d0
Showing
7 changed files
with
204 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
" Will do the following checks in order of precedence: | ||
" -Use $NODE or $NODE/node if they exist and are executable | ||
" -check for node as vim-plug plugin (user-specific) | ||
" -check for system-wide install of node | ||
" -If all above fail will get node as vim-plug plugin and build it | ||
" Changes $PATH to include node path | ||
function! spacevim#plug#nodejs#IsBuildRequired(maj, min) | ||
let pathsep = g:spacevim.os.windows ? ';' : ':' | ||
" Prefer $NODE override | ||
if exists('$NODE') && spacevim#util#IsVersionSufficient('$NODE', a:maj, a:min) | ||
let $PATH = fnamemodify('$NODE', ':h').pathsep.$PATH | ||
return 0 | ||
endif | ||
" Prefer user plugin Node.js if it exists | ||
if spacevim#util#IsVersionSufficient(g:plug_home.'/node/node', a:maj, a:min) | ||
let $PATH = g:plug_home.'/node'.pathsep.$PATH | ||
return 0 | ||
endif | ||
" Last check for system-wide Node.js | ||
if spacevim#util#IsVersionSufficient('node', a:maj, a:min) | ||
return 0 | ||
endif | ||
return 1 | ||
endfunction | ||
|
||
" If no valid $NODE or systemwide node.js: build node.js dependency | ||
function! spacevim#plug#nodejs#Build(info) | ||
if !spacevim#load('programming') | ||
echom "nodejs layer requires the 'programming' layer to build. Add 'programming' layer to init.spacevim" | ||
return | ||
endif | ||
if g:spacevim.os.windows | ||
echom 'Building Node.js automatically on Windows is untested and likely to fail' | ||
echom 'Run msys2_shell.cmd or vcvars64.bat per desired ABI' | ||
return | ||
elseif (!exists('$CC') && executable('gcc') != 1) || | ||
\ executable('make') != 1 || executable('python3') != 1 | ||
echom 'Unable to build Node.js, requires a C++ compiler, make, and python3' | ||
return | ||
endif | ||
|
||
echom 'Building Node.js, please wait 60+ seconds for build to start...' | ||
let s:cwd = getcwd() | ||
|
||
if get(g:, 'spacevim.build_deps_in_tmp', 1) && getftype('out') !~# 'dir' | ||
" Build intermediate files to temp, vim will delete folder on exit | ||
let temp_dir = fnamemodify(tempname(), ':p:h') | ||
call mkdir(temp_dir.'/out', 'p') | ||
if getftype('out') =~# 'link' | ||
call system('rm out') | ||
endif | ||
call system('ln -s '.temp_dir.'/out out') | ||
endif | ||
|
||
let s:jobs_flag = '' | ||
if g:spacevim.os.windows | ||
autocmd User asyncrun.vim ++once execute('AsyncRun -mode=term -pos=tab @ .\\vcbuild openssl-no-asm') | ||
else | ||
let ninja_flag = '' | ||
if executable('ninja') | ||
let ninja_flag=' --ninja' | ||
else | ||
" Determine number of cores/threads for make -j, ninja autodetects | ||
let num_threads = 4 | ||
if executable('lscpu') | ||
let result = system("lscpu | grep -E '?^(CPU\\(s\\):|Thread\\(s\\) per core:)' | tr -s ' ' | cut -f 2 -d:") | ||
if !v:shell_error | ||
let num_threads = join(split(result), '*') | ||
endif | ||
endif | ||
let s:jobs_flag = ' -j '.num_threads | ||
endif | ||
call system('./configure'.ninja_flag.' > '.temp_dir.'/nodejs_configure.log') | ||
autocmd User asyncrun.vim ++once execute( | ||
\ 'AsyncRun -cwd='.s:cwd.' -mode=term -pos=tab -program=make -post=call\ spacevim\#plug\#nodejs\#PostBuild(code) @'.s:jobs_flag) | ||
endif | ||
call timer_start(60000, { -> plug#load('asyncrun.vim') }) | ||
endfunction | ||
|
||
function! spacevim#plug#nodejs#PostBuild(exit_code) | ||
execute 'tcd' fnameescape(s:cwd) | ||
unlet s:cwd s:jobs_flag | ||
if a:exit_code == 0 | ||
call system('rm -r deps/icu-tmp node') | ||
call rename('out/Release/node', 'node') | ||
let pathsep = g:spacevim.os.windows ? ';' : ':' | ||
let $PATH = g:plug_home.'/node'.pathsep.$PATH | ||
|
||
" This sets up corepack/npm links the same as `make install` does | ||
call system('ln -s deps/corepack/dist/corepack.js corepack') | ||
call system('ln -s deps/npm/bin/npm-cli.js npm') | ||
call system('ln -s deps/npm/bin/npx-cli.js npx') | ||
call system('node corepack enable') | ||
endif | ||
if get(g:, 'spacevim.build_deps_in_tmp', 1) | ||
call system('rm out') | ||
endif | ||
tcd - | ||
endfunction | ||
|
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
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,43 @@ | ||
# nodejs tool Layer | ||
|
||
## Table of Contents | ||
|
||
<!-- vim-markdown-toc GFM --> | ||
* [Description](#description) | ||
* [Install](#install) | ||
* [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. | ||
|
||
Node.js built with the repo requires 1.2 GiB space. Intermediate files are deleted after build. | ||
|
||
The curated node will be added to `$PATH` for use by other plugins. Also includes yarn/npm, useful for other plugins (such as language servers) to install dependencies. | ||
|
||
## Install | ||
|
||
To use this layer, add it to your `~/.spacevim` as follows: | ||
|
||
``` | ||
let g:spacevim_layers = [ | ||
\ 'programming', 'nodejs', | ||
\ ] | ||
``` | ||
|
||
Under appropriate conditions the plugin manager will clone and build the repository in a Vim tab. | ||
|
||
To speed up the build and conserve disk space, the repository will be built in a temp directory which will be cleared on Vim exit. See `:help tempfile`. Set `g:spacevim.build_deps_in_tmp = 0` to disable this optimization. | ||
|
||
### MS Windows | ||
|
||
You have two ABI choices: MSVC (comes with Visual Studio Tools) and GNU. Your choice depends on on C/C++ libraries you want to interoperate with. | ||
|
||
Automated building from source isn't tested. However it should use the environmental variables as defined by `msys2_shell.cmd` or `vcvars64.bat` should you run that prior to launching `vim`. | ||
|
||
Alternatively, navigate to the plugin directory and build manually. Installing system-wide isn't required, it may be used in-place. Or install prebuilt binaries and set $PATH or $NODE accordingly. |
Empty file.
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,3 @@ | ||
if spacevim#plug#nodejs#IsBuildRequired(16, 10) | ||
MP 'nodejs/node', { 'do': function('spacevim#plug#nodejs#Build') } | ||
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