Upgrade nodejs to the latest version from the repo

This is possible in newer versions of the nodejs cookbook, by setting
the `node["nodejs"]["package_action"]["nodejs"]` attribute to `:upgrade`
This commit is contained in:
Greg Karékinian
2021-03-30 13:58:55 +02:00
parent 9fc49deafe
commit edf2e071e4
18 changed files with 234 additions and 77 deletions

View File

@@ -22,7 +22,25 @@ module NodeJs
Mixlib::ShellOut.new("npm list #{package} -global -json", environment: environment)
end
JSON.parse(cmd.run_command.stdout, max_nesting: false)
begin
JSON.parse(cmd.run_command.stdout, max_nesting: false)
rescue JSON::ParserError => e
Chef::Log.error("nodejs::library::nodejs_helper::npm_list exception #{e}")
{}
end
end
def url_valid?(list, package)
require 'open-uri'
begin
URI.parse(list.fetch(package, {}).fetch('resolved'))
rescue KeyError
# the package may have been installed without using a url
true
rescue URI::InvalidURIError
false
end
end
def version_valid?(list, package, version)
@@ -34,7 +52,8 @@ module NodeJs
list = npm_list(package, path, environment)['dependencies']
# Return true if package installed and installed to good version
!list.nil? && list.key?(package) && version_valid?(list, package, version)
# see if we really want to add the url check
!list.nil? && list.key?(package) && version_valid?(list, package, version) && url_valid?(list, package)
end
end
end