Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Enhancement: support to actually install any version npm we need
Browse files Browse the repository at this point in the history
  • Loading branch information
till committed Apr 30, 2015
1 parent 349422a commit d606ee9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nodejs/recipes/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
include_recipe 'nodejs::install'
when 'source'
include_recipe 'nodejs::npm_from_source'
when 'from_latest'
include_recipe 'nodejs::npm_from_latest'
else
Chef::Log.error('No install method found for npm')
end
35 changes: 35 additions & 0 deletions nodejs/recipes/npm_from_latest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
npm_bin = '/usr/bin/npm'

local_latest = "#{Chef::Config[:file_cache_path]}/install-npm.sh"

npm_version = node['nodejs']['npm']['version']

is_correct_version = ->(version) {
`npm -v`.strip! == version
}

remote_file local_latest do
source 'https://www.npmjs.org/install.sh'
mode '0755'
not_if do
File.exist?(local_latest) || is_correct_version[npm_version]
end
end

package "curl" do
action :install
only_if do
File.exist?(local_latest)
end
end

execute 'Install npm' do
command local_latest
environment({
'clean' => 'no',
'npm_install' => npm_version
})
not_if do
is_correct_version[npm_version]
end
end

0 comments on commit d606ee9

Please sign in to comment.