@@ -55,17 +55,34 @@ export function stripWorkspaceFromVersion(version: string) {
55
55
}
56
56
57
57
export function parsePackageName ( packageSpecifier : string ) : { name : string ; version ?: string } {
58
- const parts = packageSpecifier . split ( "@" ) ;
58
+ let name : string | undefined ;
59
+ let version : string | undefined ;
59
60
60
- if ( parts . length === 1 && typeof parts [ 0 ] === "string" ) {
61
- return { name : parts [ 0 ] } ;
61
+ // Check if the package is scoped
62
+ if ( packageSpecifier . startsWith ( "@" ) ) {
63
+ const atIndex = packageSpecifier . indexOf ( "@" , 1 ) ;
64
+ // If a version is included
65
+ if ( atIndex !== - 1 ) {
66
+ name = packageSpecifier . slice ( 0 , atIndex ) ;
67
+ version = packageSpecifier . slice ( atIndex + 1 ) ;
68
+ } else {
69
+ name = packageSpecifier ;
70
+ }
71
+ } else {
72
+ const [ packageName , packageVersion ] = packageSpecifier . split ( "@" ) ;
73
+
74
+ if ( typeof packageName === "string" ) {
75
+ name = packageName ;
76
+ }
77
+
78
+ version = packageVersion ;
62
79
}
63
80
64
- if ( parts . length === 2 && typeof parts [ 0 ] === "string" && typeof parts [ 1 ] === "string" ) {
65
- return { name : parts [ 0 ] , version : parts [ 1 ] } ;
81
+ if ( ! name ) {
82
+ return { name : packageSpecifier } ;
66
83
}
67
84
68
- return { name : packageSpecifier } ;
85
+ return { name, version } ;
69
86
}
70
87
71
88
async function setPackageJsonDeps ( path : string , deps : Record < string , string > ) {
0 commit comments