fix: make sure hoistingLimits are not bypassed#7189
Conversation
|
i might be mistaken, but it seems the tests fail on master as well.. at least failed for me locally from master branch. |
|
@Knagis Thanks for the fix. I'm worried that it might prevent hoisting in unexpected places though. |
|
In my opinion the hoisting with the fix is not optimal, but it is correct. Without the fix hoistingLimits: dependencies is very broken as it results in pkg3 being on the top level - exactly the thing the setting is supposed to block:
With the fix - the setting is respected:
Nothing within pkg1 should be expecting pkg3 to be hoisted up one level - since hoisting is essentially optional. yarn pnp mode won't make pkg3 available to pkg1 etc. The further improvements to this case are apparent here -
i tried a bit to get 1. done but couldn't come up with something elegant (mostly because of the self dependencies for each pkg), and as it would likely involve much bigger refactor of cloneTree, i think that could/should be separate PR. |
|
@Knagis I understand, the fix though should be:
|
|
Yarn documentation https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits states
Current behavior violates this rule. The fix does not violate this rule. Is there any other guarantee specified anywhere in terms of how hoisting works? |
Yes, I agree with the plan and with corner cases |
|
The failing integration tests prevent me from merging this PR, it is technical limitation, since failing integration tests marked as "required". If the problems in failing integration tests are unrelated to this PR they should show up on other PRs, let's see if this will be the case. |
What's the problem this PR addresses?
Fixes issue when hoistingLimits: dependencies get broken due to the same dependency being both a direct one (thus isHoistBorder: true) and a transitive one (with isHoistBorder: false)
Resolves #6662
...
How did you fix it?
during
cloneTree()mark the copiedworkNodeas hoist border when it is such at any time in the tree, not just the first time it is encountered.Consider tree:
with
hoistingLimits: dependenciesboth pkg1 and pkg2 on the root level must be hoist borders. but due to the depth-first approach ofcloneTree, the first time pkg2 is encountered is was marked with isHoistBorder: false and that was applied even to the top level entry.before the fix:
and this means that pkg3 gets hoisted to top level.
The fix makes sure that pkg2 is correctly marked as hoist border.
The fix is not ideal, it results in
While not ideal, the fix does ensure that pkg3 does not get hoisted to top level which is the main point of hoistingLimits: dependencies
Checklist