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

Use npm to install a specific npm version #160

Closed
cubiclelord opened this issue Aug 14, 2015 · 8 comments
Closed

Use npm to install a specific npm version #160

cubiclelord opened this issue Aug 14, 2015 · 8 comments
Labels
bug Something isn't working

Comments

@cubiclelord
Copy link

Hey all,

I recently downloaded the nodejs module and I think it's really well done. I have run into a small feature request though. I'm using Ubuntu and the NodeSource packages, which (I believe) puts the npm binary in the same package as nodejs, instead of having 2 separate packages like the base Ubuntu packages.

I would like to be able to use npm to upgrade npm to a specific version. When I set $npm_package_ensure to be a specific version it errors out though because it's trying to install that version via the default provider instead of via the npm provider.

I'd love to add another variable that would allow you to override the provider for npm (something like $npm_provider). Are there any downsides to doing this? Is there a better way to get a specific version of npm using npm? I'd love any feedback that the community would like to share.

Thanx!

@nibalizer
Copy link
Member

Can you try:

nodejs::npm { 'npm':
   ensure   => 'version',
   provider => npm,
}

@cubiclelord
Copy link
Author

Looks like that errors out: Error 400 on SERVER: Invalid parameter provider on Nodejs::Npm[npm]

Looking at the nodejs::npm defined type shows that there isn't a provider parameter.

I tried this also:

  nodejs::npm { 'npm':
    ensure => '2.13.4',
    target => '/usr/bin',
  }

But that also dies, trying to install npm from the default package manager, instead of from npm.

@nibalizer
Copy link
Member

Oh right maybe:

package { 'npm':
  ensure => '2.13.4',
  provider => npm,
}

@cubiclelord
Copy link
Author

That's what I tried at first, but I got a duplicate resource error because Package[npm] is already defined in install.pp on line 49. Now that I look at it again, maybe I can set $nodejs::npm_package_name to undef and then that whole package section won't be in affect.

@cubiclelord
Copy link
Author

Hmm, I tried this, but I still got Duplicate Declaration: Package[npm] is already declared

class profile::appserver::nodejstools {
  class { 'nodejs':
    # Other nodejs values are set in hiera, but undef can't be set in hiera
    npm_package_name => undef,
  }

  package { 'npm':
    ensure   => '2.13.4',
    provider => 'npm',
  }
}

@nibalizer
Copy link
Member

That makes sense. This is a legitimate deficiency in the software, and one that affects me as well.

@juniorsysadmin juniorsysadmin added the bug Something isn't working label Nov 16, 2015
@petems
Copy link
Member

petems commented Dec 2, 2015

This would only be achievable in Puppet > 4 😢
(See https://tickets.puppetlabs.com/browse/PUP-1073 for the full story)

In Puppet > 4:

class profile::appserver::nodejstools {
  include nodejs

  package { "npm-installed-with-npm":
    name     => "npm",
    provider => "npm",
    ensure   => "2.13.4",
    require   => Class['nodejs'],
  }

}

@gytisgreitai
Copy link

any updates on this?

My current workaround:

    exec { 'upgrade npm to v3:
        command => 'sudo env "PATH=$PATH" npm install npm -g',
        onlyif  => "test `npm -v | awk -F \. {'print $1'}` -lt 3",
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants