wbyoung / avn

Automatic Version Switching for Node
MIT License
1.14k stars 54 forks source link

When switching directories, first compare current and target Node version before proceeding, and abort AVN activation if they are the same #78

Open chaddjohnson opened 6 years ago

chaddjohnson commented 6 years ago

Thanks for the great free software.

My project uses multiple different repositories, and each has their own individual directory locally. When I change to one directory, avn sets up the version of node per the .node-version file in the target directory. This is desirable.

However, when I change to another directory which contains another .node-version file having exactly the same contents, avn once again goes through the setup process.

I suggest that when changing directories and switching node versions, avn should, before proceeding with anything else, compare the current and target versions of Node, and if they are the same, then abort the setup process rather than forcing the user to wait a few seconds.

Here is some sample output:

hyperion:project chad$ cd api
avn activated 8.6.0 (avn-nvm v8.6.0)
hyperion:api chad$ cd ../app
avn activated 8.6.0 (avn-nvm v8.6.0)
hyperion:app chad$ cd ../admin
avn activated 8.6.0 (avn-nvm v8.6.0)
hyperion:admin chad$ 

As you can see, Node 8.6.0 was unnecessarily activated multiple times.

Details

The output of __avn_debug in the directory with a .node-version file is:

avn activated 8.6.0 (avn-nvm v8.6.0)
nvm use v8.6.0 > /dev/null;

avn is loaded in my ~/.{bash|zsh}{_profile|rc} file with:

[[ -s "$HOME/.avn/bin/avn.sh" ]] && source "$HOME/.avn/bin/avn.sh" # load avn

nvm specific

rfgamaral commented 4 years ago

Came here to support this issue because I just noticed this happening on my machine. It's a bit pointless to try to activate a version that it's currently in use. In my particular machine takes a few seconds to switch, which is cumbersome when the versions are the same and there's not need for switching.

wufeihuang commented 4 years ago

I'm confused about it too. Version switching takes quite a few seconds on my computer.

wbyoung commented 4 years ago

I thought I commented on this before, but the version matching doesn't necessarily mean that the path (and hence the global modules, compilation flags, etc) are the best match. For consistency, it should perform a full check each time.

Speeding up the execution of the command is welcome, but also consider how fast the underlying tool is (n or nvm) and what improvements can be made there.

wufeihuang commented 4 years ago

Sorry, I don't get it what bad would happen when aborting the version switching, if the current Node version exactly matches the .node-version declaration.

wbyoung commented 4 years ago

You could have the exact same version installed with both n and nvm. Which one should be used then? The choice changes which global modules will be used.

wufeihuang commented 4 years ago

Uhm...I didn't think about such a situation of using both n and nvm. Thanks for explaining.