Closed alanhogan closed 5 years ago
I am probably going to proceed with if [ command -v __avn_debug ]
as my test. This should succeed whenever avn has been successfully loaded into the shell.
There are numerous things you could do, but this feels like it's outside the scope of concern for the project. There are too many variables at play. Which shell does everyone have? Is which
a built in or a program? This is a problem that's present in other contexts as well (i.e. in build/configure systems). Usually, it's more important to test that a program actually functions than it is to ensure it's installed. In this case, you'd likely have to load your while shell environment first.
Regardless, there's no issue here and you already found something that it sounds like may work, so I'm going to close this.
Why not actually cd into two different directories that declare different node versions and see if the node version changes?
In other words, feature test instead of user agent sniff.
@ljharb Because that's slow and my goal is not to write a test suite for avn but rather to see if it is installed.
My team maintains a script that is designed to ensure a developer's environment is fully prepared to develop on our project.
Part of this is detecting
avn
and installing it if messing.We used to do this like this:
However at least in some cases,
avn
will be fully functional, switching node versions oncd
as designed, butwhich avn
will fail to findavn
.For example, this is happening on my machine. The default
node
is v5.10.1 andavn
is installed globally with that node version. However avn is "missing" after avn itself switched to our project's node version of 8.9.x.Is there a recommended way to test for the presence of avn?
Details
avn --version
0.2.4node --version
5.10.1, 8.9.3nvm --version
0.33.4n --version
nonezsh --version
5.3bash --version
n/aThe output of
__avn_debug
in the directory with a.node-version
file is:avn
is loaded in my~/.{bash|zsh}{_profile|rc}
file with:nvm specific
nvm
user I am confirming that I did not install with Homebrew