Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

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

Open
1 task done
chaddjohnson opened this issue Jul 14, 2018 · 6 comments

Comments

@chaddjohnson
Copy link

chaddjohnson commented Jul 14, 2018

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

  • avn 0.2.3
  • node 8.6.0
  • nvm 0.33.8
  • zsh zsh 5.3 (x86_64-apple-darwin17.0)
  • bash GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)

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

  • As an nvm user I am confirming that I did not install with Homebrew
@chaddjohnson chaddjohnson changed the title When switching directories, first compare current and target Node version before proceeding When switching directories, first compare current and target Node version before proceeding, and abort switching if they are the same Apr 9, 2019
@chaddjohnson chaddjohnson changed the title When switching directories, first compare current and target Node version before proceeding, and abort switching if they are the same When switching directories, first compare current and target Node version before proceeding, and abort AVN activation if they are the same Apr 9, 2019
@rfgamaral
Copy link

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
Copy link

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

@wbyoung
Copy link
Owner

wbyoung commented Jun 3, 2020

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
Copy link

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
Copy link
Owner

wbyoung commented Jun 4, 2020

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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants