@@ -568,10 +568,11 @@ function elevateNestedPaths(
568568
569569 sortedPaths . forEach ( ( path ) => {
570570 const segments = path . split ( '/node_modules/' ) ;
571+ const mappedPackage = remappedPackages . get ( path ) ;
571572
572573 // we keep hoisted packages intact
573574 if ( segments . length === 1 ) {
574- result . set ( path , remappedPackages . get ( path ) ) ;
575+ result . set ( path , mappedPackage ) ;
575576 return ;
576577 }
577578
@@ -581,13 +582,12 @@ function elevateNestedPaths(
581582
582583 // check if grandparent has the same package
583584 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 ) ;
585+ const elevatedPath = getNewPath ( segs . slice ( 0 , - 1 ) ) ;
586+ if ( result . has ( elevatedPath ) ) {
587+ const match = result . get ( elevatedPath ) ;
588588 return (
589- match . valueV1 ?. version === source . valueV1 ?. version &&
590- match . valueV3 ?. version === source . valueV3 ?. version
589+ match . valueV1 ?. version === mappedPackage . valueV1 ?. version &&
590+ match . valueV3 ?. version === mappedPackage . valueV3 ?. version
591591 ) ;
592592 }
593593 return true ;
@@ -598,12 +598,12 @@ function elevateNestedPaths(
598598 }
599599 const newPath = getNewPath ( segments ) ;
600600 if ( path !== newPath ) {
601- result . set ( newPath , {
602- ... remappedPackages . get ( path ) ,
603- path : newPath ,
604- } ) ;
601+ if ( ! result . has ( newPath ) ) {
602+ mappedPackage . path = newPath ;
603+ result . set ( newPath , mappedPackage ) ;
604+ }
605605 } else {
606- result . set ( path , remappedPackages . get ( path ) ) ;
606+ result . set ( path , mappedPackage ) ;
607607 }
608608 } ) ;
609609
0 commit comments