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(plugin-essentials): handle aliased dependencies on dedupe #6527

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .yarn/versions/0db9ee49.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-essentials": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
16 changes: 9 additions & 7 deletions packages/plugin-essentials/sources/dedupeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const acceptedStrategies = new Set(Object.values(Strategy));
const DEDUPE_ALGORITHMS: Record<Strategy, Algorithm> = {
highest: async (project, patterns, {resolver, fetcher, resolveOptions, fetchOptions}) => {
const locatorsByIdent = new Map<IdentHash, Set<LocatorHash>>();
for (const [descriptorHash, locatorHash] of project.storedResolutions) {
const descriptor = project.storedDescriptors.get(descriptorHash);
if (typeof descriptor === `undefined`)
throw new Error(`Assertion failed: The descriptor (${descriptorHash}) should have been registered`);
for (const locatorHash of project.storedResolutions.values()) {
const locator = project.originalPackages.get(locatorHash);
if (typeof locator === `undefined`)
throw new Error(`Assertion failed: The locator (${locatorHash}) should have been registered`);

miscUtils.getSetWithDefault(locatorsByIdent, descriptor.identHash).add(locatorHash);
miscUtils.getSetWithDefault(locatorsByIdent, locator.identHash).add(locatorHash);
}

const deferredMap = new Map<DescriptorHash, miscUtils.Deferred<PackageUpdate>>(
Expand Down Expand Up @@ -91,9 +91,11 @@ const DEDUPE_ALGORITHMS: Record<Strategy, Algorithm> = {
if (!resolver.shouldPersistResolution(currentPackage, resolveOptions))
return currentPackage;

const candidateHashes = locatorsByIdent.get(descriptor.identHash);
// As the descriptor may resolve into other ident, (i.e. npm: with package name specified)
// locators should be looked up by the current resolution rather than the descriptor.
const candidateHashes = locatorsByIdent.get(currentPackage.identHash);
if (typeof candidateHashes === `undefined`)
throw new Error(`Assertion failed: The resolutions (${descriptor.identHash}) should have been registered`);
throw new Error(`Assertion failed: The resolutions (${currentPackage.identHash}) should have been registered`);

// No need to choose when there's only one possibility
if (candidateHashes.size === 1)
Expand Down