-
-
Notifications
You must be signed in to change notification settings - Fork 246
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 an option to install npm deps from package.json #300
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
Array $uninstall_options = [], | ||
$home_dir = '/root', | ||
$user = undef, | ||
Boolean $use_package_json = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. datatypes \o/ |
||
) { | ||
|
||
$install_options_string = join($install_options, ' ') | ||
|
@@ -37,21 +38,34 @@ | |
default => 'grep', | ||
} | ||
|
||
$install_check = $::osfamily ? { | ||
'Windows' => "${npm_path} ls --long --parseable | ${grep_command} \"${target}\\node_modules\\${install_check_package_string}\"", | ||
default => "${npm_path} ls --long --parseable | ${grep_command} \"${target}/node_modules/${install_check_package_string}\"", | ||
$dirsep = $::osfamily ? { | ||
'Windows' => "\\", | ||
default => '/' | ||
} | ||
|
||
$list_command = "${npm_path} ls --long --parseable" | ||
$install_check = "${list_command} | ${grep_command} \"${target}${dirsep}node_modules${dirsep}${install_check_package_string}\"" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about a using a variable for a directory separator in a string - I personally prefer explicit versus implicit values for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO this makes the code more readable - the string just differ by the dir seps... Maybe let's replace it with a call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's an idea. Not sure if there will be unintended side-effects to doing this though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this is not even necessary... According to https://docs.puppet.com/puppet/5.2/lang_windows_file_paths.html#when-to-use-each-kind-of-slash, we can just use slashes. I don't have a Windows Puppet at hands to prove this true or false - anything available on your side? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @poikilotherm Er I'm not sure if I'm much help - I haven't tested Puppet on Windows with anything for...quite some some time. Looking at the docs in more detail though, it seems as though we do care about what type of slashes, because we're using cmd.exe to run the grep-alternative and cmd.exe requires backslashes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if $ensure == 'absent' { | ||
$npm_command = 'rm' | ||
$options = $uninstall_options_string | ||
|
||
exec { "npm_${npm_command}_${name}": | ||
command => "${npm_path} ${npm_command} ${package_string} ${options}", | ||
onlyif => $install_check, | ||
user => $user, | ||
cwd => $target, | ||
require => Class['nodejs'], | ||
if $use_package_json { | ||
exec { "npm_${npm_command}_${name}": | ||
command => "${npm_path} ${npm_command} * ${options}", | ||
onlyif => $list_command, | ||
user => $user, | ||
cwd => "${target}${dirsep}node_modules", | ||
require => Class['nodejs'], | ||
} | ||
} else { | ||
exec { "npm_${npm_command}_${name}": | ||
command => "${npm_path} ${npm_command} ${package_string} ${options}", | ||
onlyif => $install_check, | ||
user => $user, | ||
cwd => $target, | ||
require => Class['nodejs'], | ||
} | ||
} | ||
} else { | ||
$npm_command = 'install' | ||
|
@@ -60,13 +74,24 @@ | |
Nodejs::Npm::Global_config_entry<| title == 'https-proxy' |> -> Exec["npm_install_${name}"] | ||
Nodejs::Npm::Global_config_entry<| title == 'proxy' |> -> Exec["npm_install_${name}"] | ||
|
||
exec { "npm_${npm_command}_${name}": | ||
command => "${npm_path} ${npm_command} ${package_string} ${options}", | ||
unless => $install_check, | ||
user => $user, | ||
cwd => $target, | ||
environment => "HOME=${home_dir}", | ||
require => Class['nodejs'], | ||
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}", | ||
require => Class['nodejs'], | ||
} | ||
} else { | ||
exec { "npm_${npm_command}_${name}": | ||
command => "${npm_path} ${npm_command} ${package_string} ${options}", | ||
unless => $install_check, | ||
user => $user, | ||
cwd => $target, | ||
environment => "HOME=${home_dir}", | ||
require => Class['nodejs'], | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs \o/