diff --git a/providers/package.rb b/providers/package.rb index ead05f5..696cff2 100644 --- a/providers/package.rb +++ b/providers/package.rb @@ -1,7 +1,8 @@ action :install do execute "install NPM package #{new_resource.name}" do - command "npm -g install #{new_resource.name}" - not_if "npm -g ls | grep '#{new_resource.name}'" + user node['current_user'] + command "sudo -u #{node['current_user']} npm -g install #{new_resource.name}" + not_if "sudo -u #{node['current_user']} npm -g ls | grep '#{new_resource.name}'" end new_resource.updated_by_last_action(true) end @@ -12,7 +13,8 @@ pkg_id += "@#{new_resource.version}" if new_resource.version execute "install NPM package #{new_resource.name} into #{path}" do cwd path - command "npm install #{pkg_id}" + user node['current_user'] + command "sudo -u #{node['current_user']} npm install #{pkg_id}" not_if "cd #{path} && npm ls | grep '#{pkg_id}'" end new_resource.updated_by_last_action(true) @@ -20,9 +22,10 @@ action :install_from_json do path = new_resource.path - cmd = "npm install" + cmd = "sudo -u #{node['current_user']} npm install" execute "install NPM packages from package.json at #{path}" do cwd path + user node['current_user'] command cmd end new_resource.updated_by_last_action(true) @@ -30,8 +33,9 @@ action :uninstall do execute "uninstall NPM package #{new_resource.name}" do - command "npm -g uninstall #{new_resource.name}" + command "sudo -u #{node['current_user']} npm -g uninstall #{new_resource.name}" only_if "npm -g ls | grep '#{new_resource.name}'" + user node['current_user'] end new_resource.updated_by_last_action(true) end @@ -42,7 +46,8 @@ pkg_id += "@#{new_resource.version}" if new_resource.version execute "uninstall NPM package #{new_resource.name} from #{path}" do cwd path - command "npm uninstall #{pkg_id}" + user node['current_user'] + command "sudo -u #{node['current_user']} npm uninstall #{pkg_id}" only_if "cd #{path} && npm | grep '#{pkg_id}'" end new_resource.updated_by_last_action(true)