Upgrade nodejs cookbook from 7.3 to 11.0
This commit is contained in:
@@ -1,19 +1,96 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module NodeJs
|
||||
module Helper
|
||||
def npm_dist
|
||||
if node['nodejs']['npm']['url']
|
||||
{ 'url' => node['nodejs']['npm']['url'] }
|
||||
def default_install_method
|
||||
case node['platform_family']
|
||||
when 'debian', 'rhel', 'fedora', 'amazon', 'mac_os_x', 'suse'
|
||||
'package'
|
||||
when 'windows'
|
||||
'chocolatey'
|
||||
else
|
||||
|
||||
require 'open-uri'
|
||||
require 'json'
|
||||
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}")
|
||||
ret
|
||||
'source'
|
||||
end
|
||||
end
|
||||
|
||||
def default_packages(install_repository)
|
||||
case node['platform_family']
|
||||
when 'debian'
|
||||
install_repository ? ['nodejs'] : %w(nodejs npm nodejs-dev)
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
install_repository ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-devel)
|
||||
when 'suse'
|
||||
%w(nodejs npm nodejs-devel)
|
||||
when 'mac_os_x'
|
||||
['node']
|
||||
else
|
||||
['nodejs']
|
||||
end
|
||||
end
|
||||
|
||||
def default_build_packages
|
||||
case node['platform_family']
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
%w(openssl-devel python3 tar)
|
||||
when 'debian'
|
||||
%w(libssl-dev python3)
|
||||
else
|
||||
%w(python3)
|
||||
end
|
||||
end
|
||||
|
||||
def dnf_python_package?(package_name)
|
||||
package_name == 'python3' && platform_family?('rhel', 'fedora', 'amazon')
|
||||
end
|
||||
|
||||
def default_make_threads
|
||||
node['cpu'] ? node['cpu']['total'].to_i : 2
|
||||
end
|
||||
|
||||
def node_major_from_version(version)
|
||||
version.to_s.split('.').first
|
||||
end
|
||||
|
||||
def nodejs_arch
|
||||
machine = node['kernel']['machine']
|
||||
|
||||
case machine
|
||||
when /armv6l/
|
||||
'arm-pi'
|
||||
when /aarch64/
|
||||
'arm64'
|
||||
when /x86_64/
|
||||
'x64'
|
||||
when /\d86/
|
||||
'x86'
|
||||
else
|
||||
machine
|
||||
end
|
||||
end
|
||||
|
||||
def nodejs_binary_checksum(checksums)
|
||||
checksums["linux_#{nodejs_arch}"]
|
||||
end
|
||||
|
||||
def nodejs_source_url(version, prefix_url, source_url)
|
||||
source_url || ::URI.join(prefix_url, "v#{version}/", "node-v#{version}.tar.gz").to_s
|
||||
end
|
||||
|
||||
def nodejs_binary_url(version, prefix_url, binary_url)
|
||||
binary_url || ::URI.join(prefix_url, "v#{version}/", "node-v#{version}-linux-#{nodejs_arch}.tar.gz").to_s
|
||||
end
|
||||
|
||||
def npm_dist(version, url = nil)
|
||||
return { 'url' => url } if url
|
||||
|
||||
require 'open-uri'
|
||||
require 'json'
|
||||
result = JSON.parse(URI.parse("https://registry.npmjs.org/npm/#{version}").read, max_nesting: false)
|
||||
ret = { 'url' => result['dist']['tarball'], 'version' => result['_npmVersion'], 'shasum' => result['dist']['shasum'] }
|
||||
Chef::Log.debug("Npm dist #{ret}")
|
||||
ret
|
||||
end
|
||||
|
||||
def npm_list(package, path = nil, environment = {})
|
||||
require 'json'
|
||||
cmd = if path
|
||||
@@ -47,9 +124,7 @@ module NodeJs
|
||||
(version ? list[package]['version'] == version : true)
|
||||
end
|
||||
|
||||
def npm_package_installed?(package, version = nil, path = nil, npm_token = nil)
|
||||
environment = { 'NPM_TOKEN' => npm_token } if npm_token
|
||||
|
||||
def npm_package_installed?(package, version = nil, path = nil, environment = {})
|
||||
list = npm_list(package, path, environment)['dependencies']
|
||||
# Return true if package installed and installed to good version
|
||||
# see if we really want to add the url check
|
||||
|
||||
Reference in New Issue
Block a user