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

Post install hook #1342

Closed
wants to merge 1 commit into from
Closed

Conversation

roberttod
Copy link

@roberttod roberttod commented Dec 5, 2016

  • NVM_POST_INSTALL env variable is executed after nvm install if it is set
  • A fairly unopinionated change that would be a nice way to allow global node modules to be installed after a new node version is installed, as discussed in Autotomatic reinstall-packages across node versions #977

Using the hook install global npm modules

Just add the NVM_POST_INSTALL variable to .bash_profile, installing global modules that are used frequently.

export NVM_DIR="$HOME/.nvm"
export NVM_POST_INSTALL="npm install -g serve webpack standard"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

@roberttod
Copy link
Author

roberttod commented Dec 5, 2016

If this is likely to be accepted I can add it to the readme, showing how to use it to install global node modules.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the exploratory PR.

I'm not yet decided on whether it's better to allow a generic hook - or whether it's better to just allow a default --reinstall-packages-from (via an env var).

@@ -2464,6 +2464,10 @@ nvm() {
&& [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
nvm reinstall-packages "$REINSTALL_PACKAGES_FROM"
fi
if [ ! -z "${NVM_POST_INSTALL-}" ]; then
nvm_echo 'Running post install hook.'
$NVM_POST_INSTALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should probably run in a subshell so that it can't interfere with nvm's operation

- NVM_POST_INSTALL env variable is executed after `nvm install` if it is set
@roberttod
Copy link
Author

I find the --reinstall-packages-from option pretty useful but from what I have seen, developers seem to have a bunch of global modules they use all the time and then a few that have been installed for a particular task or project that aren't really used very often.

I think having a specified set of global modules is nice and would prevent every node version having global modules you don't really use that often.

If there was a default --reinstall-packages-from I would setup an install specifically to contain my common global modules, then switch to that node version using nvm use to add or remove global modules that would be installed when I nvm install. That seems a little more complicated though.

@ljharb
Copy link
Member

ljharb commented Dec 6, 2016

It certainly would be more complicated for your use case - but most importantly, it would be less rife for abuse than a generic hook :-/ I'll think on it more.

@ljharb ljharb added feature requests I want a new feature in nvm! needs followup We need some info or action from whoever filed this issue/PR. labels Dec 6, 2016
@ljharb ljharb self-assigned this Dec 6, 2016
@augbog
Copy link

augbog commented Mar 23, 2017

@ljharb just wondering if there were any more thoughts on this? Personally feel like its a useful feature

@ljharb
Copy link
Member

ljharb commented Mar 24, 2017

I'm still concerned with the potential for abuse, compared with the low-cost current requirement to do nvm install X && $POST_INSTALL_COMMAND manually.

@roberttod
Copy link
Author

The post install allows us to setup installing global modules pretty easily though, without much thought. It would be useful to do it that way rather than remembering to do it after every install.

@ljharb
Copy link
Member

ljharb commented Mar 25, 2017

Once your global packages are set up once, nvm install X --reinstall-packages-from=Y covers it all in one go tho.

@ljharb
Copy link
Member

ljharb commented Apr 26, 2017

@roberttod it seems like #1463 might cover your use case a bit better?

@roberttod roberttod closed this Apr 26, 2017
@roberttod roberttod deleted the post-install-hook branch April 26, 2017 12:59
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! needs followup We need some info or action from whoever filed this issue/PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants