From ed516f61acced781cbb587337a9cf76db1dc5e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Tue, 17 Nov 2020 17:10:47 +0100 Subject: [PATCH] On Unix, add a sensible exec PATH since i don't know much about Windows, I'm leaving that as is for now. But in terms of escaping / testing, and consolidating! our testing, it would make sense to extend it to Windows as well. --- manifests/npm.pp | 11 +++++++++++ manifests/npm/global_config_entry.pp | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/manifests/npm.pp b/manifests/npm.pp index d9f240e8..21a02e98 100644 --- a/manifests/npm.pp +++ b/manifests/npm.pp @@ -45,6 +45,13 @@ $list_command = "${npm_path} ls --long --parseable" $install_check = "${list_command} | ${grep_command} \"${target}${dirsep}node_modules${dirsep}${install_check_package_string}\"" + # set a sensible path on Unix + $exec_path = $facts['os']['family'] ? { + 'Windows' => undef, + 'Darwin' => ['/bin', '/usr/bin', '/opt/local/bin', '/usr/local/bin'], + default => ['/bin', '/usr/bin', '/usr/local/bin'], + } + if $ensure == 'absent' { $npm_command = 'rm' $options = $uninstall_options_string @@ -52,6 +59,7 @@ if $use_package_json { exec { "npm_${npm_command}_${name}": command => "${npm_path} ${npm_command} * ${options}", + path => $exec_path, onlyif => $list_command, user => $user, cwd => "${target}${dirsep}node_modules", @@ -60,6 +68,7 @@ } else { exec { "npm_${npm_command}_${name}": command => "${npm_path} ${npm_command} ${package_string} ${options}", + path => $exec_path, onlyif => $install_check, user => $user, cwd => $target, @@ -76,6 +85,7 @@ if $use_package_json { exec { "npm_${npm_command}_${name}": command => "${npm_path} ${npm_command} ${options}", + path => $exec_path, unless => $list_command, user => $user, cwd => $target, @@ -85,6 +95,7 @@ } else { exec { "npm_${npm_command}_${name}": command => "${npm_path} ${npm_command} ${package_string} ${options}", + path => $exec_path, unless => $install_check, user => $user, cwd => $target, diff --git a/manifests/npm/global_config_entry.pp b/manifests/npm/global_config_entry.pp index c8a66e96..73d3101d 100644 --- a/manifests/npm/global_config_entry.pp +++ b/manifests/npm/global_config_entry.pp @@ -61,8 +61,16 @@ default => 'shell', } + # set a sensible path on Unix + $exec_path = $facts['os']['family'] ? { + 'Windows' => undef, + 'Darwin' => ['/bin', '/usr/bin', '/opt/local/bin', '/usr/local/bin'], + default => ['/bin', '/usr/bin', '/usr/local/bin'], + } + exec { "npm_config ${ensure} ${title}": command => "${npm_path} ${command}", + path => $exec_path, provider => $provider, onlyif => $onlyif_command, require => $exec_require,