Skip to content

Commit

Permalink
Fix Yarn global not working without explicit executable path (#6138)
Browse files Browse the repository at this point in the history
* Fix Yarn global not working without explicit executable path

* changelog fragment

* fix formatting and add test

* oops
  • Loading branch information
sargunv authored Mar 4, 2023
1 parent 2dee346 commit 3d67f51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/6138-fix-yarn-global.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- yarn - fix ``global=true`` to not fail when `executable` wasn't specified (https://github.com/ansible-collections/community.general/pull/6132)
14 changes: 7 additions & 7 deletions plugins/modules/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,11 @@ def __init__(self, module, **kwargs):
self.registry = kwargs['registry']
self.production = kwargs['production']
self.ignore_scripts = kwargs['ignore_scripts']
self.executable = kwargs['executable']

# Specify a version of package if version arg passed in
self.name_version = None

if kwargs['executable']:
self.executable = kwargs['executable'].split(' ')
else:
self.executable = [module.get_bin_path('yarn', True)]

if kwargs['version'] and self.name is not None:
self.name_version = self.name + '@' + str(self.version)
elif self.name is not None:
Expand Down Expand Up @@ -328,7 +324,6 @@ def main():
version = module.params['version']
globally = module.params['global']
production = module.params['production']
executable = module.params['executable']
registry = module.params['registry']
state = module.params['state']
ignore_scripts = module.params['ignore_scripts']
Expand All @@ -345,9 +340,14 @@ def main():
if state == 'latest':
version = 'latest'

if module.params['executable']:
executable = module.params['executable'].split(' ')
else:
executable = [module.get_bin_path('yarn', True)]

# When installing globally, use the defined path for global node_modules
if globally:
_rc, out, _err = module.run_command([executable, 'global', 'dir'], check_rc=True)
_rc, out, _err = module.run_command(executable + ['global', 'dir'], check_rc=True)
path = out.strip()

yarn = Yarn(module,
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/targets/yarn/tasks/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
that:
- yarn_install_old_package is changed

- name: 'Again but without explicit executable path'
yarn:
path: '{{ remote_tmp_dir }}'
name: left-pad
version: 1.1.0
state: present
environment:
PATH: '{{ yarn_bin_path }}:{{ node_bin_path }}:{{ ansible_env.PATH }}'

- name: 'Upgrade old package'
yarn:
path: '{{ remote_tmp_dir }}'
Expand Down

0 comments on commit 3d67f51

Please sign in to comment.