Conversation
**Summary** Fixes #4445. The bug was introduced in https://github.com/yarnpkg/yarn/pull/3976/files#diff-7066979f95168f7bb59e4f9cfb3ba8fcR211 with an incomplete package optional check, causing many transient dependencies to be ignored at linking stage when `--ignore-optional` flag is passed. This patch fixes the check to combine the flag with the package's actual optional mark. **Test plan** Manually verified #4445 is resolved. Also added a unit test.
This is not true yet, obviously. I will add a unit test soon and won't merge without tests for this. |
| invariant(ref, 'Resolved package info has no package reference'); | ||
| ref.addRequest(this); | ||
| ref.addPattern(this.pattern, resolved); | ||
| ref.addOptional(this.optional); |
There was a problem hiding this comment.
The new test case revealed another bug here: if a package is listed as optional by one package and as a strict dependency by another, it should be non-optional at the end. However, due to incorrect request caching below and the lack of this line here, it's optional status was random :(
bestander
left a comment
There was a problem hiding this comment.
Looks reasonable.
If tests are passing I am fine with it.
I would suggest adding a separate test case for this specific issue instead of making existing one bigger
I was only able to find the additional issues when writing tests. Are you suggesting that I split this into two tests one with nested optional dependencies and keep the old one in addition to them? |
| invariant(ref, 'Resolved package info has no package reference'); | ||
| ref.addRequest(this); | ||
| ref.addPattern(this.pattern, resolved); | ||
| ref.addOptional(this.optional); |
src/package-resolver.js
Outdated
| return; | ||
| } else { | ||
| this.fetchingPatterns[fetchKey] = true; | ||
| this.fetchingPatterns.add(fetchKey); |
There was a problem hiding this comment.
this else block isn't necessary since other wise it'll just return?
There was a problem hiding this comment.
Cost me about 3 hours to catch it :D
| } | ||
|
|
||
| const isMarkedAsOptional = !depinfo.pkg._reference || this.ignoreOptional; | ||
| const isMarkedAsOptional = depinfo.pkg._reference && depinfo.pkg._reference.optional && this.ignoreOptional; |
There was a problem hiding this comment.
sorry I deleted the previous comment because I realized the logic isn't quite the same. The previous one is saying mark as optional if depinfo.pkg._reference doesn't exist (or if ignoreOptional flag). That seemed a little weird to be but if that's still the case, we should probably restore it to the way you had it.
There was a problem hiding this comment.
I know they are not equivalent but no tests failed and I feel like it makes more sense with the new version. What do you think?
There was a problem hiding this comment.
Works for me. LET'S LIVE ON THE EDGE. 🎉
**Summary** Fixes yarnpkg#4445. The bug was introduced in https://github.com/yarnpkg/yarn/pull/3976/files#diff-7066979f95168f7bb59e4f9cfb3ba8fcR211 with an incomplete package optional check. This caused many transient dependencies to be ignored at linking stage when `--ignore-optional` flag is passed. This patch fixes the check to combine the flag with the package's actual optional mark. **Test plan** Manually verified yarnpkg#4445 is resolved. Also added a unit test.
|
Should the night build contain the fix ? |
|
@acuper this change went live with the 1.3.2 release |
|
OK, I have 1.3.2, so for me --ignore-optional is still not working properly. Is there older version of yarn witch should has no the bug introduced inhttps://github.com//pull/3976/files#diff-7066979f95168f7bb59e4f9cfb3ba8fcR211 |
|
I think I found a way to reproduce it:
the result of |
|
@acuper can you please create a new issue so we can track and debug this properly. I'd love to fix of this is broken. |
Summary
Fixes #4445. The bug was introduced in
https://github.com/yarnpkg/yarn/pull/3976/files#diff-7066979f95168f7bb59e4f9cfb3ba8fcR211
with an incomplete package optional check. This caused many transient
dependencies to be ignored at linking stage when
--ignore-optionalflag is passed. This patch fixes the check to combine the flag with
the package's actual optional mark.
Test plan
Manually verified #4445 is resolved. Also added a unit test.