Skip to content

Commit

Permalink
feat(core): optimize npm pruning path elevation function (#15880)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav committed Mar 27, 2023
1 parent 15e29b2 commit 1f935a7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/nx/src/lock-file/npm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,11 @@ function elevateNestedPaths(

sortedPaths.forEach((path) => {
const segments = path.split('/node_modules/');
const mappedPackage = remappedPackages.get(path);

// we keep hoisted packages intact
if (segments.length === 1) {
result.set(path, remappedPackages.get(path));
result.set(path, mappedPackage);
return;
}

Expand All @@ -581,13 +582,12 @@ function elevateNestedPaths(

// check if grandparent has the same package
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);
const elevatedPath = getNewPath(segs.slice(0, -1));
if (result.has(elevatedPath)) {
const match = result.get(elevatedPath);
return (
match.valueV1?.version === source.valueV1?.version &&
match.valueV3?.version === source.valueV3?.version
match.valueV1?.version === mappedPackage.valueV1?.version &&
match.valueV3?.version === mappedPackage.valueV3?.version
);
}
return true;
Expand All @@ -598,12 +598,12 @@ function elevateNestedPaths(
}
const newPath = getNewPath(segments);
if (path !== newPath) {
result.set(newPath, {
...remappedPackages.get(path),
path: newPath,
});
if (!result.has(newPath)) {
mappedPackage.path = newPath;
result.set(newPath, mappedPackage);
}
} else {
result.set(path, remappedPackages.get(path));
result.set(path, mappedPackage);
}
});

Expand Down

1 comment on commit 1f935a7

@vercel
Copy link

@vercel vercel bot commented on 1f935a7 Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx.dev

Please sign in to comment.