diff --git a/README.md b/README.md index f42fd267..2077fee0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/manifests/init.pp b/manifests/init.pp index f8ce08a5..1e361474 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, diff --git a/manifests/install.pp b/manifests/install.pp index f28d912f..e6db8d04 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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', @@ -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', diff --git a/spec/classes/nodejs_spec.rb b/spec/classes/nodejs_spec.rb index d653d781..9a9f36b5 100644 --- a/spec/classes/nodejs_spec.rb +++ b/spec/classes/nodejs_spec.rb @@ -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') @@ -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') @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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')