Skip to content

Commit

Permalink
add parameter $manage_nodejs_package
Browse files Browse the repository at this point in the history
Defaults to true. This allows for using this module without managing
the nodejs package. The use case for this is where you want to use the
npm package provider in this module, but otherwise have no need for
directly installing nodejs. This patch allows for expressing that use
case in your puppet code.
  • Loading branch information
kenyon committed Nov 17, 2020
1 parent a311c5d commit 30161b2
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ applied before the local installation of npm packages using `nodejs::npm`.
Path to cmd.exe on Windows. Defaults to C:\Windows\system32\cmd.exe. You may
need to change this parameter for certain versions of Windows Server.

#### `manage_nodejs_package`

Whether to manage the nodejs and nodejs-dev packages. Defaults to `true`.

#### `manage_package_repo`

Whether to manage an external repository and use it as the source of the
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# == Class: nodejs: See README.md for documentation.
class nodejs (
$cmd_exe_path = $nodejs::params::cmd_exe_path,
Boolean $manage_nodejs_package = true,
Boolean $manage_package_repo = $nodejs::params::manage_package_repo,
$nodejs_debug_package_ensure = $nodejs::params::nodejs_debug_package_ensure,
Optional[String] $nodejs_debug_package_name = $nodejs::params::nodejs_debug_package_name,
Expand Down
12 changes: 7 additions & 5 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

# npm is a Gentoo USE flag
if $facts['os']['name'] == 'Gentoo' {
if $facts['os']['name'] == 'Gentoo' and $nodejs::manage_nodejs_package {
package_use { $nodejs::nodejs_package_name:
ensure => present,
target => 'nodejs-flags',
Expand All @@ -20,13 +20,15 @@
Package { provider => $nodejs::package_provider }

# nodejs
package { $nodejs::nodejs_package_name:
ensure => $nodejs::nodejs_package_ensure,
tag => 'nodesource_repo',
if $nodejs::manage_nodejs_package {
package { $nodejs::nodejs_package_name:
ensure => $nodejs::nodejs_package_ensure,
tag => 'nodesource_repo',
}
}

# nodejs-development
if $nodejs::nodejs_dev_package_name {
if $nodejs::manage_nodejs_package and $nodejs::nodejs_dev_package_name {
package { $nodejs::nodejs_dev_package_name:
ensure => $nodejs::nodejs_dev_package_ensure,
tag => 'nodesource_repo',
Expand Down
241 changes: 241 additions & 0 deletions spec/classes/nodejs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('nodejs')
is_expected.not_to contain_package(native_debian_devel_package)
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down Expand Up @@ -333,6 +354,27 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('nodejs')
is_expected.not_to contain_package('nodejs-devel')
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down Expand Up @@ -668,6 +710,32 @@
end
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('nodejs')
is_expected.not_to contain_package('nodejs-devel')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -729,6 +797,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -765,6 +858,32 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('www/node')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('www/node')
is_expected.not_to contain_package('www/node-devel')
end
end

# nodejs_dev_package_ensure
context 'with nodejs_dev_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -851,6 +970,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('node')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('node')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -887,6 +1031,32 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('nodejs')
is_expected.not_to contain_package('nodejs-devel')
end
end

# nodejs_dev_package_ensure
context 'with nodejs_dev_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -994,6 +1164,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -1055,6 +1250,31 @@
}
end

# manage_nodejs_package
context 'and manage_nodejs_package set to true' do
let :params do
{
manage_nodejs_package: true
}
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('net-libs/nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
{
manage_nodejs_package: false
}
end

it 'the nodejs package resource should not be present' do
is_expected.not_to contain_package('net-libs/nodejs')
end
end

# nodejs_package_ensure
context 'with nodejs_package_ensure set to present' do
let :params do
Expand Down Expand Up @@ -1121,6 +1341,27 @@
}
end

context 'and manage_nodejs_package set to true' do
let :params do
default_params.merge!(manage_nodejs_package: true)
end

it 'the nodejs package resource should be present' do
is_expected.to contain_package('nodejs')
end
end

context 'and manage_nodejs_package set to false' do
let :params do
default_params.merge!(manage_nodejs_package: false)
end

it 'the nodejs and dev package resources should not be present' do
is_expected.not_to contain_package('nodejs')
is_expected.not_to contain_package('nodejs-devel')
end
end

context 'and repo_class set to ::nodejs::repo::nodesource' do
let :params do
default_params.merge!(repo_class: 'nodejs::repo::nodesource')
Expand Down

0 comments on commit 30161b2

Please sign in to comment.