From eb2369a93475c9aef81b4ffea6be2b1b8bb86074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ga=C3=9Fner?= <40096303+moonrail@users.noreply.github.com> Date: Thu, 23 Jul 2020 09:19:32 +0200 Subject: [PATCH] yarn: Fix handling of empty outdated & scoped packages (#474) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed index out of range in yarn module when no packages are outdated * Fixed handling of yarn dependencies when scoped modules are installed * Added changelog fragment for yarn module fixes * Adhere changelogs/fragments/474-yarn_fix-outdated-fix-list.yml to current standards Co-authored-by: Andrew Klychkov * Added scoped package to yarn integration test Co-authored-by: Jan Gaßner Co-authored-by: Andrew Klychkov --- changelogs/fragments/474-yarn_fix-outdated-fix-list.yml | 3 +++ plugins/modules/packaging/language/yarn.py | 5 ++++- tests/integration/targets/yarn/templates/package.j2 | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/474-yarn_fix-outdated-fix-list.yml diff --git a/changelogs/fragments/474-yarn_fix-outdated-fix-list.yml b/changelogs/fragments/474-yarn_fix-outdated-fix-list.yml new file mode 100644 index 0000000000..baa19b7070 --- /dev/null +++ b/changelogs/fragments/474-yarn_fix-outdated-fix-list.yml @@ -0,0 +1,3 @@ +bugfixes: + - yarn - fixed an index out of range error when no outdated packages where returned by yarn executable (see https://github.com/ansible-collections/community.general/pull/474). + - yarn - fixed an too many values to unpack error when scoped packages are installed (see https://github.com/ansible-collections/community.general/pull/474). diff --git a/plugins/modules/packaging/language/yarn.py b/plugins/modules/packaging/language/yarn.py index 8b21753851..7def1698f0 100644 --- a/plugins/modules/packaging/language/yarn.py +++ b/plugins/modules/packaging/language/yarn.py @@ -243,7 +243,7 @@ class Yarn(object): return installed, missing for dep in dependencies: - name, version = dep['name'].split('@') + name, version = dep['name'].rsplit('@', 1) installed.append(name) if self.name not in installed: @@ -274,6 +274,9 @@ class Yarn(object): if err: self.module.fail_json(msg=err) + if not cmd_result: + return outdated + outdated_packages_data = cmd_result.splitlines()[1] data = json.loads(outdated_packages_data) diff --git a/tests/integration/targets/yarn/templates/package.j2 b/tests/integration/targets/yarn/templates/package.j2 index 5af8b4bab6..8ca73aa83a 100644 --- a/tests/integration/targets/yarn/templates/package.j2 +++ b/tests/integration/targets/yarn/templates/package.j2 @@ -3,6 +3,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "iconv-lite": "^0.4.21" + "iconv-lite": "^0.4.21", + "@types/node": "^12.0.0" } } \ No newline at end of file