Skip to content

Commit

Permalink
npm: add support for production flag when using ci (ansible-colle…
Browse files Browse the repository at this point in the history
…ctions#4299)

* npm - add  '--production` support to 'npm ci' flag

* add changelog fragement for 4299

* Add backticks

Co-authored-by: Felix Fontein <[email protected]>

Co-authored-by: Felix Fontein <[email protected]>
  • Loading branch information
watermelonpizza and felixfontein authored Mar 10, 2022
1 parent 56e8bf1 commit 43af053
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/4299-npm-add-production-with-ci-flag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- npm - add ability to use ``production`` flag when ``ci`` is set (https://github.com/ansible-collections/community.general/pull/4299).
2 changes: 1 addition & 1 deletion plugins/modules/packaging/language/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _exec(self, args, run_in_check_mode=False, check_rc=True, add_package_name=T

if self.glbl:
cmd.append('--global')
if self.production and ('install' in cmd or 'update' in cmd):
if self.production and ('install' in cmd or 'update' in cmd or 'ci' in cmd):
cmd.append('--production')
if self.ignore_scripts:
cmd.append('--ignore-scripts')
Expand Down
72 changes: 72 additions & 0 deletions tests/unit/plugins/modules/packaging/language/test_npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,75 @@ def test_absent_version_different(self):
call(['/testbin/npm', 'list', '--json', '--long', '--global'], check_rc=False, cwd=None),
call(['/testbin/npm', 'uninstall', '--global', 'coffee-script'], check_rc=True, cwd=None),
])

def test_present_package_json(self):
set_module_args({
'global': 'true',
'state': 'present'
})
self.module_main_command.side_effect = [
(0, '{}', ''),
(0, '{}', ''),
]

result = self.module_main(AnsibleExitJson)

self.assertTrue(result['changed'])
self.module_main_command.assert_has_calls([
call(['/testbin/npm', 'install', '--global'], check_rc=True, cwd=None),
])

def test_present_package_json_production(self):
set_module_args({
'production': 'true',
'global': 'true',
'state': 'present',
})
self.module_main_command.side_effect = [
(0, '{}', ''),
(0, '{}', ''),
]

result = self.module_main(AnsibleExitJson)

self.assertTrue(result['changed'])
self.module_main_command.assert_has_calls([
call(['/testbin/npm', 'install', '--global', '--production'], check_rc=True, cwd=None),
])

def test_present_package_json_ci(self):
set_module_args({
'ci': 'true',
'global': 'true',
'state': 'present'
})
self.module_main_command.side_effect = [
(0, '{}', ''),
(0, '{}', ''),
]

result = self.module_main(AnsibleExitJson)

self.assertTrue(result['changed'])
self.module_main_command.assert_has_calls([
call(['/testbin/npm', 'ci', '--global'], check_rc=True, cwd=None),
])

def test_present_package_json_ci_production(self):
set_module_args({
'ci': 'true',
'production': 'true',
'global': 'true',
'state': 'present'
})
self.module_main_command.side_effect = [
(0, '{}', ''),
(0, '{}', ''),
]

result = self.module_main(AnsibleExitJson)

self.assertTrue(result['changed'])
self.module_main_command.assert_has_calls([
call(['/testbin/npm', 'ci', '--global', '--production'], check_rc=True, cwd=None),
])

0 comments on commit 43af053

Please sign in to comment.