@@ -48,7 +48,8 @@ export default async function convertPackageLockToShrinkwrap(workspaceRootDir, t
4848 path : workspaceRootDir ,
4949 } ) ;
5050 const tree = await arb . loadVirtual ( ) ;
51- const cliNode = Array . from ( tree . tops ) . find ( ( node ) => node . packageName === targetPackageName ) ;
51+ const tops = Array . from ( tree . tops . values ( ) ) ;
52+ const cliNode = tops . find ( ( node ) => node . packageName === targetPackageName ) ;
5253 if ( ! cliNode ) {
5354 throw new Error ( `Target package "${ targetPackageName } " not found in workspace` ) ;
5455 }
@@ -71,7 +72,7 @@ export default async function convertPackageLockToShrinkwrap(workspaceRootDir, t
7172 throw new Error ( `Duplicate root package entry for "${ targetPackageName } "` ) ;
7273 }
7374 } else {
74- packageLoc = normalizePackageLocation ( packageLoc ) ;
75+ packageLoc = normalizePackageLocation ( packageLoc , node , targetPackageName , tree . packageName ) ;
7576 }
7677 if ( packageLoc !== "" && ! pkg . resolved ) {
7778 // For all but the root package, ensure that "resolved" and "integrity" fields are present
@@ -104,24 +105,27 @@ export default async function convertPackageLockToShrinkwrap(workspaceRootDir, t
104105}
105106
106107/**
107- * Normalize package locations from workspace-specific paths to standard npm paths
108- * Examples:
108+ * Normalize package locations from workspace-specific paths to standard npm paths.
109+ * Examples (assuming @ui5/cli is the targetPackageName) :
109110 * - packages/cli/node_modules/foo -> node_modules/foo
110- * - packages/fs/node_modules/bar -> node_modules/bar
111+ * - packages/fs/node_modules/bar -> node_modules/@ui5/fs/node_modules/ bar
111112 *
112113 * @param {string } location - Package location from arborist
114+ * @param {object } node - Package node from arborist
115+ * @param {string } targetPackageName - Target package name for shrinkwrap file
116+ * @param {string } rootPackageName - Root / workspace package name
113117 * @returns {string } - Normalized location for npm-shrinkwrap.json
114118 */
115- function normalizePackageLocation ( location ) {
116- // Remove workspace prefix (packages/*/...) and convert to standard node_modules path
117- // Match: packages/<workspace-name>/node_modules/... or packages/<workspace-name>
118- const workspacePattern = / ^ p a c k a g e s \/ [ ^ / ] + \/ ( n o d e _ m o d u l e s \/ .+ ) $ / ;
119- const match = location . match ( workspacePattern ) ;
120- if ( match ) {
121- return match [ 1 ] ;
119+ function normalizePackageLocation ( location , node , targetPackageName , rootPackageName ) {
120+ const topPackageName = node . top . packageName ;
121+ if ( topPackageName === targetPackageName ) {
122+ // Remove location for packages within target package (e.g. @ui5/cli)
123+ return location . substring ( node . top . location . length + 1 ) ;
124+ } else if ( topPackageName !== rootPackageName ) {
125+ // Add package within node_modules of actual package name (e.g. @ui5/fs)
126+ return `node_modules/${ topPackageName } /${ location . substring ( node . top . location . length + 1 ) } ` ;
122127 }
123- // If it's just the workspace package itself (packages/<name>), keep as-is
124- // Otherwise return the location unchanged
128+ // If it's already within the root workspace package, keep as-is
125129 return location ;
126130}
127131
0 commit comments