mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Properly parse JSON Lines output from yarn (#4050)
* Properly parse JSON Lines output from yarn * Properly support output of yarn global list * Add changelog fragment * Check that the string starts with 'bins-' * Fix changelog fragment * Update changelogs/fragments/4050-properly-parse-json-lines-output-from-yarn.yaml Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
ab7e4ee578
commit
4309dfda52
2 changed files with 15 additions and 9 deletions
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- yarn - fix incorrect handling of ``yarn list`` and ``yarn global list`` output that could result in fatal error (https://github.com/ansible-collections/community.general/pull/4050).
|
||||||
|
- yarn - fix incorrectly reported status when installing a package globally (https://github.com/ansible-collections/community.general/issues/4045, https://github.com/ansible-collections/community.general/pull/4050).
|
|
@ -241,12 +241,15 @@ class Yarn(object):
|
||||||
if error:
|
if error:
|
||||||
self.module.fail_json(msg=error)
|
self.module.fail_json(msg=error)
|
||||||
|
|
||||||
data = json.loads(result)
|
for json_line in result.strip().split('\n'):
|
||||||
try:
|
data = json.loads(json_line)
|
||||||
|
if self.globally:
|
||||||
|
if data['type'] == 'list' and data['data']['type'].startswith('bins-'):
|
||||||
|
# This is a string in format: 'bins-<PACKAGE_NAME>'
|
||||||
|
installed.append(data['data']['type'][5:])
|
||||||
|
else:
|
||||||
|
if data['type'] == 'tree':
|
||||||
dependencies = data['data']['trees']
|
dependencies = data['data']['trees']
|
||||||
except KeyError:
|
|
||||||
missing.append(self.name)
|
|
||||||
return installed, missing
|
|
||||||
|
|
||||||
for dep in dependencies:
|
for dep in dependencies:
|
||||||
name, version = dep['name'].rsplit('@', 1)
|
name, version = dep['name'].rsplit('@', 1)
|
||||||
|
|
Loading…
Reference in a new issue