Install the latest nodejs from source

This commit is contained in:
Greg Karékinian
2017-01-20 03:48:01 +00:00
parent b431e75e79
commit 671a2c4421
25 changed files with 882 additions and 141 deletions

View File

@@ -1,4 +1,6 @@
if defined?(ChefSpec)
ChefSpec.define_matcher :nodejs_npm
def install_nodejs_npm(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:nodejs_npm, :install, resource_name)
end

View File

@@ -7,7 +7,7 @@ module NodeJs
require 'open-uri'
require 'json'
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, :max_nesting => false)
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{node['nodejs']['npm']['version']}").read, max_nesting: false)
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
Chef::Log.debug("Npm dist #{ret}")
return ret
@@ -16,13 +16,13 @@ module NodeJs
def npm_list(path = nil, environment = {})
require 'json'
if path
cmd = Mixlib::ShellOut.new('npm list -json', :cwd => path, :environment => environment)
else
cmd = Mixlib::ShellOut.new('npm list -global -json', :environment => environment)
end
cmd = if path
Mixlib::ShellOut.new('npm list -json', cwd: path, environment: environment)
else
Mixlib::ShellOut.new('npm list -global -json', environment: environment)
end
JSON.parse(cmd.run_command.stdout, :max_nesting => false)
JSON.parse(cmd.run_command.stdout, max_nesting: false)
end
def url_valid?(list, package)
@@ -38,7 +38,7 @@ module NodeJs
list = npm_list(path, environment)['dependencies']
# Return true if package installed and installed to good version
(!list.nil?) && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package)
!list.nil? && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package)
end
end
end