From 17edde35a6cf3581c946eb2db2ec61adf0dd44bb Mon Sep 17 00:00:00 2001 From: fnoop Date: Wed, 2 May 2018 09:28:13 +0100 Subject: [PATCH 1/3] Fix default install as non-root user, #305 --- manifests/npm.pp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/manifests/npm.pp b/manifests/npm.pp index 8b4924a3..256282f1 100644 --- a/manifests/npm.pp +++ b/manifests/npm.pp @@ -8,7 +8,7 @@ String $package = $title, $source = 'registry', Array $uninstall_options = [], - $home_dir = '/root', + String $home_dir = "", $user = undef, Boolean $use_package_json = false, ) { @@ -74,13 +74,19 @@ Nodejs::Npm::Global_config_entry<| title == 'https-proxy' |> -> Exec["npm_install_${name}"] Nodejs::Npm::Global_config_entry<| title == 'proxy' |> -> Exec["npm_install_${name}"] + if !empty($home_dir) { + $_homedir = "HOME=${home_dir}" + } else { + $_homedir = undef + } + if $use_package_json { exec { "npm_${npm_command}_${name}": command => "${npm_path} ${npm_command} ${options}", unless => $list_command, user => $user, cwd => $target, - environment => "HOME=${home_dir}", + environment => $_homedir, require => Class['nodejs'], } } else { @@ -89,7 +95,7 @@ unless => $install_check, user => $user, cwd => $target, - environment => "HOME=${home_dir}", + environment => $_homedir, require => Class['nodejs'], } } From 5adf1293028919dcb4bde28a0683bab86a7cefb6 Mon Sep 17 00:00:00 2001 From: fnoop Date: Wed, 2 May 2018 09:57:02 +0100 Subject: [PATCH 2/3] Unset $home_dir type to allow undef, #305, #363 --- manifests/npm.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/npm.pp b/manifests/npm.pp index 256282f1..d046da77 100644 --- a/manifests/npm.pp +++ b/manifests/npm.pp @@ -8,7 +8,7 @@ String $package = $title, $source = 'registry', Array $uninstall_options = [], - String $home_dir = "", + $home_dir = undef, $user = undef, Boolean $use_package_json = false, ) { From 353c6f496c5132cc3064f95c066146c173f37c47 Mon Sep 17 00:00:00 2001 From: fnoop Date: Wed, 2 May 2018 10:27:45 +0100 Subject: [PATCH 3/3] Remove incorrect test for /root HOME, #305 #363 --- spec/defines/nodejs_npm_spec.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spec/defines/nodejs_npm_spec.rb b/spec/defines/nodejs_npm_spec.rb index 5a8b4559..bd370e03 100644 --- a/spec/defines/nodejs_npm_spec.rb +++ b/spec/defines/nodejs_npm_spec.rb @@ -52,10 +52,6 @@ it 'the exec directory should be /home/npm/packages' do is_expected.to contain_exec('npm_install_express').with('cwd' => '/home/npm/packages') end - - it 'the environment variable HOME should be /root' do - is_expected.to contain_exec('npm_install_express').with('environment' => 'HOME=/root') - end end # npm install