-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yarn: Fix state=latest not working with global=true #5829
yarn: Fix state=latest not working with global=true #5829
Conversation
plugins/modules/yarn.py
Outdated
if self.globally and unsupported_with_global: | ||
_rc, out, _err = self.module.run_command(self.executable + ['global', 'dir'], check_rc=check_rc) | ||
path = out.strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does mean a global=true
param will override the path
param, but that was previously true anyway due to this line:
if self.path and not self.globally:
Hi @sargunv Also, if you could please add a testcase in the integration tests, so future modifications in this module take that change into account. |
507a647
to
56d8a49
Compare
56d8a49
to
5d162de
Compare
There were previously no The test for upgrade (state=latest, what this PR fixes) is passing, but the newly added test for remove (state=absent) is failing. I'll have to look into how to get these tests running locally to investigate. Normal usage of global=true with state=absent does work locally. EDIT: wasn't able to get the tests running locally at all b/c I'm on a distro w/o systemd. I'll just add only the tests relevant to this PR's scope instead of a full set of |
e9c51e5
to
78ae045
Compare
Got the tests working locally (turns out WSL can enable systemd) and found the issue with the The yarn module assumes a certain community.general/plugins/modules/yarn.py Line 166 in 44172dd
And regardless, hardcoding this path isn't correct as the global dir can be modified by the user with the Yarn config or by environment variable ( |
The magic of tests, we find problems we did not imagine we had 😁. Thanks! |
Fixed that, and while testing that fix I found yet another little bug 🙃 The I updated that one to use the same |
Codecov Report
@@ Coverage Diff @@
## main #5829 +/- ##
==========================================
- Coverage 45.54% 45.54% -0.01%
==========================================
Files 1005 1005
Lines 97706 97713 +7
Branches 17808 17811 +3
==========================================
+ Hits 44505 44507 +2
- Misses 51144 51149 +5
Partials 2057 2057
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Co-authored-by: Felix Fontein <[email protected]>
Hi, is there anything else I need to do to make this PR ready to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sargunv it looks good to me. Only one small issue with the changelog fragment.
Co-authored-by: Alexei Znamensky <[email protected]>
Fixed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Backport to stable-5: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 4c4ef80 on top of patchback/backports/stable-5/4c4ef80ca9518792bc4e0551864a7929254a27a0/pr-5829 Backporting merged PR #5829 into main
🤖 @patchback |
Backport to stable-6: 💚 backport PR created✅ Backport PR branch: Backported as #5992 🤖 @patchback |
* Yarn module: fix state=latest not working with global=true * fix whitespace * add changelog fragment * add integration test cases * add only tests for this PR (install+upgrade) * fix assuming default global dir * fix list() not working when global=true and name a package with no binary * remove ignores * whitespace * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Felix Fontein <[email protected]> * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Alexei Znamensky <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Alexei Znamensky <[email protected]> (cherry picked from commit 4c4ef80)
…king with global=true (#5992) yarn: Fix state=latest not working with global=true (#5829) * Yarn module: fix state=latest not working with global=true * fix whitespace * add changelog fragment * add integration test cases * add only tests for this PR (install+upgrade) * fix assuming default global dir * fix list() not working when global=true and name a package with no binary * remove ignores * whitespace * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Felix Fontein <[email protected]> * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Alexei Znamensky <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Alexei Znamensky <[email protected]> (cherry picked from commit 4c4ef80) Co-authored-by: Sargun Vohra <[email protected]>
…ons#5829) * Yarn module: fix state=latest not working with global=true * fix whitespace * add changelog fragment * add integration test cases * add only tests for this PR (install+upgrade) * fix assuming default global dir * fix list() not working when global=true and name a package with no binary * remove ignores * whitespace * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Felix Fontein <[email protected]> * Update changelogs/fragments/5829-fix-yarn-global.yml Co-authored-by: Alexei Znamensky <[email protected]> --------- Co-authored-by: Felix Fontein <[email protected]> Co-authored-by: Alexei Znamensky <[email protected]>
SUMMARY
Fixes #5712.
_exec
to support running Yarn commands that wouldn't ordinarily be available withyarn global
by setting the working directory to the path fromyarn global dir
instead.list_outdated
to use this new functionality when invokingyarn outdated
.list_outdated
to check for actual errors in stderr output instead of failing on the presence of anything in stderr. This is b/c the Yarn global package.json has no license field, causing a warning to be logged to stderr when invokingyarn outdated
in that directory.Through testing, found a couple more related bugs to fix (see comments below):
DEFAULT_GLOBAL_INSTALLATION_PATH
with code to check the output ofyarn global dir
, as the default path may be different when the use is root, or when the user has set YARN_GLOBAL_FOLDER or the corresponding config flag.list
to function correctly for packages without binaries (regular libraries) when global=true by invokingyarn list
withoutglobal
, the same way I did foryarn outdated
above.And finally, added tests for all the above cases. Previously, there were no tests for
global=true
at all.ISSUE TYPE
COMPONENT NAME
yarn
ADDITIONAL INFORMATION
Before:
After: