Skip to content
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

Fix: Resolve peerDependencies from all higher levels, not just root #4478

Merged
merged 11 commits into from
Sep 16, 2017

Conversation

BYK
Copy link
Member

@BYK BYK commented Sep 15, 2017

Summary

Fixes #4446, fixes #4433, fixes #2688, fixes #2387. Follow up to #3803. The fix in #3893 was
too aggressive, allowing only top-level dependencies to be used in
peer dependency resolution which was incorrect. This patch allows
resolving peer dependencies from the same or higher levels in the
dependency tree.

Test plan

Additional unit and integration tests.

**Summary**

Fixes #4446, fixes #4433. Follow up to #3893. The fix in #3893 was
too aggressive, allowing only top-level dependencies to be used in
peer dependency resolution which was incorrect. This patch allows
resolving peer dependencies from the same or higher levels in the
dependency tree.

**Test plan**

Additional unit and integration tests.
@BYK
Copy link
Member Author

BYK commented Sep 15, 2017

I've tested this with the mentioned issues and it seems to fix them both. I'll also test tihs with other similar issues and create-react-app but it should be fine. I'll also add tests. This is to get initial feedback to confirm my approach is sound.

package.json Outdated
@@ -40,7 +40,7 @@
"request": "^2.81.0",
"request-capture-har": "^1.2.2",
"rimraf": "^2.5.0",
"semver": "^5.1.0",
"semver": "^5.4.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

This update is not required so I can revert if you want.

@buildsize
Copy link

buildsize bot commented Sep 15, 2017

This change will increase the build size from 9.69 MB to 9.69 MB, an increase of 1.55 KB (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 834.53 KB 834.59 KB 67 bytes (0%)
yarn-[version].js 3.69 MB 3.69 MB 656 bytes (0%)
yarn-legacy-[version].js 3.74 MB 3.74 MB 656 bytes (0%)
yarn-v[version].tar.gz 838.58 KB 838.7 KB 124 bytes (0%)
yarn_[version]all.deb 634.79 KB 634.88 KB 88 bytes (0%)

const {root, version} = pkg._reference || {};
return root && this._satisfiesPeerDependency(range, version);
const {level, version} = pkg._reference || {};
return level <= ref.level && this._satisfiesPeerDependency(range, version);
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be prioritizing some links over others, i.e. top level dependency should satisfy its dependencies from root (same level). I'm not sure whether a nested dependency should satisfy it from root first or sibling first. But maybe instead of find, we need to add it to a collection and then pick out either the lowest level or closest level match. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good thinking! I think it should resolve to the closest. I'll update the code.

@BYK
Copy link
Member Author

BYK commented Sep 15, 2017

@kaylieEB updated per your suggestion. Also tested with yarn create react-app and all the peer dependency warnings are gone now 🎉

if (resolvedPeerPkgPattern) {
ref.addDependencies(resolvedPeerPkgPattern);
} else {
const depError = incorrectPeer ? 'incorrectPeer' : 'unmetPeer';
Copy link
Member

Choose a reason for hiding this comment

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

you can define let depError = 'unmetPeer' instead of let incorrectPeer = false and set it to 'incorrectPeer' above right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hahaha, right! Stupid me. Will do that too. Rest looks fine? I'll add tests soon.

Copy link
Member

Choose a reason for hiding this comment

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

yup the rest looks good!

@BYK
Copy link
Member Author

BYK commented Sep 15, 2017

@kaylieEB one more review, for tests please! :)

Copy link
Member

@kaylie-alexa kaylie-alexa left a comment

Choose a reason for hiding this comment

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

minor comment, looks good!

@@ -223,6 +223,7 @@ const messages = {

unmetPeer: '$0 has unmet peer dependency $1.',
incorrectPeer: '$0 has incorrect peer dependency $1.',
selectedPeer: 'Selecting $1 at level $2 as the peer dependency of $0.',
Copy link
Member

Choose a reason for hiding this comment

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

saw this earlier, nice touch!

@@ -51,6 +59,7 @@ addTest('https://[email protected]/stevemao/left-pad.git'); // git url, with userna
addTest('https://github.com/yarnpkg/yarn/releases/download/v0.18.1/yarn-v0.18.1.tar.gz'); // tarball
addTest('https://github.com/bestander/chrome-app-livereload.git'); // no package.json
addTest('bestander/chrome-app-livereload'); // no package.json, github, tarball
addTest('react-scripts', {strict: true}); // many peer dependencies, there shouldn't be any peerDep warnings
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should fix this version in case the react-scripts package does get updated?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh, another good insight. Update coming.

@BYK BYK merged commit 96c215c into master Sep 16, 2017
@BYK BYK deleted the fix-peer-warnings branch September 16, 2017 10:16
@paul-court
Copy link

If this is now fixed, which version of yarn should we see it in 1.0.3?

@BYK
Copy link
Member Author

BYK commented Sep 18, 2017

@Gargoyle 1.1.0, which is around the corner. It is a minor version upgrade instead of a patch release since it will have some features like performance improvements.

@BYK
Copy link
Member Author

BYK commented Sep 18, 2017

it will have some features like performance improvements.

To be specific, not because of this PR but others :)

BYK added a commit that referenced this pull request Oct 5, 2017
**Summary**

This is a follow up to #4484 and #4478 which improves the code
around those areas a bit and removes a now-unnecessary `while`
loop.

**Test plan**

Existing tests should pass.
gkalpak added a commit to gkalpak/angular that referenced this pull request Oct 5, 2017
With [email protected] `aio/` and some guide examples fail to build. The failures seem
to be caused by something (possibly `@ngtools/webpack`, which is a dependency of
`@angular/cli`) which peer-depends on TypeScript (TS@^2.0.2), getting linked to
a higher version ([email protected]) with [email protected], which is stricter than the 2.3.2
version we use on `aio/` (and which that something gets linked to with
[email protected]).

[This change][1] is what is causing this difference in behavior.

Downgrading yarn to v1.0.2 (same we use on master) for now.

[1]: yarnpkg/yarn#4478
gkalpak added a commit to gkalpak/angular that referenced this pull request Oct 5, 2017
With [email protected] `aio/` and some guide examples fail to build. The failures seem
to be caused by something (possibly `@ngtools/webpack`, which is a dependency of
`@angular/cli`) which peer-depends on TypeScript (TS@^2.0.2), getting linked to
a higher version ([email protected]) with [email protected], which is stricter than the 2.3.2
version we use on `aio/` (and which that something gets linked to with
[email protected]).

[This change][1] is what is causing this difference in behavior.

Downgrading yarn to v1.0.2 (same we use on master) for now.

[1]: yarnpkg/yarn#4478
arcanis pushed a commit that referenced this pull request Oct 6, 2017
* chore(resolver): Minor improvements in resolver code and tests

**Summary**

This is a follow up to #4484 and #4478 which improves the code
around those areas a bit and removes a now-unnecessary `while`
loop.

**Test plan**

Existing tests should pass.

* Fix logic
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
…arnpkg#4478)

**Summary**

Fixes yarnpkg#4446, fixes yarnpkg#4433, fixes yarnpkg#2688, fixes yarnpkg#2387. Follow up to yarnpkg#3803. The fix in yarnpkg#3893 was
too aggressive, allowing only top-level dependencies to be used in
peer dependency resolution which was incorrect. This patch allows
resolving peer dependencies from the same or higher levels in the
dependency tree.

**Test plan**

Additional unit and integration tests.
joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
…kg#4644)

* chore(resolver): Minor improvements in resolver code and tests

**Summary**

This is a follow up to yarnpkg#4484 and yarnpkg#4478 which improves the code
around those areas a bit and removes a now-unnecessary `while`
loop.

**Test plan**

Existing tests should pass.

* Fix logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants