From 17186bbde05dce4c9ba7d1d7876b2d999d2ff6dd Mon Sep 17 00:00:00 2001 From: Bramzor Date: Fri, 22 Feb 2019 14:54:54 +0100 Subject: [PATCH] Added npm ci command (#49665) * #49664 Added npm ci command * Update lib/ansible/modules/packaging/language/npm.py Sure Co-Authored-By: Bramzor * Moved ci_install so it would work for specific packages Would this work? * Reverted last commit npm ci will remove node_modules so cannot be used it to install a specific module. * Update lib/ansible/modules/packaging/language/npm.py Co-Authored-By: Bramzor * Update lib/ansible/modules/packaging/language/npm.py Co-Authored-By: Bramzor * Update lib/ansible/modules/packaging/language/npm.py Co-Authored-By: Bramzor --- .../fragments/49664-npm-added-ci-param.yaml | 3 +++ lib/ansible/modules/packaging/language/npm.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/49664-npm-added-ci-param.yaml diff --git a/changelogs/fragments/49664-npm-added-ci-param.yaml b/changelogs/fragments/49664-npm-added-ci-param.yaml new file mode 100644 index 00000000000..9ae98862c35 --- /dev/null +++ b/changelogs/fragments/49664-npm-added-ci-param.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - "npm ci feature added which allows to install a project with a clean slate: https://docs.npmjs.com/cli/ci.html" diff --git a/lib/ansible/modules/packaging/language/npm.py b/lib/ansible/modules/packaging/language/npm.py index aa608052f8e..4afa2ef56e6 100644 --- a/lib/ansible/modules/packaging/language/npm.py +++ b/lib/ansible/modules/packaging/language/npm.py @@ -59,6 +59,12 @@ options: type: bool default: no version_added: "2.8" + ci: + description: + - Install packages based on package-lock file, same as running npm ci + type: bool + default: no + version_added: "2.8" production: description: - Install dependencies in production mode, excluding devDependencies @@ -211,6 +217,9 @@ class Npm(object): def install(self): return self._exec(['install']) + def ci_install(self): + return self._exec(['ci']) + def update(self): return self._exec(['update']) @@ -241,6 +250,7 @@ def main(): state=dict(default='present', choices=['present', 'absent', 'latest']), ignore_scripts=dict(default=False, type='bool'), unsafe_perm=dict(default=False, type='bool'), + ci=dict(default=False, type='bool'), ) arg_spec['global'] = dict(default='no', type='bool') module = AnsibleModule( @@ -258,6 +268,7 @@ def main(): state = module.params['state'] ignore_scripts = module.params['ignore_scripts'] unsafe_perm = module.params['unsafe_perm'] + ci = module.params['ci'] if not path and not glbl: module.fail_json(msg='path must be specified when not using global') @@ -269,7 +280,10 @@ def main(): unsafe_perm=unsafe_perm, state=state) changed = False - if state == 'present': + if ci: + npm.ci_install() + changed = True + elif state == 'present': installed, missing = npm.list() if missing: changed = True