Skip to content

Commit

Permalink
On Unix, add a sensible exec PATH
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
igalic committed Nov 17, 2020
1 parent 532eead commit ed516f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions manifests/npm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@
$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

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",
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions manifests/npm/global_config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ed516f6

Please sign in to comment.