wbyoung / avn

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

How can a version manager FOR node work if it is written IN node? #21

Closed macgyver closed 9 years ago

macgyver commented 9 years ago

Do I need to install avn in every single node environment on my system, and then remember to keep them all up to date?

wbyoung commented 9 years ago

@macgyver no. avn installs itself in ~/.avn and adds a startup script to your shell's init script, usually ~/.bash_profile that sources a shell script. When you cd to a directory, a small shell script shim will check to see if there's a .node_version or .nvmrc file in the current directory & kick off a node process that does some work to figure out how to activate the right version of node via the right version manager. This info is transferred back to that shell script that then executes the proper commands.

So it's really written more in shell scripting with a utility library written in node.

macgyver commented 9 years ago

how does the shell script know which environment the node process has been installed in? For example, say I'm using nvm to switch between environments, and I switch away from the node environment where I've installed avn. If I cd to a directory with a .nvmrc, will the node process run in the version where avn exists, or in the one I've switched to using nvm?

wbyoung commented 9 years ago

It will use the node that was available before the switch. When using nvm or n, this is usually activated during your shell's initialization script.

The details of the implementation & what version of node it uses don't change whether or not it's capable of switching versions for you. If the design choices are bad, they can be replaced in a future version of avn & users wouldn't notice any difference.