Skip to content

Commit 9aee82b

Browse files
author
Roderik van der Veer
committed
Try to fix NPM permissions, to test!
1 parent f6d442a commit 9aee82b

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

providers/package.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
action :install do
22
execute "install NPM package #{new_resource.name}" do
3-
command "npm -g install #{new_resource.name}"
4-
not_if "npm -g ls | grep '#{new_resource.name}'"
3+
user node['current_user']
4+
command "sudo -u #{node['current_user']} npm -g install #{new_resource.name}"
5+
not_if "sudo -u #{node['current_user']} npm -g ls | grep '#{new_resource.name}'"
56
end
67
new_resource.updated_by_last_action(true)
78
end
@@ -12,26 +13,29 @@
1213
pkg_id += "@#{new_resource.version}" if new_resource.version
1314
execute "install NPM package #{new_resource.name} into #{path}" do
1415
cwd path
15-
command "npm install #{pkg_id}"
16+
user node['current_user']
17+
command "sudo -u #{node['current_user']} npm install #{pkg_id}"
1618
not_if "cd #{path} && npm ls | grep '#{pkg_id}'"
1719
end
1820
new_resource.updated_by_last_action(true)
1921
end
2022

2123
action :install_from_json do
2224
path = new_resource.path
23-
cmd = "npm install"
25+
cmd = "sudo -u #{node['current_user']} npm install"
2426
execute "install NPM packages from package.json at #{path}" do
2527
cwd path
28+
user node['current_user']
2629
command cmd
2730
end
2831
new_resource.updated_by_last_action(true)
2932
end
3033

3134
action :uninstall do
3235
execute "uninstall NPM package #{new_resource.name}" do
33-
command "npm -g uninstall #{new_resource.name}"
36+
command "sudo -u #{node['current_user']} npm -g uninstall #{new_resource.name}"
3437
only_if "npm -g ls | grep '#{new_resource.name}'"
38+
user node['current_user']
3539
end
3640
new_resource.updated_by_last_action(true)
3741
end
@@ -42,7 +46,8 @@
4246
pkg_id += "@#{new_resource.version}" if new_resource.version
4347
execute "uninstall NPM package #{new_resource.name} from #{path}" do
4448
cwd path
45-
command "npm uninstall #{pkg_id}"
49+
user node['current_user']
50+
command "sudo -u #{node['current_user']} npm uninstall #{pkg_id}"
4651
only_if "cd #{path} && npm | grep '#{pkg_id}'"
4752
end
4853
new_resource.updated_by_last_action(true)

0 commit comments

Comments
 (0)