Skip to content

Commit

Permalink
[PR #8885/38479ee9 backport][stable-9] npm: Add force flag (#8893)
Browse files Browse the repository at this point in the history
npm: Add force flag (#8885)

* Add force flag for nmp module

* Add CHANGELOG fragment

* Add force to cmdrunner

* Update CHANGELOG

* Add comma

(cherry picked from commit 38479ee)

Co-authored-by: alexander <[email protected]>
  • Loading branch information
patchback[bot] and abakanovskii committed Sep 21, 2024
1 parent 57277e0 commit eae0c4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8885-add-force-flag-for-nmp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- npm - add ``force`` parameter to allow ``--force`` (https://github.com/ansible-collections/community.general/pull/8885).
19 changes: 17 additions & 2 deletions plugins/modules/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
type: bool
default: false
version_added: 2.5.0
force:
description:
- Use the C(--force) flag when installing.
type: bool
default: false
version_added: 9.5.0
requirements:
- npm installed in bin path (recommended /usr/local/bin)
'''
Expand All @@ -117,6 +123,11 @@
name: coffee-script
global: true
- name: Force Install "coffee-script" node.js package.
community.general.npm:
name: coffee-script
force: true
- name: Remove the globally package "coffee-script".
community.general.npm:
name: coffee-script
Expand Down Expand Up @@ -167,6 +178,7 @@ def __init__(self, module, **kwargs):
self.state = kwargs['state']
self.no_optional = kwargs['no_optional']
self.no_bin_links = kwargs['no_bin_links']
self.force = kwargs['force']

if kwargs['executable']:
self.executable = kwargs['executable'].split(' ')
Expand All @@ -191,6 +203,7 @@ def __init__(self, module, **kwargs):
registry=cmd_runner_fmt.as_opt_val('--registry'),
no_optional=cmd_runner_fmt.as_bool('--no-optional'),
no_bin_links=cmd_runner_fmt.as_bool('--no-bin-links'),
force=cmd_runner_fmt.as_bool('--force'),
)
)

Expand All @@ -212,7 +225,7 @@ def _exec(self, args, run_in_check_mode=False, check_rc=True, add_package_name=T
params['name_version'] = self.name_version if add_package_name else None

with self.runner(
"exec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links",
"exec_args global_ production ignore_scripts unsafe_perm name_version registry no_optional no_bin_links force",
check_rc=check_rc, cwd=cwd
) as ctx:
rc, out, err = ctx.run(**params)
Expand Down Expand Up @@ -289,6 +302,7 @@ def main():
ci=dict(default=False, type='bool'),
no_optional=dict(default=False, type='bool'),
no_bin_links=dict(default=False, type='bool'),
force=dict(default=False, type='bool'),
)
arg_spec['global'] = dict(default=False, type='bool')
module = AnsibleModule(
Expand Down Expand Up @@ -318,7 +332,8 @@ def main():
unsafe_perm=module.params['unsafe_perm'],
state=state,
no_optional=module.params['no_optional'],
no_bin_links=module.params['no_bin_links'])
no_bin_links=module.params['no_bin_links'],
force=module.params['force'])

changed = False
if module.params['ci']:
Expand Down

0 comments on commit eae0c4f

Please sign in to comment.