X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/7b9ec4b60ee39614d1d083d7220e76b07d2b275f..2fa4b09c609ade8b4c3c2782c22608b8db464784:/cookbooks/nodejs/providers/package.rb diff --git a/cookbooks/nodejs/providers/package.rb b/cookbooks/nodejs/providers/package.rb index f726df310..9d83f40ff 100644 --- a/cookbooks/nodejs/providers/package.rb +++ b/cookbooks/nodejs/providers/package.rb @@ -22,33 +22,33 @@ require "json" include Chef::Mixin::ShellOut +use_inline_resources + def load_current_resource - @packages = JSON.parse(shell_out("npm list --global --json").stdout)["dependencies"] + @packages = JSON.parse(shell_out("npm list --global --json").stdout)["dependencies"] || {} @current_resource = Chef::Resource::NodejsPackage.new(new_resource.name) @current_resource.package_name(new_resource.package_name) - if package = @packages[@current_resource.package_name] + if (package = @packages[@current_resource.package_name]) @current_resource.version(package["version"]) end @current_resource end action :install do - if new_resource.version - package_name = "#{new_resource.package_name}@#{new_resource.version}" - else - package_name = new_resource.package_name - end + package_name = if new_resource.version + "#{new_resource.package_name}@#{new_resource.version}" + else + new_resource.package_name + end - unless @packages.include?(new_resource.package_name) + if !@packages.include?(new_resource.package_name) + shell_out!("npm install --global #{package_name}") + new_resource.updated_by_last_action(true) + elsif new_resource.version && + new_resource.version != @current_resource.version shell_out!("npm install --global #{package_name}") new_resource.updated_by_last_action(true) - else - if new_resource.version && - new_resource.version != @current_resource.version - shell_out!("npm install --global #{package_name}") - new_resource.updated_by_last_action(true) - end end end