Skip to content

Commit

Permalink
Add support for npm proxy configuration.
Browse files Browse the repository at this point in the history
Add npm proxy support and configuration of proxy prior to installing npm
packages. Without this support npm install <package> will error:

    npm ERR! Error: failed to fetch from registry: <package>
  • Loading branch information
nanliu committed Jun 6, 2012
1 parent 02ceb1b commit b7d48c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion manifests/init.pp
Expand Up @@ -9,7 +9,8 @@
# Usage:
#
class nodejs(
$dev_package = false
$dev_package = false,
$proxy = ''
) inherits nodejs::params {

case $::operatingsystem {
Expand Down Expand Up @@ -67,6 +68,14 @@
require => Anchor['nodejs::repo']
}

if $proxy {
exec { 'npm_proxy':
command => "npm config set proxy ${proxy}",
path => $::path,
require => Package['npm'],

This comment has been minimized.

Copy link
@Poplava

Poplava Jun 4, 2014

But if Ubuntu we can't require npm package...

}
}

if $dev_package and $nodejs::params::dev_pkg {
package { 'nodejs-dev':
name => $nodejs::params::dev_pkg,
Expand Down
3 changes: 3 additions & 0 deletions manifests/npm.pp
Expand Up @@ -43,6 +43,9 @@
path => $::path,
require => Class['nodejs'],
}

# Conditionally require npm_proxy only if resource exists.
Exec<| title=='npm_proxy' |> -> Exec["npm_install_${name}"]
} else {
exec { "npm_remove_${name}":
command => "npm remove ${npm_pkg}",
Expand Down
29 changes: 29 additions & 0 deletions spec/classes/nodejs_spec.rb
Expand Up @@ -33,13 +33,18 @@
}
end

let :params do
{ :dev_package => true, }
end

it { should contain_class('apt') }
it { should contain_apt__ppa('ppa:chris-lea/node.js') }
it { should contain_package('nodejs') }
it { should contain_package('nodejs').with({
'name' => 'nodejs',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_package('nodejs-dev') }
it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
Expand Down Expand Up @@ -76,5 +81,29 @@
it { should_not contain_package('nodejs-dev') }
end
end

describe 'when deploying with proxy' do
let :facts do
{
:operatingsystem => 'Ubuntu',
:lsbdistcodename => 'edgy',
}
end

let :params do
{ :proxy => 'http://proxy.puppetlabs.lan:80/' }
end

it { should contain_package('npm').with({
'name' => 'npm',
'require' => 'Anchor[nodejs::repo]',
}) }
it { should contain_exec('npm_proxy').with({
'command' => 'npm config set proxy http://proxy.puppetlabs.lan:80/',
'require' => 'Package[npm]',
}) }
it { should_not contain_package('nodejs-stable-release') }
end

end

0 comments on commit b7d48c9

Please sign in to comment.