mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
npm - fix installing from package.json (#2924)
correctly handle cases where a dependency does not have a `version` property because it is either missing or invalid
This commit is contained in:
parent
ffe505a798
commit
a0915036f9
3 changed files with 25 additions and 2 deletions
3
changelogs/fragments/2924-npm-fix-package-json.yml
Normal file
3
changelogs/fragments/2924-npm-fix-package-json.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bugfixes:
|
||||||
|
- npm - correctly handle cases where a dependency does not have a ``version`` property because it is either missing or invalid
|
||||||
|
(https://github.com/ansible-collections/community.general/issues/2917).
|
|
@ -216,7 +216,6 @@ class Npm(object):
|
||||||
self.module.fail_json(msg="Failed to parse NPM output with error %s" % to_native(e))
|
self.module.fail_json(msg="Failed to parse NPM output with error %s" % to_native(e))
|
||||||
if 'dependencies' in data:
|
if 'dependencies' in data:
|
||||||
for dep, props in data['dependencies'].items():
|
for dep, props in data['dependencies'].items():
|
||||||
dep_version = dep + '@' + str(props['version'])
|
|
||||||
|
|
||||||
if 'missing' in props and props['missing']:
|
if 'missing' in props and props['missing']:
|
||||||
missing.append(dep)
|
missing.append(dep)
|
||||||
|
@ -224,6 +223,8 @@ class Npm(object):
|
||||||
missing.append(dep)
|
missing.append(dep)
|
||||||
else:
|
else:
|
||||||
installed.append(dep)
|
installed.append(dep)
|
||||||
|
if 'version' in props and props['version']:
|
||||||
|
dep_version = dep + '@' + str(props['version'])
|
||||||
installed.append(dep_version)
|
installed.append(dep_version)
|
||||||
if self.name_version and self.name_version not in installed:
|
if self.name_version and self.name_version not in installed:
|
||||||
missing.append(self.name)
|
missing.append(self.name)
|
||||||
|
|
|
@ -52,6 +52,25 @@ class NPMModuleTestCase(ModuleTestCase):
|
||||||
call(['/testbin/npm', 'install', '--global', 'coffee-script'], check_rc=True, cwd=None),
|
call(['/testbin/npm', 'install', '--global', 'coffee-script'], check_rc=True, cwd=None),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_present_missing(self):
|
||||||
|
set_module_args({
|
||||||
|
'name': 'coffee-script',
|
||||||
|
'global': 'true',
|
||||||
|
'state': 'present',
|
||||||
|
})
|
||||||
|
self.module_main_command.side_effect = [
|
||||||
|
(0, '{"dependencies": {"coffee-script": {"missing" : true}}}', ''),
|
||||||
|
(0, '{}', ''),
|
||||||
|
]
|
||||||
|
|
||||||
|
result = self.module_main(AnsibleExitJson)
|
||||||
|
|
||||||
|
self.assertTrue(result['changed'])
|
||||||
|
self.module_main_command.assert_has_calls([
|
||||||
|
call(['/testbin/npm', 'list', '--json', '--long', '--global'], check_rc=False, cwd=None),
|
||||||
|
call(['/testbin/npm', 'install', '--global', 'coffee-script'], check_rc=True, cwd=None),
|
||||||
|
])
|
||||||
|
|
||||||
def test_present_version(self):
|
def test_present_version(self):
|
||||||
set_module_args({
|
set_module_args({
|
||||||
'name': 'coffee-script',
|
'name': 'coffee-script',
|
||||||
|
|
Loading…
Reference in a new issue