Skip to content
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
25 changes: 25 additions & 0 deletions .yarn/versions/3bda9cd7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/nm": patch
"@yarnpkg/plugin-nm": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@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"
- "@yarnpkg/pnpify"
6 changes: 4 additions & 2 deletions packages/yarnpkg-nm/sources/hoist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,6 @@ const cloneTree = (tree: HoisterTree, options: InternalHoistOptions): HoisterWor
const isSeen = !!workNode;
if (!workNode) {
const {name, identName, reference, peerNames, hoistPriority, dependencyKind} = node;
const dependenciesNmHoistingLimits = options.hoistingLimits.get(parentNode.locator);
workNode = {
name,
references: new Set([reference]),
Expand All @@ -814,7 +813,7 @@ const cloneTree = (tree: HoisterTree, options: InternalHoistOptions): HoisterWor
peerNames: new Set(peerNames),
reasons: new Map(),
decoupled: true,
isHoistBorder: dependenciesNmHoistingLimits ? dependenciesNmHoistingLimits.has(name) : false,
isHoistBorder: false,
hoistPriority: hoistPriority || 0,
dependencyKind: dependencyKind || HoisterDependencyKind.REGULAR,
hoistedFrom: new Map(),
Expand All @@ -823,6 +822,9 @@ const cloneTree = (tree: HoisterTree, options: InternalHoistOptions): HoisterWor
seenNodes.set(node, workNode);
}

if (!workNode.isHoistBorder && options.hoistingLimits.get(parentNode.locator)?.has(node.name))
workNode.isHoistBorder = true;

parentNode.dependencies.set(node.name, workNode);
parentNode.originalDependencies.set(node.name, workNode);

Expand Down
14 changes: 14 additions & 0 deletions packages/yarnpkg-nm/tests/hoist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,18 @@ describe(`hoist`, () => {
};
expect(getTreeHeight(hoist(toTree(tree), {check: true}))).toEqual(4);
});

it(`should hoistingLimits when top level dependency matches a transitive dependency`, () => {
// . -> A -> B -> C
// -> B -> C
// with hoistingLimits: dependencies, C should not be hoisted to the top
const tree = {
'.': {dependencies: [`A`, `B`]},
A: {dependencies: [`B`]},
B: {dependencies: [`C`]},
};
const hoistedTree = hoist(toTree(tree), {check: true, hoistingLimits: new Map([[`.@`, new Set([`A`, `B`])]])});
const C = Array.from(hoistedTree.dependencies).filter(x => x.name === `C`);
expect(C).toEqual([]);
});
});
Loading