X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/aba8e248099280195f06609e08a4f6840c956933..18424e9038b5f06d815167da8f0c10bed5d5d211:/cookbooks/nodejs/providers/package.rb diff --git a/cookbooks/nodejs/providers/package.rb b/cookbooks/nodejs/providers/package.rb index ec20d157d..0ecd08eba 100644 --- a/cookbooks/nodejs/providers/package.rb +++ b/cookbooks/nodejs/providers/package.rb @@ -22,46 +22,50 @@ require "json" include Chef::Mixin::ShellOut +use_inline_resources + def load_current_resource @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) - 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 + if !@packages.include?(new_resource.package_name) + converge_by "install #{package_name}" do + shell_out!("npm install --global #{package_name}") + end + elsif new_resource.version && + new_resource.version != @current_resource.version + converge_by "update #{package_name}" do shell_out!("npm install --global #{package_name}") - new_resource.updated_by_last_action(true) end end end action :upgrade do if @packages.include?(new_resource.package_name) - shell_out!("npm update --global #{new_resource.package_name}") - new_resource.updated_by_last_action(true) + converge_by "update #{new_resource.package_name}" do + shell_out!("npm update --global #{new_resource.package_name}") + end end end action :remove do if @packages.include?(new_resource.package_name) - shell_out!("npm remove --global #{new_resource.package_name}") - new_resource.updated_by_last_action(true) + converge_by "remove #{new_resource.package_name}" do + shell_out!("npm remove --global #{new_resource.package_name}") + end end end