wbyoung / avn

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

avn-nvm aliases #43

Open hiendv opened 8 years ago

hiendv commented 8 years ago

Details

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

avn could not activate node default
error: no plugin passed predicate
  avn-nvm: no version matching default

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

hiendv commented 8 years ago

.nvmrc

default
wbyoung commented 8 years ago

@hiendv yes, we should do one of two things:

The idea behind nvm is to establish a per project-based version of node, so I'm actually leaning more toward the idea of ignoring it. But it'll still require some changes to ignore, and should certainly be done so that a ~/.nvmrc w/ an alias doesn't cause avn to freak out.

hiendv commented 8 years ago

From my point of view, avn and nvm match perfectly. One makes project-based versioning possible, the other makes the whole process automatically. So why ignoring it, @wbyoung ? Anyway, there's no need for avn to care about nvm aliases but avn-nvm should, imo. Thank you for considering this.

ljharb commented 8 years ago

.nvmrc is not just per-project - ~/.nvmrc and /.nvmrc, etc, are all valid use cases.

wbyoung commented 8 years ago

@ljharb right, which is why I don't want to do anything silly if we read those files (which we do during directory traversal). avn, though, was created with the intention of being per-proejct and expanded to handle .nvmrc files.

ljharb commented 8 years ago

what denotes a project root in avn?

wbyoung commented 8 years ago

@ljharb previously a .node-version file, but after https://github.com/wbyoung/avn/issues/17 was addressed, it's really either an .nvmrc or .node-version file. I understand that this isn't perfect and that it also doesn't really fit well the same things that the .nvmrc file is trying to accomplish.

This same line of thinking has been previously discussed.

And I think it's worth noting that #17 was implemented to avoid duplication between two different files.

I'm still thinking that ignoring aliases in .nvmrc files w/ aliases seems like an appropriate course of action. It basically says, you can use .nvmrc as a replacement to .node-version, but only if you're using it as a .node-version style file that doesn't support aliases.

ljharb commented 8 years ago

I don't think that's good at all. If you're going to support .nvmrc, support it - otherwise, please don't. I don't want a slew of bug reports because .nvmrc only half-works in avn.

ljharb commented 8 years ago

Also please note that LTS support is coming to .nvmrc shortly, and there's very little purpose in putting a full version number in that file. The common use cases are going to be node, lts/*, lts/argon, etc.

wbyoung commented 8 years ago

@ljharb okay, we'll try to support it.

Also, if there's little point in putting a version number in that file, the docs should probably be updated when you do support that so your example is more in line with how things should be used in the majority use case.

A quick question about how to get things accomplished on this side:

ljharb commented 8 years ago

@wbyoung nvm version "${NVM_RC_CONTENTS}" should do it

wbyoung commented 8 years ago

@ljharb thanks.

To support this, we'll need to update avn-nvm which receives the version in the match function and either use the command listed above to convert to a real version before searching installed versions or just treat it specially if it doesn't look like an installed version, skipping the search entirely.

Note that we still want to allow search of installed versions when it's a version number because if it comes from a .node-version file, we want the best option between installed avn plugins.

PR welcome!

ljharb commented 8 years ago

nvm version already searches nvm-installed versions for you, fwiw.

duckontheweb commented 6 years ago

@ljharb @wbyoung If no one is currently working on a PR for this I'm happy to put one together.

wbyoung commented 6 years ago

@duckontheweb please do!

duckontheweb commented 6 years ago

I have tests and working support for aliases written on a fork of avn-nvm. Support for the system alias in an .nvmrc file is going to take a bit more work since nvm version system resolves to system. I think I could use nvm unload and then which node and node --version to grab the system version if the version resolves to system after the other checks.

ljharb commented 6 years ago

@duckontheweb nvm run system --version?

duckontheweb commented 6 years ago

@ljharb I ended up going with nvm use system > /dev/null && node --version because nvm run system --version gave a line of output before echoing the version number and it made things easier to parse. Would there be any advantage to using nvm run system --version over this approach?

ljharb commented 6 years ago

@duckontheweb you can use nvm run --silent system --version, or nvm exec --silent system node --version; the advantage is that it's a single command.