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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"strip-bom": "^3.0.0",
"tar-fs": "^1.15.1",
"tar-stream": "^1.5.2",
Expand Down
4 changes: 2 additions & 2 deletions src/package-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ export default class PackageLinker {
const range = peerDeps[name];
const pkgs = this.resolver.getAllInfoForPackageName(name);
const found = pkgs.find(pkg => {
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.

});
const foundPattern = found && found._reference && found._reference.patterns;

Expand Down
12 changes: 8 additions & 4 deletions src/package-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class PackageReference {
this.permissions = {};
this.patterns = [];
this.optional = null;
this.root = false;
this.level = Infinity;
this.ignore = false;
this.incompatible = false;
this.fresh = false;
Expand All @@ -39,7 +39,7 @@ export default class PackageReference {
lockfile: Lockfile;
config: Config;

root: boolean;
level: number;
name: string;
version: string;
uid: string;
Expand All @@ -66,9 +66,13 @@ export default class PackageReference {
addRequest(request: PackageRequest) {
this.requests.push(request);

if (!request.parentRequest) {
this.root = true;
let requestLevel = -1;
let currentRequest = request;
while (currentRequest && requestLevel < this.level) {
requestLevel += 1;
currentRequest = currentRequest.parentRequest;
}
this.level = requestLevel;
}

prune() {
Expand Down
6 changes: 5 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4191,14 +4191,18 @@ sax@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"

"semver@2 || 3 || 4 || 5", semver@^5.1.0, semver@^5.3.0:
"semver@2 || 3 || 4 || 5", semver@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"

semver@^4.1.0:
version "4.3.6"
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"

semver@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

sequencify@~0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/sequencify/-/sequencify-0.0.7.tgz#90cff19d02e07027fd767f5ead3e7b95d1e7380c"
Expand Down