Skip to content

Commit 8cd410a

Browse files
authored
fix(core): fix broken path elevation in npm lockfile pruning (#15833)
1 parent c7e49c5 commit 8cd410a

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

packages/nx/src/lock-file/npm-parser.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,20 @@ function elevateNestedPaths(
580580
`${segs.join('/node_modules/')}/node_modules/${packageName}`;
581581

582582
// check if grandparent has the same package
583-
while (
584-
segments.length > 1 &&
585-
!result.has(getNewPath(segments.slice(0, -1)))
586-
) {
583+
const shouldElevate = (segs: string[]) => {
584+
const newPath = getNewPath(segs.slice(0, -1));
585+
if (result.has(newPath)) {
586+
const match = result.get(newPath);
587+
const source = remappedPackages.get(path);
588+
return (
589+
match.valueV1?.version === source.valueV1?.version &&
590+
match.valueV3?.version === source.valueV3?.version
591+
);
592+
}
593+
return true;
594+
};
595+
596+
while (segments.length > 1 && shouldElevate(segments)) {
587597
segments.pop();
588598
}
589599
const newPath = getNewPath(segments);

0 commit comments

Comments
 (0)