From ce8b58d7d3a185239b686c50576578e075771458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Mon, 16 Nov 2020 10:57:30 +0100 Subject: [PATCH 1/6] fix failures on BSDs by not using fully qualified path if we can't rely on our PATH, we're hosed anyway. --- manifests/npm/global_config_entry.pp | 10 +++++----- manifests/params.pp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/manifests/npm/global_config_entry.pp b/manifests/npm/global_config_entry.pp index 2a61cc9f..c8a66e96 100644 --- a/manifests/npm/global_config_entry.pp +++ b/manifests/npm/global_config_entry.pp @@ -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 @@ -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)", } } 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}\"", } } } @@ -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}\"", } } } diff --git a/manifests/params.pp b/manifests/params.pp index 87f935f0..b3c521a5 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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 } From b952f90367b465bbcb010b9eb0527d77e9b4e387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Tue, 17 Nov 2020 16:20:01 +0100 Subject: [PATCH 2/6] add FreeBSD to supported OSes --- metadata.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/metadata.json b/metadata.json index e6a6c64f..65481788 100644 --- a/metadata.json +++ b/metadata.json @@ -54,6 +54,13 @@ "18.04", "20.04" ] + }, + { + "operatingsystem": "FreeBSD", + "operatingsystemrelease": [ + "11", + "12" + ] } ], "requirements": [ From 532eead268bf5c8b5becc6c0d0bf4c80712a91f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Tue, 17 Nov 2020 17:00:15 +0100 Subject: [PATCH 3/6] Fix now failing tests on FreeBSD --- spec/defines/global_config_entry_spec.rb | 29 ++++++--- spec/defines/nodejs_npm_spec.rb | 82 +++++++++++++----------- 2 files changed, 64 insertions(+), 47 deletions(-) diff --git a/spec/defines/global_config_entry_spec.rb b/spec/defines/global_config_entry_spec.rb index 029160bf..a4be7480 100644 --- a/spec/defines/global_config_entry_spec.rb +++ b/spec/defines/global_config_entry_spec.rb @@ -11,6 +11,15 @@ facts end + let(:npm_path) do + if os =~ /freebsd/i + '/usr/local/bin/npm' + else + '/usr/bin/npm' + end + end + + context 'with name set to proxy and value set to proxy.domain' do let(:title) { 'proxy' } let :params do @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/defines/nodejs_npm_spec.rb b/spec/defines/nodejs_npm_spec.rb index 5a8b4559..a206365c 100644 --- a/spec/defines/nodejs_npm_spec.rb +++ b/spec/defines/nodejs_npm_spec.rb @@ -11,6 +11,14 @@ facts end + let(:npm_path) do + if os =~ /freebsd/i + '/usr/local/bin/npm' + else + '/usr/bin/npm' + end + end + # This should only affect the exec title let(:title) { 'express' } @@ -26,7 +34,7 @@ it 'the npm install command should run under user foo' do is_expected.to contain_exec('npm_install_express').with( - 'command' => '/usr/bin/npm install express ', + 'command' => "#{npm_path} install express ", 'user' => 'foo' ) end @@ -42,11 +50,11 @@ end it 'the command should be npm install express' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install express ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install express ") end it 'the install_check should grep for /home/npm/packages/node_modules/express' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/express"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/express\"") end it 'the exec directory should be /home/npm/packages' do @@ -69,7 +77,7 @@ end it 'the command should be npm install express --no-bin-links --no-optional' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install express --no-bin-links --no-optional') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install express --no-bin-links --no-optional") end end @@ -83,11 +91,11 @@ end it 'the command should be npm install @scopename/express' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install @scopename/express ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install @scopename/express ") end it 'the install_check should grep for /home/npm/packages/node_modules/@scopename/express' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/@scopename/express"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/@scopename/express\"") end end @@ -102,11 +110,11 @@ end it 'the command should be npm install @scopename/express@tagname' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install @scopename/express@tagname ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install @scopename/express@tagname ") end it 'the install_check should grep for /home/npm/package/node_modules/@scopename/express:@scopename/express@tagname' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/@scopename/express:@scopename/express@tagname"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/@scopename/express:@scopename/express@tagname\"") end end @@ -121,11 +129,11 @@ end it 'the command should be npm install express@tagname' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install express@tagname ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install express@tagname ") end it 'the install_check should grep for /home/npm/package/node_modules/express:express@tagname' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/express:express@tagname"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/express:express@tagname\"") end end @@ -140,11 +148,11 @@ end it 'the command should be npm install @scopename/express@3' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install @scopename/express@3 ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install @scopename/express@3 ") end it 'the install_check should grep for /home/npm/package/node_modules/@scopename/express:@scopename/express@3' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/@scopename/express:@scopename/express@3"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/@scopename/express:@scopename/express@3\"") end end @@ -159,11 +167,11 @@ end it 'the command should be npm install express@3' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install express@3 ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install express@3 ") end it 'the install_check should grep for /home/npm/package/node_modules/express:express@3' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/express:express@3"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/express:express@3\"") end end @@ -178,11 +186,11 @@ end it 'the command should be npm install /local/folder' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install /local/folder ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install /local/folder ") end it 'the install_check should grep for /home/npm/package/node_modules//local/folder' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules//local/folder"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules//local/folder\"") end end @@ -197,11 +205,11 @@ end it 'the command should be npm install /local/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install /local/package.tgz ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install /local/package.tgz ") end it 'the install_check should grep for /home/npm/package/node_modules//local/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules//local/package.tgz"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules//local/package.tgz\"") end end @@ -216,11 +224,11 @@ end it 'the command should be npm install http://domain/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install http://domain/package.tgz ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install http://domain/package.tgz ") end it 'the install_check should grep for /home/npm/package/node_modules/http://domain/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/http://domain/package.tgz"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/http://domain/package.tgz\"") end end @@ -235,11 +243,11 @@ end it 'the command should be npm install https://domain/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install https://domain/package.tgz ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install https://domain/package.tgz ") end it 'the install_check should grep for /home/npm/package/node_modules/https://domain/package.tgz' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/https://domain/package.tgz"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/https://domain/package.tgz\"") end end @@ -254,11 +262,11 @@ end it 'the command should be npm install strongloop/express' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install strongloop/express ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install strongloop/express ") end it 'the install_check should grep for /home/npm/package/node_modules/strongloop/express' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/strongloop/express"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/strongloop/express\"") end end @@ -273,11 +281,11 @@ end it 'the command should be npm install git://github.com/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install git://github.com/strongloop/expressjs.git ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install git://github.com/strongloop/expressjs.git ") end it 'the install_check should grep for /home/npm/package/node_modules/git://github.com/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/git://github.com/strongloop/expressjs.git"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/git://github.com/strongloop/expressjs.git\"") end end @@ -292,11 +300,11 @@ end it 'the command should be npm install git+ssh://git@github.com:/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install git+ssh://git@github.com:/strongloop/expressjs.git ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install git+ssh://git@github.com:/strongloop/expressjs.git ") end it 'the install_check should grep for /home/npm/package/node_modules/git+ssh://git@github.com/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/git+ssh://git@github.com:/strongloop/expressjs.git"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/git+ssh://git@github.com:/strongloop/expressjs.git\"") end end @@ -311,11 +319,11 @@ end it 'the command should be npm install git+https://user@github.com/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install git+https://user@github.com/strongloop/expressjs.git ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install git+https://user@github.com/strongloop/expressjs.git ") end it 'the install_check should grep for /home/npm/package/node_modules/git+https://user@github.com/strongloop/expressjs.git' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/git+https://user@github.com/strongloop/expressjs.git"') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/git+https://user@github.com/strongloop/expressjs.git\"") end end @@ -331,11 +339,11 @@ end it 'the command should be npm install' do - is_expected.to contain_exec('npm_install_express').with('command' => '/usr/bin/npm install ') + is_expected.to contain_exec('npm_install_express').with('command' => "#{npm_path} install ") end it 'the list_command should check if all deps are installed in /home/user/project/node_modules' do - is_expected.to contain_exec('npm_install_express').with('unless' => '/usr/bin/npm ls --long --parseable') + is_expected.to contain_exec('npm_install_express').with('unless' => "#{npm_path} ls --long --parseable") end end @@ -350,11 +358,11 @@ end it 'the command should be npm rm express' do - is_expected.to contain_exec('npm_rm_express').with('command' => '/usr/bin/npm rm express ') + is_expected.to contain_exec('npm_rm_express').with('command' => "#{npm_path} rm express ") end it 'the install_check should grep for /home/npm/packages/node_modules/express' do - is_expected.to contain_exec('npm_rm_express').with('onlyif' => '/usr/bin/npm ls --long --parseable | grep "/home/npm/packages/node_modules/express"') + is_expected.to contain_exec('npm_rm_express').with('onlyif' => "#{npm_path} ls --long --parseable | grep \"/home/npm/packages/node_modules/express\"") end end @@ -371,7 +379,7 @@ it 'the command should be npm rm express --save' do is_expected.to contain_exec('npm_rm_express').with( - 'command' => '/usr/bin/npm rm express --save', + 'command' => "#{npm_path} rm express --save", 'cwd' => '/home/npm/packages' ) end @@ -389,12 +397,12 @@ end it 'the command should be npm rm * in subdirectory node_modules' do - is_expected.to contain_exec('npm_rm_express').with('command' => '/usr/bin/npm rm * ') + is_expected.to contain_exec('npm_rm_express').with('command' => "#{npm_path} rm * ") is_expected.to contain_exec('npm_rm_express').with('cwd' => '/home/user/project/node_modules') end it 'the list_command should check if modules are installed in /home/user/project/node_modules' do - is_expected.to contain_exec('npm_rm_express').with('onlyif' => '/usr/bin/npm ls --long --parseable') + is_expected.to contain_exec('npm_rm_express').with('onlyif' => "#{npm_path} ls --long --parseable") is_expected.to contain_exec('npm_rm_express').with('cwd' => '/home/user/project/node_modules') end end 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 4/6] 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, From c842cb27fb820bdf589bdc5bea9efecb53dd8eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Tue, 17 Nov 2020 23:18:51 +0100 Subject: [PATCH 5/6] directly use facts object, rather than the name from facterdb thanks to @bastelfreak for pointing this out --- spec/defines/global_config_entry_spec.rb | 2 +- spec/defines/nodejs_npm_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/defines/global_config_entry_spec.rb b/spec/defines/global_config_entry_spec.rb index a4be7480..b2c8c958 100644 --- a/spec/defines/global_config_entry_spec.rb +++ b/spec/defines/global_config_entry_spec.rb @@ -12,7 +12,7 @@ end let(:npm_path) do - if os =~ /freebsd/i + if facts[:os]['family'] == 'FreeBSD' '/usr/local/bin/npm' else '/usr/bin/npm' diff --git a/spec/defines/nodejs_npm_spec.rb b/spec/defines/nodejs_npm_spec.rb index a206365c..b9d65907 100644 --- a/spec/defines/nodejs_npm_spec.rb +++ b/spec/defines/nodejs_npm_spec.rb @@ -12,7 +12,7 @@ end let(:npm_path) do - if os =~ /freebsd/i + if facts[:os]['family'] == 'FreeBSD' '/usr/local/bin/npm' else '/usr/bin/npm' From c7f89bc34e9fca4ae1825c52c90f6d6c40f26135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Wed, 18 Nov 2020 06:41:21 +0100 Subject: [PATCH 6/6] remove extra empty line to satisfy rubocop --- spec/defines/global_config_entry_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/defines/global_config_entry_spec.rb b/spec/defines/global_config_entry_spec.rb index b2c8c958..15221b57 100644 --- a/spec/defines/global_config_entry_spec.rb +++ b/spec/defines/global_config_entry_spec.rb @@ -19,7 +19,6 @@ end end - context 'with name set to proxy and value set to proxy.domain' do let(:title) { 'proxy' } let :params do