Skip to content

Fix: incorrect optional ignore in nested dependencies#4448

Merged
BYK merged 7 commits intomasterfrom
optional
Sep 14, 2017
Merged

Fix: incorrect optional ignore in nested dependencies#4448
BYK merged 7 commits intomasterfrom
optional

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Sep 13, 2017

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-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.

**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.
@BYK
Copy link
Copy Markdown
Member Author

BYK commented Sep 13, 2017

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);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

Copy link
Copy Markdown
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@BYK
Copy link
Copy Markdown
Member Author

BYK commented Sep 14, 2017

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

return;
} else {
this.fetchingPatterns[fetchKey] = true;
this.fetchingPatterns.add(fetchKey);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this else block isn't necessary since other wise it'll just return?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I'll fix it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. LET'S LIVE ON THE EDGE. 🎉

@BYK BYK merged commit ef8185b into master Sep 14, 2017
@BYK BYK deleted the optional branch September 14, 2017 16:30
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
**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.
@acuper
Copy link
Copy Markdown

acuper commented Dec 7, 2017

Should the night build contain the fix ?
I installed it and still see missing dependencies errors while using --ignore-optional

@BYK
Copy link
Copy Markdown
Member Author

BYK commented Dec 7, 2017

@acuper this change went live with the 1.3.2 release

@acuper
Copy link
Copy Markdown

acuper commented Dec 7, 2017

OK, I have 1.3.2, so for me --ignore-optional is still not working properly.
Will try to provide the steps how to reproduce but it might hard because this is happening in our internal projects where dependency hierarchy is huge.

Is there older version of yarn witch should has no the bug introduced inhttps://github.com//pull/3976/files#diff-7066979f95168f7bb59e4f9cfb3ba8fcR211
?

@acuper
Copy link
Copy Markdown

acuper commented Dec 7, 2017

I think I found a way to reproduce it:

{ "dependencies": { "internal-package": "^4.1.0", "yargs": "^9.0.1" } }
now internal-package has this as optionalDependency:
"yargs": "^7.0.2"

the result of yarn --ignore-optional is missing package: is-fullwidth-code-point
which dependency path is: yargs -> string-width -> is-fullwidth-code-point

@BYK
Copy link
Copy Markdown
Member Author

BYK commented Dec 7, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error installing phantomjs-prebuilt, with 1.0.x, --ignore-optional, and 2 other deps

4 participants