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

Fix default install as non-root user, #305 #363

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions manifests/npm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
String $package = $title,
$source = 'registry',
Array $uninstall_options = [],
$home_dir = '/root',
$home_dir = undef,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're at it, we could just as well give home_dir an Optional[Stdlib::AbsPath] type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the default behavior of the module and would likely need a major version bump.

$user = undef,
Boolean $use_package_json = false,
) {
Expand Down Expand Up @@ -74,13 +74,19 @@
Nodejs::Npm::Global_config_entry<| title == 'https-proxy' |> -> Exec["npm_install_${name}"]
Nodejs::Npm::Global_config_entry<| title == 'proxy' |> -> Exec["npm_install_${name}"]

if !empty($home_dir) {
$_homedir = "HOME=${home_dir}"
} else {
$_homedir = undef
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a selector is easier to read?

$_homedir = $home_dir? {
  undef => undef,
  default => "HOME=${home_dir}",
}


if $use_package_json {
exec { "npm_${npm_command}_${name}":
command => "${npm_path} ${npm_command} ${options}",
unless => $list_command,
user => $user,
cwd => $target,
environment => "HOME=${home_dir}",
environment => $_homedir,
require => Class['nodejs'],
}
} else {
Expand All @@ -89,7 +95,7 @@
unless => $install_check,
user => $user,
cwd => $target,
environment => "HOME=${home_dir}",
environment => $_homedir,
require => Class['nodejs'],
}
}
Expand Down
4 changes: 0 additions & 4 deletions spec/defines/nodejs_npm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@
it 'the exec directory should be /home/npm/packages' do
is_expected.to contain_exec('npm_install_express').with('cwd' => '/home/npm/packages')
end

it 'the environment variable HOME should be /root' do
is_expected.to contain_exec('npm_install_express').with('environment' => 'HOME=/root')
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of removing the test, why not modify it ?

end

# npm install <package> <install_options>
Expand Down