@@ -163,24 +163,27 @@ export function getAnotherInstallRequiredOutput(recurringInstall = false, oldNon
163163}
164164
165165function extractPackageName ( packageString : string ) : string {
166- const lastAtIndex = packageString . lastIndexOf ( '@' ) ;
166+ if ( ! packageString ) return '' ;
167167
168- // If no '@' is present, or it's at the start (meaning it's just a scope),
169- // we can assume there's no separate version part to remove.
170- if ( lastAtIndex <= 0 ) {
168+ // Handle https and git protocols. We don't allow "file" protocol here. It won't work for the consumer.
169+ const allowedPrefixes = [ 'https://' , 'git:' , 'git+ssh://' , 'git+https://' ] ;
170+ if ( allowedPrefixes . some ( ( prefix ) => packageString . startsWith ( prefix ) ) ) {
171171 return packageString ;
172172 }
173173
174- // Get everything after the last '@'
175- const afterLastAt = packageString . slice ( lastAtIndex + 1 ) ;
176-
177- // If the substring after the last '@' contains a slash, it's part of the scoped package name,
178- // not a version. In that case, do not remove anything.
179- if ( afterLastAt . includes ( '/' ) ) {
180- return packageString ;
174+ // If it's a scoped package
175+ if ( packageString . startsWith ( '@' ) ) {
176+ // Find the second '@' (first is for scope, second is for version/tag)
177+ const atIndex = packageString . indexOf ( '@' , 1 ) ;
178+ if ( atIndex === - 1 ) return packageString ;
179+ const possibleVersion = packageString . slice ( atIndex + 1 ) ;
180+ // If the part after the second '@' contains a slash, it's not a version/tag
181+ if ( possibleVersion . includes ( '/' ) ) return packageString ;
182+ return packageString . slice ( 0 , atIndex ) ;
181183 }
182184
183- // Otherwise, we assume that last '@' starts the version,
184- // so we remove that part.
185+ // For unscoped packages, split at the last '@'
186+ const lastAtIndex = packageString . lastIndexOf ( '@' ) ;
187+ if ( lastAtIndex <= 0 ) return packageString ;
185188 return packageString . slice ( 0 , lastAtIndex ) ;
186189}
0 commit comments