Skip to content

Commit

Permalink
fix(core): fix broken path elevation in npm lockfile pruning (#15833)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8cd410a)
  • Loading branch information
meeroslav authored and FrozenPandaz committed Mar 23, 2023
1 parent cf785ef commit c94c00d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/nx/src/lock-file/npm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,10 +580,20 @@ function elevateNestedPaths(
`${segs.join('/node_modules/')}/node_modules/${packageName}`;

// check if grandparent has the same package
while (
segments.length > 1 &&
!result.has(getNewPath(segments.slice(0, -1)))
) {
const shouldElevate = (segs: string[]) => {
const newPath = getNewPath(segs.slice(0, -1));
if (result.has(newPath)) {
const match = result.get(newPath);
const source = remappedPackages.get(path);
return (
match.valueV1?.version === source.valueV1?.version &&
match.valueV3?.version === source.valueV3?.version
);
}
return true;
};

while (segments.length > 1 && shouldElevate(segments)) {
segments.pop();
}
const newPath = getNewPath(segments);
Expand Down

0 comments on commit c94c00d

Please sign in to comment.