'nvs exec' loops forever upon error when giving arguments
I'm setting up a build chain that uses NVS for choosing Nodejs version, but without "installing" it in ~/.nvs (mostly for continuous integration).
Roughly, the wrapper script uses nvs add $NODE_VERSION and nvs exec $NODE_VERSION npm run build (and other steps). However, when the npm run build fails, nvs tries to run it again, and again. Forever. This happens with and without ~/.nvs installation (i.e. on CI and on developer machines). I've reproduced with node 12.11.1 and 13.0.1, with NVS 1.5.3 and 1.5.4.
This can be reproduced with the following script:
#!/bin/bash
DIR=$(cd $(dirname $0) && pwd)
NVS_FODLER=${DIR}/.nvs/
NVS_VERSION=1.5.4
NODE_VERSION=13.0.1
command -v nvs > /dev/null
# if not, init env
if [ $? != 0 ]; then
[ ! -d "${NVS_FODLER}" ] && \
git clone --branch v$NVS_VERSION --depth 1 https://github.com/jasongin/nvs "${NVS_FODLER}"
. "${NVS_FODLER}"/nvs.sh ""
fi
NODE_VERSION_AVAILABLE=$(nvs ls ${NODE_VERSION} | grep 'node/12.11.1' | wc -l)
[ ${NODE_VERSION_AVAILABLE} == 0 ] && nvs add ${NODE_VERSION}
(nvs exec ${NODE_VERSION} ls nonExistingFolder) && echo SUCCESS || (echo ERROR && exit 1)
Also, you can replace the nvs exec ${NODE_VERSION} ls nonExistingFolder with nvs exec ${NODE_VERSION} false to observe the proper behavior when there is no argument given.
I have this behaviour on windows, too. For me the problem is in vscode with a launch configuration which uses nvs exec 20 to launch my test. The command executed is nvs exec 20 npm run test. I debugged the nvs.ps1 script and found that the actual node lib\index.js call to run the javascript part of nvs, returns with exit code 2. Apparently this is used to say that the node bootstrap version is wrong, which it isn't in my case.
I suppose the problem is, that the mocha test runner fails with exit code 2 if there are tests that don't pass. Cause if all my tests pass, it doesn't loop. But if my test fails, it loops due to exiting with code 2.
I currently don't have any idea how to resolve this.
Some more investigation showed that mocha seems to return the number of failed tests.
To solve my issue, I modified the test script in my package.json to something like mocha || exit 1. So in case mocha fails, it returns 1 regardless of the number of tests that failed.
But it seems to me that bootstrapping is flawed in case of nvs exec.