Skip to content

Commit f558f49

Browse files
authored
Merge pull request #435 from voxpupuli/fix/freebsd
fix failures on BSDs by not using fully qualified path
2 parents 30161b2 + c7f89bc commit f558f49

File tree

6 files changed

+95
-53
lines changed

6 files changed

+95
-53
lines changed

manifests/npm.pp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,21 @@
4545
$list_command = "${npm_path} ls --long --parseable"
4646
$install_check = "${list_command} | ${grep_command} \"${target}${dirsep}node_modules${dirsep}${install_check_package_string}\""
4747

48+
# set a sensible path on Unix
49+
$exec_path = $facts['os']['family'] ? {
50+
'Windows' => undef,
51+
'Darwin' => ['/bin', '/usr/bin', '/opt/local/bin', '/usr/local/bin'],
52+
default => ['/bin', '/usr/bin', '/usr/local/bin'],
53+
}
54+
4855
if $ensure == 'absent' {
4956
$npm_command = 'rm'
5057
$options = $uninstall_options_string
5158

5259
if $use_package_json {
5360
exec { "npm_${npm_command}_${name}":
5461
command => "${npm_path} ${npm_command} * ${options}",
62+
path => $exec_path,
5563
onlyif => $list_command,
5664
user => $user,
5765
cwd => "${target}${dirsep}node_modules",
@@ -60,6 +68,7 @@
6068
} else {
6169
exec { "npm_${npm_command}_${name}":
6270
command => "${npm_path} ${npm_command} ${package_string} ${options}",
71+
path => $exec_path,
6372
onlyif => $install_check,
6473
user => $user,
6574
cwd => $target,
@@ -76,6 +85,7 @@
7685
if $use_package_json {
7786
exec { "npm_${npm_command}_${name}":
7887
command => "${npm_path} ${npm_command} ${options}",
88+
path => $exec_path,
7989
unless => $list_command,
8090
user => $user,
8191
cwd => $target,
@@ -85,6 +95,7 @@
8595
} else {
8696
exec { "npm_${npm_command}_${name}":
8797
command => "${npm_path} ${npm_command} ${package_string} ${options}",
98+
path => $exec_path,
8899
unless => $install_check,
89100
user => $user,
90101
cwd => $target,

manifests/npm/global_config_entry.pp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Enum['present', 'absent'] $ensure = 'present',
44
$config_setting = $title,
55
$cmd_exe_path = $nodejs::cmd_exe_path,
6-
$npm_path = $nodejs::params::npm_path,
6+
$npm_path = $nodejs::npm_path,
77
$value = undef,
88
) {
99
include nodejs
@@ -17,13 +17,13 @@
1717
if $config_setting =~ /(_|:_)/ {
1818
$onlyif_command = $facts['os']['family'] ? {
1919
'Windows' => "${cmd_exe_path} /C FOR /F %G IN ('${npm_path} config get globalconfig') DO IF EXIST %G (FINDSTR /B /C:\"${$config_setting}\" %G) ELSE (EXIT 1)",
20-
default => "test -f $(${npm_path} config get globalconfig) && /bin/grep -qe \"^${$config_setting}\" $(${npm_path} config get globalconfig)",
20+
default => "test -f $(${npm_path} config get globalconfig) && grep -qe \"^${$config_setting}\" $(${npm_path} config get globalconfig)",
2121
}
2222
}
2323
else {
2424
$onlyif_command = $facts['os']['family'] ? {
2525
'Windows' => "${cmd_exe_path} /C ${npm_path} get --global| FINDSTR /B \"${config_setting}\"",
26-
default => "${npm_path} get --global | /bin/grep -e \"^${config_setting}\"",
26+
default => "${npm_path} get --global | grep -e \"^${config_setting}\"",
2727
}
2828
}
2929
}
@@ -35,13 +35,13 @@
3535
if $config_setting =~ /(_|:_)/ {
3636
$onlyif_command = $facts['os']['family'] ? {
3737
'Windows' => "${cmd_exe_path} /V /C FOR /F %G IN ('${npm_path} config get globalconfig') DO IF EXIST %G (FINDSTR /B /C:\"${$config_setting}=\\\"${$value}\\\"\" %G & IF !ERRORLEVEL! EQU 0 ( EXIT 1 ) ELSE ( EXIT 0 )) ELSE ( EXIT 0 )",
38-
default => "! test -f $(${npm_path} config get globalconfig) || ! /bin/grep -qe '^${$config_setting}=\"\\?${$value}\"\\?$' $(${npm_path} config get globalconfig)",
38+
default => "! test -f $(${npm_path} config get globalconfig) || ! grep -qe '^${$config_setting}=\"\\?${$value}\"\\?$' $(${npm_path} config get globalconfig)",
3939
}
4040
}
4141
else {
4242
$onlyif_command = $facts['os']['family'] ? {
4343
'Windows' => "${cmd_exe_path} /C FOR /F %i IN ('${npm_path} get ${config_setting} --global') DO IF \"%i\" NEQ \"${value}\" ( EXIT 0 ) ELSE ( EXIT 1 )",
44-
default => "/usr/bin/test \"$(${npm_path} get ${config_setting} --global | /usr/bin/tr -d '\n')\" != \"${value}\"",
44+
default => "test \"$(${npm_path} get ${config_setting} --global | tr -d '\n')\" != \"${value}\"",
4545
}
4646
}
4747
}
@@ -61,8 +61,16 @@
6161
default => 'shell',
6262
}
6363

64+
# set a sensible path on Unix
65+
$exec_path = $facts['os']['family'] ? {
66+
'Windows' => undef,
67+
'Darwin' => ['/bin', '/usr/bin', '/opt/local/bin', '/usr/local/bin'],
68+
default => ['/bin', '/usr/bin', '/usr/local/bin'],
69+
}
70+
6471
exec { "npm_config ${ensure} ${title}":
6572
command => "${npm_path} ${command}",
73+
path => $exec_path,
6674
provider => $provider,
6775
onlyif => $onlyif_command,
6876
require => $exec_require,

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
$nodejs_package_name = 'www/node'
149149
$npm_package_ensure = 'present'
150150
$npm_package_name = 'www/npm'
151-
$npm_path = '/usr/bin/npm'
151+
$npm_path = '/usr/local/bin/npm'
152152
$repo_class = undef
153153
$package_provider = undef
154154
}

metadata.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
"18.04",
5555
"20.04"
5656
]
57+
},
58+
{
59+
"operatingsystem": "FreeBSD",
60+
"operatingsystemrelease": [
61+
"11",
62+
"12"
63+
]
5764
}
5865
],
5966
"requirements": [

spec/defines/global_config_entry_spec.rb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
facts
1212
end
1313

14+
let(:npm_path) do
15+
if facts[:os]['family'] == 'FreeBSD'
16+
'/usr/local/bin/npm'
17+
else
18+
'/usr/bin/npm'
19+
end
20+
end
21+
1422
context 'with name set to proxy and value set to proxy.domain' do
1523
let(:title) { 'proxy' }
1624
let :params do
@@ -20,7 +28,7 @@
2028
end
2129

2230
it 'npm config set proxy proxy.domain should be executed' do
23-
is_expected.to contain_exec('npm_config present proxy').with('command' => '/usr/bin/npm config set proxy proxy.domain --global')
31+
is_expected.to contain_exec('npm_config present proxy').with('command' => "#{npm_path} config set proxy proxy.domain --global")
2432
end
2533
end
2634

@@ -33,7 +41,7 @@
3341
end
3442

3543
it 'npm config set https-proxy proxy.domain should be executed' do
36-
is_expected.to contain_exec('npm_config present https-proxy').with('command' => '/usr/bin/npm config set https-proxy proxy.domain --global')
44+
is_expected.to contain_exec('npm_config present https-proxy').with('command' => "#{npm_path} config set https-proxy proxy.domain --global")
3745
end
3846
end
3947

@@ -46,7 +54,7 @@
4654
end
4755

4856
it 'npm config delete color should be executed' do
49-
is_expected.to contain_exec('npm_config absent color').with('command' => '/usr/bin/npm config delete color --global')
57+
is_expected.to contain_exec('npm_config absent color').with('command' => "#{npm_path} config delete color --global")
5058
end
5159
end
5260

@@ -60,7 +68,7 @@
6068
end
6169

6270
it 'npm config set :_secret should be executed' do
63-
is_expected.to contain_exec('npm_config present //path.to.registry/:_secret').with('command' => '/usr/bin/npm config set //path.to.registry/:_secret cGFzc3dvcmQ= --global')
71+
is_expected.to contain_exec('npm_config present //path.to.registry/:_secret').with('command' => "#{npm_path} config set //path.to.registry/:_secret cGFzc3dvcmQ= --global")
6472
end
6573
end
6674

@@ -82,11 +90,11 @@ class { 'nodejs':
8290
end
8391

8492
it 'npm config set prefer-online should be executed and require npm package' do
85-
is_expected.to contain_exec('npm_config present prefer-online').with('command' => '/usr/bin/npm config set prefer-online true --global').that_requires('Package[npm-package-name]')
93+
is_expected.to contain_exec('npm_config present prefer-online').with('command' => "#{npm_path} config set prefer-online true --global").that_requires('Package[npm-package-name]')
8694
end
8795

8896
it 'npm config set prefer-online should not require node package' do
89-
is_expected.not_to contain_exec('npm_config present prefer-online').with('command' => '/usr/bin/npm config set prefer-online true --global').that_requires('Package[node-package-name]')
97+
is_expected.not_to contain_exec('npm_config present prefer-online').with('command' => "#{npm_path} config set prefer-online true --global").that_requires('Package[node-package-name]')
9098
end
9199
end
92100

@@ -108,7 +116,7 @@ class { 'nodejs':
108116
end
109117

110118
it 'npm config set loglevel should be executed and require nodejs package' do
111-
is_expected.to contain_exec('npm_config present loglevel').with('command' => '/usr/bin/npm config set loglevel debug --global').that_requires('Package[node-package-name]')
119+
is_expected.to contain_exec('npm_config present loglevel').with('command' => "#{npm_path} config set loglevel debug --global").that_requires('Package[node-package-name]')
112120
end
113121
end
114122

@@ -132,15 +140,15 @@ class { 'nodejs':
132140
end
133141

134142
it 'npm config set init-version should be executed' do
135-
is_expected.to contain_exec('npm_config present init-version').with('command' => '/usr/bin/npm config set init-version 0.0.1 --global')
143+
is_expected.to contain_exec('npm_config present init-version').with('command' => "#{npm_path} config set init-version 0.0.1 --global")
136144
end
137145

138146
it 'npm config set init-version should not require npm package' do
139-
is_expected.not_to contain_exec('npm_config present init-version').with('command' => '/usr/bin/npm config set init-version 0.0.1 --global').that_requires('Package[npm-package-name]')
147+
is_expected.not_to contain_exec('npm_config present init-version').with('command' => "#{npm_path} config set init-version 0.0.1 --global").that_requires('Package[npm-package-name]')
140148
end
141149

142150
it 'npm config set init-version should not require node package' do
143-
is_expected.not_to contain_exec('npm_config present init-version').with('command' => '/usr/bin/npm config set init-version 0.0.1 --global').that_requires('Package[node-package-name]')
151+
is_expected.not_to contain_exec('npm_config present init-version').with('command' => "#{npm_path} config set init-version 0.0.1 --global").that_requires('Package[node-package-name]')
144152
end
145153
end
146154
end

0 commit comments

Comments
 (0)