From dc60e71fd5ec60494a28fdb7f145c183ce99bb22 Mon Sep 17 00:00:00 2001 From: Amin Vakil Date: Wed, 2 Dec 2020 00:43:15 +0330 Subject: [PATCH] Add no-optional flag to npm (#1428) * Add no-optional flag to npm * Add changelog * Oops * Add no_optional to Npm class --- changelogs/fragments/1428-npm-no-optional.yml | 3 +++ plugins/modules/packaging/language/npm.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1428-npm-no-optional.yml diff --git a/changelogs/fragments/1428-npm-no-optional.yml b/changelogs/fragments/1428-npm-no-optional.yml new file mode 100644 index 0000000000..8c91fd7dfb --- /dev/null +++ b/changelogs/fragments/1428-npm-no-optional.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - npm - add ``no-optional`` option (https://github.com/ansible-collections/community.general/issues/1421). diff --git a/plugins/modules/packaging/language/npm.py b/plugins/modules/packaging/language/npm.py index 42fe8d906c..5c07d26287 100644 --- a/plugins/modules/packaging/language/npm.py +++ b/plugins/modules/packaging/language/npm.py @@ -76,6 +76,12 @@ options: type: str default: present choices: [ "present", "absent", "latest" ] + no_optional: + description: + - Use the C(--no-optional) flag when installing. + type: bool + default: no + version_added: 2.0.0 requirements: - npm installed in bin path (recommended /usr/local/bin) ''' @@ -144,6 +150,7 @@ class Npm(object): self.ignore_scripts = kwargs['ignore_scripts'] self.unsafe_perm = kwargs['unsafe_perm'] self.state = kwargs['state'] + self.no_optional = kwargs['no_optional'] if kwargs['executable']: self.executable = kwargs['executable'].split(' ') @@ -172,6 +179,8 @@ class Npm(object): if self.registry: cmd.append('--registry') cmd.append(self.registry) + if self.no_optional: + cmd.append('--no-optional') # If path is specified, cd into that path and run the command. cwd = None @@ -245,6 +254,7 @@ def main(): ignore_scripts=dict(default=False, type='bool'), unsafe_perm=dict(default=False, type='bool'), ci=dict(default=False, type='bool'), + no_optional=dict(default=False, type='bool'), ) arg_spec['global'] = dict(default=False, type='bool') module = AnsibleModule( @@ -263,6 +273,7 @@ def main(): ignore_scripts = module.params['ignore_scripts'] unsafe_perm = module.params['unsafe_perm'] ci = module.params['ci'] + no_optional = module.params['no_optional'] if not path and not glbl: module.fail_json(msg='path must be specified when not using global') @@ -271,7 +282,7 @@ def main(): npm = Npm(module, name=name, path=path, version=version, glbl=glbl, production=production, executable=executable, registry=registry, ignore_scripts=ignore_scripts, - unsafe_perm=unsafe_perm, state=state) + unsafe_perm=unsafe_perm, state=state, no_optional=no_optional) changed = False if ci: