33set  -eo pipefail
44
55function  nodejs_register_packages()  {
6-   if  !  vvv_src_list_has " nodesource" ;  then 
7-     cp -f " /srv/provision/core/nodejs/sources.list"   " /etc/apt/sources.list.d/vvv-nodejs-sources.list" 
8-   fi 
6+   cp -f " /srv/provision/core/nodejs/sources.list"   " /etc/apt/sources.list.d/vvv-nodejs-sources.list" 
97
108  if  !  vvv_apt_keys_has ' NodeSource' ;  then 
119    #  Retrieve the NodeJS signing key from nodesource.com
@@ -21,21 +19,28 @@ function nodejs_register_packages() {
2119}
2220vvv_add_hook before_packages nodejs_register_packages
2321
22+ function  reinstall_node()  {
23+   vvv_info "  * Purging NodeJS package." 
24+   apt-get purge nodejs -y
25+   vvv_info "  * Cleaning apt." 
26+   apt-get clean -y
27+   vvv_info "  * Apt autoremove." 
28+   apt-get autoremove -y
29+   vvv_info "  * Installing Node 14 LTS." 
30+   apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew install --fix-missing --fix-broken nodejs
31+   vvv_success "  ✓ Reinstalled Node, if you need another version use the nvm utility" 
32+ }
33+ 
2434function  node_setup()  {
25-   if  [[ $( nodejs -v |  sed -ne ' s/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p' )   !=  ' 10'   ]];  then 
26-     vvv_info "  * Downgrading to Node v10." 
27-     apt remove nodejs -y
28-     apt install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confnew install --fix-missing --fix-broken nodejs
35+   if  [[ $( nodejs -v |  sed -ne ' s/[^0-9]*\(\([0-9]\.\)\{0,4\}[0-9][^.]\).*/\1/p' )   !=  ' 14'   ]];  then 
36+     vvv_info "  * Migrating to Node v14." 
37+     reinstall_node
38+   fi 
39+   if  [[ !  -f  " /usr/bin/npm"   ]];  then 
40+     vvv_warn "  ! npm is missing in /usr/bin, reinstalling Node" 
41+     reinstall_node
2942  fi 
30- 
31-   #  npm
32-   # 
33-   #  Make sure we have the latest npm version and the update checker module
34-   vvv_info "  * Installing/updating npm..." 
35-   npm_config_loglevel=error npm install -g npm
36-   vvv_info "  * Installing/updating npm-check-updates..." 
37-   npm_config_loglevel=error npm install -g npm-check-updates
3843}
3944export  -f node_setup
4045
41- vvv_add_hook after_packages node_setup
46+ vvv_add_hook after_packages node_setup
0 commit comments