Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FreeBSD support #435

Merged
merged 6 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 13 additions & 5 deletions manifests/npm/global_config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Enum['present', 'absent'] $ensure = 'present',
$config_setting = $title,
$cmd_exe_path = $nodejs::cmd_exe_path,
$npm_path = $nodejs::params::npm_path,
$npm_path = $nodejs::npm_path,
$value = undef,
) {
include nodejs
Expand All @@ -17,13 +17,13 @@
if $config_setting =~ /(_|:_)/ {
$onlyif_command = $facts['os']['family'] ? {
'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)",
default => "test -f $(${npm_path} config get globalconfig) && /bin/grep -qe \"^${$config_setting}\" $(${npm_path} config get globalconfig)",
default => "test -f $(${npm_path} config get globalconfig) && grep -qe \"^${$config_setting}\" $(${npm_path} config get globalconfig)",
igalic marked this conversation as resolved.
Show resolved Hide resolved
}
}
else {
$onlyif_command = $facts['os']['family'] ? {
'Windows' => "${cmd_exe_path} /C ${npm_path} get --global| FINDSTR /B \"${config_setting}\"",
default => "${npm_path} get --global | /bin/grep -e \"^${config_setting}\"",
default => "${npm_path} get --global | grep -e \"^${config_setting}\"",
}
}
}
Expand All @@ -35,13 +35,13 @@
if $config_setting =~ /(_|:_)/ {
$onlyif_command = $facts['os']['family'] ? {
'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 )",
default => "! test -f $(${npm_path} config get globalconfig) || ! /bin/grep -qe '^${$config_setting}=\"\\?${$value}\"\\?$' $(${npm_path} config get globalconfig)",
default => "! test -f $(${npm_path} config get globalconfig) || ! grep -qe '^${$config_setting}=\"\\?${$value}\"\\?$' $(${npm_path} config get globalconfig)",
}
}
else {
$onlyif_command = $facts['os']['family'] ? {
'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 )",
default => "/usr/bin/test \"$(${npm_path} get ${config_setting} --global | /usr/bin/tr -d '\n')\" != \"${value}\"",
default => "test \"$(${npm_path} get ${config_setting} --global | tr -d '\n')\" != \"${value}\"",
}
}
}
Expand All @@ -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
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
$nodejs_package_name = 'www/node'
$npm_package_ensure = 'present'
$npm_package_name = 'www/npm'
$npm_path = '/usr/bin/npm'
$npm_path = '/usr/local/bin/npm'
$repo_class = undef
$package_provider = undef
}
Expand Down
7 changes: 7 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
"18.04",
"20.04"
]
},
{
"operatingsystem": "FreeBSD",
"operatingsystemrelease": [
"11",
"12"
]
}
],
"requirements": [
Expand Down
29 changes: 19 additions & 10 deletions spec/defines/global_config_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
facts
end

let(:npm_path) do
if facts[:os]['family'] == 'FreeBSD'
'/usr/local/bin/npm'
else
'/usr/bin/npm'
end
end


igalic marked this conversation as resolved.
Show resolved Hide resolved
context 'with name set to proxy and value set to proxy.domain' do
let(:title) { 'proxy' }
let :params do
Expand All @@ -20,7 +29,7 @@
end

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

Expand All @@ -33,7 +42,7 @@
end

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

Expand All @@ -46,7 +55,7 @@
end

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

Expand All @@ -60,7 +69,7 @@
end

it 'npm config set :_secret should be executed' do
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')
is_expected.to contain_exec('npm_config present //path.to.registry/:_secret').with('command' => "#{npm_path} config set //path.to.registry/:_secret cGFzc3dvcmQ= --global")
end
end

Expand All @@ -82,11 +91,11 @@ class { 'nodejs':
end

it 'npm config set prefer-online should be executed and require npm package' do
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]')
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]')
end

it 'npm config set prefer-online should not require node package' do
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]')
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]')
end
end

Expand All @@ -108,7 +117,7 @@ class { 'nodejs':
end

it 'npm config set loglevel should be executed and require nodejs package' do
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]')
is_expected.to contain_exec('npm_config present loglevel').with('command' => "#{npm_path} config set loglevel debug --global").that_requires('Package[node-package-name]')
end
end

Expand All @@ -132,15 +141,15 @@ class { 'nodejs':
end

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

it 'npm config set init-version should not require npm package' do
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]')
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]')
end

it 'npm config set init-version should not require node package' do
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]')
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]')
end
end
end
Expand Down
Loading