fix(plugin-essentials): handle aliased dependencies on dedupe
What's the problem this PR addresses?
I wasn't able to reliably reproduce the problem but I think you can see what was the issue from the patches.
When running a dedupe on a project with aliased dependencies (usually esbuild and esbuild-wasm for us), we experienced Yarn abruptly stopping the dedupe process with this error message:
Assertion Error: The package ([hash]) should have been registered
The hash depends on the resolution but I believe it is happening because Yarn is trying to find a version of aliased dependency on original package (like trying to find esbuild-wasm on esbuild idents).
Fixes #6176.
...
How did you fix it?
Instead of trusting the descriptor's ident, dedupeUtils will now look up the project.originalPackages first to find potentially aliased packages. I tried using project.storedPackages first but it was empty on runtime.
...
Checklist
- [x] I have read the Contributing Guide.
- [x] I have set the packages that need to be released for my changes to be effective.
- [x] I will check that all automated PR checks pass before the PR gets reviewed.
I'm not certain about this fix without a regression test, as I don't quite understand the issue - from what I see we're iterating over all resolutions and saving them into locatorsByIdent - so, for the assertion to fail, it means that we must have something in storedDescriptors that doesn't have a key in storedResolutions. Why does that happen?