Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run correct npm completion script #427

Open
callumacrae opened this issue May 26, 2014 · 20 comments
Open

Run correct npm completion script #427

callumacrae opened this issue May 26, 2014 · 20 comments
Labels
feature requests I want a new feature in nvm!

Comments

@callumacrae
Copy link

I have the following line in my .bash_profile:

source ~/.nvm/v0.10.28/lib/node_modules/npm/lib/utils/completion.sh

That seems kind of fragile. Is there a better way, or could a better way be written?

@ljharb
Copy link
Member

ljharb commented May 26, 2014

You could create an alias, and put the path to the alias in your bash_profile

@callumacrae
Copy link
Author

That's just another way of doing the same thing though, right? If I use a different version of node, I'm now using the wrong completion.sh.

@ljharb
Copy link
Member

ljharb commented May 26, 2014

Ah, i see what you're saying. You could do source ~/.nvm/node -v/lib/node_modules/npm/lib/utils/completion.sh which would adapt, but you're not going to re-source your bash profile every time you switch node versions. I'm not really sure what a proper solution is here.

@callumacrae
Copy link
Author

Would adding a line to nvm use do the trick?

Link for if I do it: https://github.com/creationix/nvm/blob/master/nvm.sh#L462

@ljharb
Copy link
Member

ljharb commented May 27, 2014

I don't think it's appropriate to handle shell completion inside nvm. I'd be open to a way to solve this, but I'm not sure what you have in mind to add to nvm.sh

@callumacrae
Copy link
Author

Either through an option (--autocompletion?) or possibly just by doing something like adding a hook (if $NVM_USE_RAN points to a file, run the file), which would let people do it themselves. Not sure about the second one, though.

@jasonkarns
Copy link

How big of an issue is this, since the npm completion script mostly just calls out to npm completion (which would then be using the nvm-managed npm)? Would anything be improved if nvm used proper shims? (#577)

@ljharb
Copy link
Member

ljharb commented Mar 4, 2015

The idea, I think, is using the nvm-managed npm whenever nvm switches node versions.

Shims don't actually end up improving anything, if Ruby's tools are any indication :-)

@wilmoore
Copy link

How big of an issue is this

This is really only an issue when switching between node versions that include wildly different npm versions.

This can be solved by simply using the latest version of npm always (regardless of the node version you are currently using).

I personally just do the following:

  • export PATH=$NPM_CONFIG_PREFIX/bin:$PATH
  • npm install npm@latest --global # this will install npm to $NPM_CONFIG_PREFIX/bin
  • source <(npm completion)

If you've installed the latest npm but get an older version when you npm --version, then you have a $PATH order issue since there are multiple npm programs installed. You can debug through this by typing which -a npm then use that to fix your $PATH ordering.

@ljharb
Copy link
Member

ljharb commented Mar 10, 2015

I don't have $NPM_CONFIG_PREFIX specified anywhere - where is this set for you?

I highly discourage anyone from installing anything outside an nvm version path. Each node/io.js should have its own copy of npm, and if they don't, I consider that an unsupported environment.

@wilmoore
Copy link

I don't have $NPM_CONFIG_PREFIX specified anywhere - where is this set for you?

$NPM_CONFIG_PREFIX is not set by default; but is honored by npm when set.

@ljharb
Copy link
Member

ljharb commented Mar 10, 2015

Just like in #606, that's the sort of thing that nvm will forcibly unset in the future - those kinds of settings are fundamentally incompatible with nvm.

@wilmoore
Copy link

that's the sort of thing that nvm will forcibly unset in the future

Seems like a fairly rude thing to do 😒 - What other modules should I be afraid nvm might intentionally break in the future?

@ljharb
Copy link
Member

ljharb commented Mar 10, 2015

I haven't committed to doing that - I may instead just make it so nvm refuses to work if any of those are set (which is less invasive). nvm doesn't break modules - but non-default config options for npm are rarely a good idea anyways, but most of those options were designed for a world where there's only one node installed, so it's just not reasonable to expect them to work in a multiple-node world.

@wilmoore
Copy link

I may instead just make it so nvm refuses to work if any of those are set (which is less invasive).

Well, that would indeed be less terrible.

@andihafner
Copy link

andihafner commented May 21, 2020

On my Ubuntu 20.04 box with nvm 0.35.3 installed, there exists the environment variable

NVM_BIN="/home/[username]/.nvm/versions/node/v12.16.3/bin"

Therefore, a

source $(echo $NVM_BIN)/../lib/node_modules/npm/lib/utils/completion.sh

does the trick version independent.

@gotofritz

This comment has been minimized.

@ljharb

This comment has been minimized.

@gotofritz

This comment has been minimized.

@ljharb

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm!
Projects
None yet
Development

No branches or pull requests

6 participants