-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(resolver): Fix incorrect peer dependency res. from different trees #4687
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,6 +446,24 @@ export default class PackageLinker { | |
} | ||
const ref = pkg._reference; | ||
invariant(ref, 'Package reference is missing'); | ||
// TODO: We are taking the "shortest" ref tree but there may be multiple ref trees with the same length | ||
const refTree = ref.requests.map(req => req.parentNames).sort((arr1, arr2) => arr1.length - arr2.length)[0]; | ||
const refTreeLen = refTree.length; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was mostly for ease of reading for myself but sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh well, these were easier on the eyes in a previous version of the code. Now they are useless as you pointed out. |
||
|
||
const getLevelDistance = pkgRef => { | ||
let minDistance = Infinity; | ||
for (const req of pkgRef.requests) { | ||
const pkgParents = req.parentNames; | ||
const pkgParentsLen = pkgParents.length; | ||
const distance = refTreeLen - pkgParentsLen; | ||
|
||
if (distance >= 0 && distance < minDistance && pkgParents.every((name, idx) => name === refTree[idx])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be more less readable, but more efficient to use |
||
minDistance = distance; | ||
} | ||
} | ||
|
||
return minDistance; | ||
}; | ||
|
||
for (const peerDepName in peerDeps) { | ||
const range = peerDeps[peerDepName]; | ||
|
@@ -459,16 +477,16 @@ export default class PackageLinker { | |
if (!(peerPkgRef && peerPkgRef.patterns)) { | ||
continue; | ||
} | ||
const levelDistance = ref.level - peerPkgRef.level; | ||
if (levelDistance >= 0 && levelDistance < resolvedLevelDistance) { | ||
const levelDistance = getLevelDistance(peerPkgRef); | ||
if (isFinite(levelDistance) && levelDistance < resolvedLevelDistance) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to not set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted that too but then I'd need to add special casing into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, hmm can't think of an alternative atm. Thanks for explaining. :) |
||
if (this._satisfiesPeerDependency(range, peerPkgRef.version)) { | ||
resolvedLevelDistance = levelDistance; | ||
resolvedPeerPkgPattern = peerPkgRef.patterns; | ||
this.reporter.verbose( | ||
this.reporter.lang( | ||
'selectedPeer', | ||
`${pkg.name}@${pkg.version}`, | ||
`${peerDepName}@${range}`, | ||
`${peerDepName}@${peerPkgRef.version}`, | ||
peerPkgRef.level, | ||
), | ||
); | ||
|
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.
Is it a problem if we choose one of those at random?
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.
I honestly don't know, hence the TODO.