|
1 | 1 | action :install do |
2 | 2 | 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}'" |
5 | 6 | end |
6 | 7 | new_resource.updated_by_last_action(true) |
7 | 8 | end |
|
12 | 13 | pkg_id += "@#{new_resource.version}" if new_resource.version |
13 | 14 | execute "install NPM package #{new_resource.name} into #{path}" do |
14 | 15 | cwd path |
15 | | - command "npm install #{pkg_id}" |
| 16 | + user node['current_user'] |
| 17 | + command "sudo -u #{node['current_user']} npm install #{pkg_id}" |
16 | 18 | not_if "cd #{path} && npm ls | grep '#{pkg_id}'" |
17 | 19 | end |
18 | 20 | new_resource.updated_by_last_action(true) |
19 | 21 | end |
20 | 22 |
|
21 | 23 | action :install_from_json do |
22 | 24 | path = new_resource.path |
23 | | - cmd = "npm install" |
| 25 | + cmd = "sudo -u #{node['current_user']} npm install" |
24 | 26 | execute "install NPM packages from package.json at #{path}" do |
25 | 27 | cwd path |
| 28 | + user node['current_user'] |
26 | 29 | command cmd |
27 | 30 | end |
28 | 31 | new_resource.updated_by_last_action(true) |
29 | 32 | end |
30 | 33 |
|
31 | 34 | action :uninstall do |
32 | 35 | 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}" |
34 | 37 | only_if "npm -g ls | grep '#{new_resource.name}'" |
| 38 | + user node['current_user'] |
35 | 39 | end |
36 | 40 | new_resource.updated_by_last_action(true) |
37 | 41 | end |
|
42 | 46 | pkg_id += "@#{new_resource.version}" if new_resource.version |
43 | 47 | execute "uninstall NPM package #{new_resource.name} from #{path}" do |
44 | 48 | cwd path |
45 | | - command "npm uninstall #{pkg_id}" |
| 49 | + user node['current_user'] |
| 50 | + command "sudo -u #{node['current_user']} npm uninstall #{pkg_id}" |
46 | 51 | only_if "cd #{path} && npm | grep '#{pkg_id}'" |
47 | 52 | end |
48 | 53 | new_resource.updated_by_last_action(true) |
|
0 commit comments