Fix cacheKeyForTree & OneShot incompatibility #1100
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The fix in #1064 turns out to be insufficient.
The problem is that
cacheKeyForTree
can provide a cached tree at any point in the broccoli graph. We can't tell just by looking at the top level node for an addon whether it contains, deep down inside it, some trees that have already been run by other builders via OneShot.I don't like
cacheKeyForTree
. It's trying to solve a real problem, but at the wrong layer. Instead of sharing work between many addon instances, it should have been preventing there from being many addon instances in the first place.This PR moves Embroider to a solution more like that. We already have the
reduceInstances
hook. Here I give it a default implementation that will allow two addon instances with identicalcacheKeyForTree
for all trees to deduplicate at the instance level, not the tree level.It's also important to point out that there are up to three different kinds of deduplication going on in a classic build via
cacheKeyForTree
:Our
reduceInstances
hook intentionally only covers the first case.For the second case (when you want to deduplicate different copies of a package) you can do that in your package manager instead via yarn resolutions or NPM overrides.
For the third case (when you want to deduplicate between entirely unrelated packages)... no. Just don't. That is the worst kind of hidden global monkey patching.